fix: resolve chainId race condition in preset flow#2436
Closed
kronosapiens wants to merge 1 commit intomainfrom
Closed
fix: resolve chainId race condition in preset flow#2436kronosapiens wants to merge 1 commit intomainfrom
kronosapiens wants to merge 1 commit intomainfrom
Conversation
Pass chain_id as URL parameter from all providers (controller, session, telegram, node) to the keychain iframe. Initialize chainId synchronously from the URL param to eliminate the race condition where isPoliciesResolved gates UI rendering on asynchronously-derived chainId. Replace RPC URL string comparison with semantic chain ID comparison in disconnect logic to avoid false-positive disconnects from URL normalization differences (e.g., different RPC endpoints for same chain). Fixes v0.13.9 regression where users upgrading with presets experience indefinite loading screen. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users upgrading from v0.13.4 to v0.13.9 with preset-based configurations experience an indefinite loading screen — authentication and session registration are non-functional.
Root cause: v0.13.9 introduced
isPoliciesResolvedas a UI gate inapp.tsx. For preset users,resolvePoliciesreturnsisPoliciesResolved: falsewhen eitherisConfigLoadingis true orchainIdis undefined. ThechainIdin the keychain is derived asynchronously (via RPC call), creating a race condition where the UI blocks on a value that hasn't resolved yet.A secondary issue compounds this: the disconnect
useEffectcompares RPC URL strings (controller.rpcUrl() === urlRpcUrl). URL normalization differences (encoding, trailing slashes, different providers for the same chain) cause false-positive mismatches, triggering unnecessary disconnect loops that prevent recovery.Fix
1. Pass
chain_idas a URL parameter from all providers to the keychain.The controller already knows the
chainIdsynchronously at construction time. This passes it through the URL to the keychain iframe (and session/telegram/node redirect URLs), eliminating the need for an async RPC derivation on initial load.2. Initialize
chainIdsynchronously from the URL param inuseConnectionValue.The
useStateinitializer readschain_idfromwindow.location.search, sochainIdis immediately available whenresolvePoliciesruns — no more race condition.3. Replace RPC URL string comparison with chain ID comparison in disconnect logic.
Comparing
controller.chainId() === chainIdinstead ofcontroller.rpcUrl() === urlRpcUrlavoids false-positive disconnects from URL normalization differences. Two different RPC endpoints for the same chain no longer trigger a disconnect.Files changed
packages/controller/src/iframe/keychain.ts— Accept and forwardchainIdoption as URL parampackages/controller/src/controller.ts— PassselectedChainto KeychainIFramepackages/controller/src/session/provider.ts— Addchain_idto session redirect URLpackages/controller/src/telegram/provider.ts— Addchain_idto telegram redirect URLpackages/controller/src/node/provider.ts— Addchain_idto node redirect URLpackages/keychain/src/hooks/connection.ts— Sync chainId init + chain ID disconnect comparisonpackages/keychain/src/hooks/connection.test.ts— Updated disconnect tests for chain ID logic