Skip to content

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

Description

@yasha-meursault

Reconnect (packages/client/src/actions/reconnect.ts) readds each connector under its new uid but never removes the connection rehydrated from storage under the previous session's uid. Since uids are regenerated every page load (createEmitter(uid()) in createConfig), every reload leaves the old entry behind the store grows and current ends up pointing at a dead one.

Rehydrated connectors are serialized to plain { id, name, type, uid } (partialize in createConfig) no methods, no emitter. On success reconnect only adds:

const connections = new Map(x.connections)  // keeps the stale entry
connections.set(connector.uid, { ... })     // new uid => a second entry
return { ...x, connections, current: x.current || connector.uid, status: 'connected' }

and on total failure it only flips status, leaving the dead entries. wagmi (which this was ported from) instead wipes the map on first success new Map(connected ? x.connections : new Map()), current: connected ? x.current : connector.uid and resets connections/current when nothing reconnects.

Proof - bigmi.store after connecting UniSat once, then one reload:

{"connections":{"value":[
  ["99b28195730",{"connector":{"id":"unisat","uid":"99b28195730"}}],
  ["63dbada9850",{"connector":{"id":"unisat","uid":"63dbada9850"}}]
]},"current":"99b28195730"}

Two entries for one connection; current points at the dead 99b28195730. Another reload adds another.

Impact: getAccount reads connections.get(current) => the stub (no icon, no methods) => UI loses the wallet icon/name; and disconnect(config, { connector }) on a stored connector throws connector.disconnect is not a function before connections.delete, so it can't be cleared via the API.

Repro: connect any connector, reload with reconnectOnMount (default), inspect localStorage["bigmi.store"].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions