fix: resolve race conditions in wallet identity toggling and hook caching - #24
Merged
JamesEjembi merged 1 commit intoJun 16, 2026
Conversation
…hing Implement wallet transitioning guard, identity generation counter, cache invalidation, and deep-comparison query key wrapper. - Add WalletProvider with transitioning state that blocks queries - Add useWalletIdentity hook with publicKey, generation, isTransitioning - Add useWalletQueryKey with automatic public-key-prefixed cache keys - Wire queryClient.cancelQueries on every identity change - Guard query execution via 'enabled' check during transitions - Add useMemo deep-comparison around wallet-dependent query keys - Add WalletStatusBar test helper for e2e assertions - Write Playwright e2e test validating rapid 3-wallet toggling Closes Lumina-etwork#1
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.
Summary
Fixes #1 — Race conditions when rapidly switching wallet accounts in Freighter. The WalletProvider dispatches identity updates asynchronously, but downstream hooks cached stale React Query results keyed to the previous public key.
Changes
WalletProvider (
src/components/providers/WalletProvider.tsx)isTransitioningstate flag that blocks query execution during identity switchesaccountChangeevents and callsqueryClient.cancelQueries()before fetching new identitygenerationcounter on every account change to force downstream re-rendersuseWalletIdentity (
src/hooks/useWalletIdentity.ts){ publicKey, generation, isTransitioning }from WalletContextuseMemofor identity stability across rendersuseWalletQueryKeyprefixes query keys with the wallet public key, or returns["wallet-blocked", ...]during transitionsuseSorobanBilling / useLedgerEvents
useWalletQueryKeyenabled: false) during wallet transitions via key prefix checkuseMemodeep-comparison wrappers around query keysQueryClient (
src/lib/queryClient.ts)walletTransitioningRefthat WalletProvider updatesE2E Tests (
e2e/wallet-toggling.spec.ts)Verification
npm run buildpasses with zero errorsnpx eslint .passes with zero errors