Skip to content

fix(core): unsubscribe connect after a wallet-initiated connection - #5265

Merged
tmm merged 2 commits into
wevm:mainfrom
mortezashojaei:fix/wallet-initiated-connect-listener
Nov 12, 2026
Merged

tmm merged 2 commits into
wevm:mainfrom
mortezashojaei:fix/wallet-initiated-connect-listener

Conversation

@mortezashojaei

Copy link
Copy Markdown
Contributor

Summary

When a wallet connects on its own (MetaMask “manually connect”, or accountsChanged before the app calls connect()), createConfig is supposed to stop listening for connect. The handler calls emitter.off('connect', change), but change was never subscribed to that event, so the connect listener stays.

injected treats a leftover connect listener as “still disconnected”. The next account change is emitted as another connect, and that path sets state.current. A background wallet switching accounts can replace the active connector.

connect() and reconnect() already unsubscribe the real connect listener. This handler now does the same.

Test plan

  • Wallet-initiated connect removes the connect listener (fails on main: count stays 1)
  • Account change on a background injected wallet keeps state.current (fails on main: current switches to that wallet)
  • createConfig, connect, disconnect, and reconnect tests

The connect handler removed `change` from the `connect` event, so the
listener stayed attached. Injected wallets then treated the next account
change as a new connection and could replace the active connector.
@vercel

vercel Bot commented Oct 22, 2026

Copy link
Copy Markdown

@mortezashojaei is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a76c4d9

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

This PR includes changesets to release 5 packages
Name Type
@wagmi/core Patch
@wagmi/connectors Patch
wagmi Patch
@wagmi/solid Patch
@wagmi/vue 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

@mortezashojaei

Copy link
Copy Markdown
Contributor Author

@tmm Any comments on this one? should we quick one to review 👀

@mortezashojaei

Copy link
Copy Markdown
Contributor Author

@tmm Bump here 👀

@tmm
tmm merged commit b148425 into wevm:main Nov 12, 2026
2 of 4 checks passed
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.

3 participants