Skip to content

fix(client): drop stale connections on reconnect - #66

Merged
chybisov merged 2 commits into
lifinance:mainfrom
yasha-meursault:fix/reconnect-stale-connections
Jul 27, 2026
Merged

fix(client): drop stale connections on reconnect#66
chybisov merged 2 commits into
lifinance:mainfrom
yasha-meursault:fix/reconnect-stale-connections

Conversation

@yasha-meursault

@yasha-meursault yasha-meursault commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Problem

reconnect never removes connections rehydrated from storage under the previous session's connector uid. On every reload the successful-reconnection path did new Map(x.connections), copying the rehydrated map, so the stale stub survived and current could keep pointing at a dead connector.

Fixes #65

Fix

Match wagmi's behavior:

  • Introduce a shared connected flag (reconnect attempts run in parallel via Promise.allSettled). The first successful reconnection rebuilds the connections map from scratch (new Map(connected ? x.connections : new Map())) and sets current: connected ? x.current : connector.uid, so the fresh map replaces the rehydrated one and current points at the connector that actually reconnected. Later successes in the same run append to it.
  • When nothing reconnects, reset connections and current alongside status: 'disconnected' instead of leaving the stale map in place.

Notes

  • Includes a @bigmi/client patch changeset.
  • pnpm check, pnpm check:types, pnpm check:circular-deps, pnpm knip:check, and pnpm test all pass locally (pre-commit / pre-push hooks).

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-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 586cfea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@bigmi/client Patch
@bigmi/react Patch

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

Comment thread packages/client/src/actions/reconnect.ts
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
chybisov merged commit 8da5d88 into lifinance:main Jul 27, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 27, 2026
@chybisov

Copy link
Copy Markdown
Member

Hey, thank you for your contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconnect leaks stale connections on reload, dead connector stubs pile up

2 participants