fix(client): keep concurrent connect() alive across reconnect - #69
Merged
Conversation
reconnect runs on mount and polls for a wallet provider for up to 5s, so a user can complete a manual connect() while it is still in flight. When no connector reconnected, the tail reset wiped that fresh connection along with the stale rehydrated entries. Gate the reset on the store still being in the reconnecting/connecting state reconnect put it in, matching wagmi. Also restore the @bigmi/client vitest setup and the UniSat connector spec removed in #67, and add reconnect specs covering the stale-connection replacement, the no-connector reset, and the race above.
🦋 Changeset detectedLatest commit: c895e02 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merged
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.
Follow-up to #66 / #67.
Problem
reconnectruns on mount and polls each connector for a provider for up to 5s (retryUntil, 5000ms), so it is commonly in flight for several seconds on every page load. A user can complete a manualconnect()inside that window.When no connector reconnected, the tail reset fired unconditionally and wiped that fresh connection:
The user ends up disconnected immediately after successfully connecting.
Fix
Gate the reset on the store still being in the state reconnect put it in, so it only clears what reconnect itself owns:
This is wagmi's guard ("Prevent overwriting connected status from race condition"), the one piece of that block #66 did not port. Both interleavings are safe: if
connect()finishes first the status isconnectedand the reset is skipped; if it is still in flight the status isconnecting, the reset clears an empty map, andconnect()then writes its own state on top.Tests
Restores the
@bigmi/clientvitest setup andunisat.spec.tsthat were added and then removed within #67 — the specs pass unchanged against the merged code. Addsreconnect.spec.tscovering:connections/currentreset when nothing reconnectsconnect()lands; verified to fail without the guard and pass with itpnpm testnow covers@bigmi/clientas well: 6 passed (client), 32 passed / 1 skipped (core).Considered and rejected
Making
currentdeterministic under parallelism (first-to-resolve wins rather than first insortedorder, sorecentConnectorIdpriority is best-effort). Both implementations — rank tracking shared across parallel tasks, or a post-hoc re-pick — add a second synchronicity invariant to already-subtle code, and the loser is still a live connector. Not worth the complexity; happy to revisit if multi-wallet users report it.Validation
pnpm check,pnpm check:types,pnpm check:circular-deps,pnpm knip:check,pnpm testall pass.