fix: retry wallet connect on WalletNotSelectedError to fix first-select race - #4
Open
SAY-5 wants to merge 1 commit into
Open
fix: retry wallet connect on WalletNotSelectedError to fix first-select race#4SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
SAY-5
force-pushed
the
fix/wallet-connect-retry-on-first-select
branch
from
August 16, 2026 09:54
07a68d7 to
7bf6c21
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2.
`select(walletName)` triggers a React state update; the auto-connect
`useEffect` then sees `wallet` truthy and calls `connect()` from
`useWallet()`. On the first selection after the modal mounts,
the @solana/wallet-adapter-react WalletContext has not always finished
registering the underlying adapter by the time this effect re-runs,
so `connect()` throws `WalletNotSelectedError` and the wallet
popup never opens. Clicking again succeeds because the second pass
sees a fully-registered adapter.
Fix
Wrap the auto-connect in a small async helper that retries once
after 200ms when, and only when, the failure is
`WalletNotSelectedError`. Other errors, user rejection, timeout,
session-expired, propagate to `setError` unchanged.
The effect's cleanup cancels both an in-flight retry timer and any
post-`await` state writes, so a re-mount or wallet switch during
the retry window doesn't leak a state update or a stray retry call.
The original code's behaviour for the happy path (`connect`
resolves on first try) and for non-race errors is preserved
verbatim, the retry only fires for `WalletNotSelectedError` and
only once per selection.
Test plan
extension installed (would confirm the popup opens on first
select). I don't have a desktop Solana wallet installed in
this environment, so I'm relying on review for the runtime
check.
Notes on alternatives considered
The issue body lists three options. I went with the retry approach
(option 3) because:
connecting flag and is more invasive.
WalletContext layer and risks the context's internal state going
out of sync with the adapter's connected state for downstream
hooks (`publicKey`, `sendTransaction`).
known race; it leaves all other paths untouched and is easy to
remove later if @solana/wallet-adapter-react fixes the race
upstream.