fix(wallet): guard undefined connector on reconnect to stop refresh crash - #7772
Conversation
|
@tenderdeve is attempting to deploy a commit to the cow-dev Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughPatches the ChangesWagmi adapter patch update
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Cloudflare Pages preview mirror Preview branch URL: https://github.com/cowprotocol/cowswap/tree/cf-preview/pr-7772 Source fork branch:
|
elena-zh
left a comment
There was a problem hiding this comment.
Hey @tenderdeve , thanks, but not fixed.
|
@elena-zh updated in 8bdd9b9 — the previous |
|
@tenderdeve could you please rebase the PR to point to develop instead of main? |
@elena-zh fixed, now PR pointed to develop |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…rash @reown/appkit-adapter-wagmi reads `accountData.connector.id` unguarded in the `watchAccount` onChange handler, while the very next operand already uses `prevAccountData.connector?.id`. During reconnection rehydration on page refresh (e.g. Rabby on Polygon) wagmi can briefly report status 'connected' before the connector object is attached, so `.id` throws 'Cannot read properties of undefined (reading id)'. The throw aborts the connected handler, so reconnection never finalizes and the wallet ends up disconnected. Patch the dependency to read `accountData.connector?.id`, matching the existing optional chaining on the prev value.
The connector?.id guard alone only fixed the comparison in the watchAccount onChange handler; the crash then moved into handleAccountChanged, which calls connector.getProvider() and reads connector.id unguarded. On page refresh (e.g. Rabby on Polygon) wagmi can report status 'connected' before the connector object is attached, so getProvider() throws "Cannot read properties of undefined (reading 'getProvider')" and reconnection never finalizes, leaving the wallet disconnected. Only finalize the connected account when accountData.connector is present. The connector-less 'connected' state is a transient rehydration step; wagmi fires onChange again once the connector attaches (which registers as a connector change), so no event is lost.
6f76a2a to
02249cf
Compare
|
Rebased cleanly onto |
Summary
Fixes #7769
On refresh, a connected wallet (repro: Rabby on Polygon) disconnects and the console throws
Cannot read properties of undefined (reading 'id').The throw comes from
@reown/appkit-adapter-wagmi'swatchAccountonChange handler, which readsaccountData.connector.idunguarded — even though the very next operand already usesprevAccountData.connector?.id:During reconnection rehydration, wagmi can briefly report
status: 'connected'before the connector object is attached (the window is wider with a custom injected connector + EIP-6963 isolation and a non-mainnet chain).accountData.connectoris thenundefined, so.idthrows. Because the throw happens inside the connected handler, reconnection never finalizes and the wallet ends up disconnected — both reported symptoms from one line.Extended the existing
patches/@reown__appkit-adapter-wagmi@1.8.19.patchto readaccountData.connector?.id, matching the optional chaining already used on the previous value.To Test
reading 'id'error in the console.Background
The unguarded
.idis upstream library code, so the fix is a dependency patch rather than an app change. I don't have an on-device Rabby/Polygon setup to reproduce the exact rehydration timing, so this targets the single unguarded dereference the stack points to; the asymmetric optional chaining on the same line is a clear upstream oversight.Summary by CodeRabbit