fix(client): drop stale connections on reconnect - #66
Merged
chybisov merged 2 commits intoJul 27, 2026
Conversation
reconnect copied the connections map rehydrated from storage under the previous session's connector uid, so every reload left a dead stub behind and `current` could point at it. Match wagmi: on the first successful reconnection rebuild the connections map from scratch (guarded by a shared `connected` flag since reconnect runs in parallel) and set `current` to the reconnected connector's uid. When nothing reconnects, reset `connections`/`current` alongside `status: 'disconnected'`. Closes #65 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 586cfea 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 |
Hoist the `connected` check-and-set out of the zustand updater so the state callback stays side-effect free, and gate the reset on `connected` rather than the results array — if `setState` throws after committing (e.g. storage quota), the connection landed but never reaches the array, and the tail would wipe it.
chybisov
approved these changes
Jul 27, 2026
Merged
Member
|
Hey, thank you for your contribution :) |
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.
Problem
reconnectnever removes connections rehydrated from storage under the previous session's connectoruid. On every reload the successful-reconnection path didnew Map(x.connections), copying the rehydrated map, so the stale stub survived andcurrentcould keep pointing at a dead connector.Fixes #65
Fix
Match wagmi's behavior:
connectedflag (reconnect attempts run in parallel viaPromise.allSettled). The first successful reconnection rebuilds the connections map from scratch (new Map(connected ? x.connections : new Map())) and setscurrent: connected ? x.current : connector.uid, so the fresh map replaces the rehydrated one andcurrentpoints at the connector that actually reconnected. Later successes in the same run append to it.connectionsandcurrentalongsidestatus: 'disconnected'instead of leaving the stale map in place.Notes
@bigmi/clientpatch changeset.pnpm check,pnpm check:types,pnpm check:circular-deps,pnpm knip:check, andpnpm testall pass locally (pre-commit / pre-push hooks).