Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only reconnect accounts for active chain during rehydration #1356

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

jakehobbs
Copy link
Member

@jakehobbs jakehobbs commented Feb 12, 2025

Bug when switching chains after refreshing page

Explanation

  • When the page is refreshed, the store is rehydrated using the cookie data.
  • The hydrate function calls hydrateAccountState, which reads all existing accounts from the store and sets them to "RECONNECTING" on all chains.
  • The hydrate function then calls the reconnect function, which calls createAccount for each account. But this only happens on the active chain, so any other chain's accounts will get stuck in the "RECONNECTING" state but never actually reconnect.

Solutions

  • The easiest solution is to not set accounts to "RECONNECTING" if they are not on the active chain during hydration. We can just set them to "DISCONNECTED", then they will naturally reconnect if they are attempted to be used again.
  • An alternative solution would be to alter the createAccount function to accept an option chain param instead of only being able to reconnect accounts on the active chain.

Pull Request Checklist


PR-Codex overview

This PR focuses on enhancing the account state management by introducing an activeChainId that determines if the current chain is active, affecting the reconnection logic for various account types.

Detailed summary

  • Added activeChainId to track the current active chain.
  • Introduced isActiveChain to check if the current chain matches activeChainId.
  • Updated the reconnection logic for LightAccount, MultiOwnerModularAccount, MultiOwnerLightAccount, and ModularAccountV2 to consider shouldReconnect based on the active chain.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented Feb 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
aa-sdk-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 6:17pm
aa-sdk-ui-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 6:17pm

Copy link

graphite-app bot commented Feb 12, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link
Collaborator

@adamegyed adamegyed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job digging through the stack to find this!

Do you know if setChain from useChain will automatically start the re-connect process? https://accountkit.alchemy.com/react/multi-chain-apps#change-chains

@jakehobbs
Copy link
Member Author

Good job digging through the stack to find this!

Do you know if setChain from useChain will automatically start the re-connect process? https://accountkit.alchemy.com/react/multi-chain-apps#change-chains

it does not. the only place reconnect is called is during rehydration.

@jakehobbs jakehobbs merged commit 95c6174 into main Feb 12, 2025
7 checks passed
@jakehobbs jakehobbs deleted the jake/multi-chain-rehydration-fix branch February 12, 2025 21:55
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.

2 participants