Skip to content

fix(react): race condition between initialize and isAuthorized in RN#75

Merged
andrascodes merged 1 commit into
mainfrom
andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn
May 13, 2026
Merged

fix(react): race condition between initialize and isAuthorized in RN#75
andrascodes merged 1 commit into
mainfrom
andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn

Conversation

@andrascodes
Copy link
Copy Markdown
Collaborator

@andrascodes andrascodes commented Apr 1, 2026

This PR is part of a stack created with Aviator.

Closes FS-1930

On mobile when passing in a SecureStoreStamper to the SDK I noticed that the session refresh wasn't working properly. The session refresh itself succeeded (so initialize() ran and completed) but the connect() wasn't being called inside wagmi.
Here's the lifecycle of the connector methods in wagmi:

  1. In Wagmi: setup() is called in createConfig, it's not awaited, you can see it here - so this just kicks off our session refresh and initialize()

  2. In reconnect() (when the user refreshes the app): (here)

    1. getProvider() is called first, awaited, if !provider  then skips - on mobile we have the provider here already so this is truthy and the execution continues to
    2. isAuthorized() : this gets called and awaited, here the eoaAccount that we return is still null when this method is called, because initalize() takes too long likely because of the secureStoreStamper operations. So when this happens the reconnect() doesn't continue. It just skips our connector.

The fix I opted for was awaiting initialize() in getProvider() so even at that point we for sure have the Provider and initialized the session.
An additional fix I opted for was awaiting the hydration of the Zustand store as well. This is best done because on React Native the store can be AsyncStorage with async operations. In order to do this, I passed skipHydration to the store and then in initialize() started and await the store.persist.rehydrate().

This way at the point wagmi calls getProvider() we know we have the store hydrated and the ZDWallet + the Session initialized and set in store. So connect() will definitely be called with the correct state.

On Web: awaiting the hydration should be quick because the store is Sync. Also, IndexedDB is much faster so the initialize() should already be resolved by the time getProvider() (and await initialize()) is called.

@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 8837a4c to 5f1e79a Compare April 1, 2026 17:11
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from 6d3fa6a to 49a2c93 Compare April 1, 2026 17:11
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 5f1e79a to 9134f2e Compare April 1, 2026 21:08
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from 49a2c93 to 9631468 Compare April 1, 2026 21:08
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from 9631468 to 5dfaff7 Compare April 7, 2026 11:21
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 9134f2e to 19af0fe Compare April 7, 2026 11:21
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from 5dfaff7 to ed19d1b Compare April 7, 2026 16:17
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 19af0fe to 67fc62b Compare April 7, 2026 16:17
@andrascodes andrascodes marked this pull request as ready for review April 7, 2026 16:55
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from ed19d1b to 64aaa8d Compare April 20, 2026 10:11
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 67fc62b to 7e8b5c9 Compare April 20, 2026 10:11
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 7e8b5c9 to 6d49f74 Compare April 24, 2026 17:57
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from 64aaa8d to 1be46e0 Compare April 24, 2026 17:57
SahilVasava
SahilVasava previously approved these changes Apr 28, 2026
Copy link
Copy Markdown
Collaborator

@SahilVasava SahilVasava left a comment

Choose a reason for hiding this comment

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

LGTM!

@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch 2 times, most recently from e37a38e to 72d702a Compare May 4, 2026 16:56
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from 1609ff9 to 21c5bb8 Compare May 4, 2026 16:56
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 72d702a to 9fcc007 Compare May 5, 2026 11:02
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch 2 times, most recently from 48228c1 to bacc73c Compare May 5, 2026 11:28
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 9fcc007 to 6cbe1be Compare May 5, 2026 11:28
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 6cbe1be to 93c9219 Compare May 5, 2026 13:22
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch 2 times, most recently from 3bdb8a3 to 66555a7 Compare May 5, 2026 14:31
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 93c9219 to 0004ce4 Compare May 5, 2026 14:31
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from 66555a7 to c6d9181 Compare May 6, 2026 12:18
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 0004ce4 to 6f58d08 Compare May 6, 2026 12:18
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from c6d9181 to bdf379f Compare May 6, 2026 13:26
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 6f58d08 to b93af0f Compare May 6, 2026 13:26
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from b93af0f to accc419 Compare May 11, 2026 18:48
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from bdf379f to 57273e4 Compare May 11, 2026 18:48
@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zerodev-signer-demo Ready Ready Preview, Comment May 13, 2026 11:32am

Request Review

@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from 57273e4 to b980e22 Compare May 13, 2026 10:29
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from accc419 to 47943b2 Compare May 13, 2026 10:29
@andrascodes andrascodes force-pushed the andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn branch from b980e22 to 3752741 Compare May 13, 2026 10:45
@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 47943b2 to 23d330a Compare May 13, 2026 10:45
@andrascodes andrascodes changed the base branch from andras/feat-add-fetchoptions-to-core-and-react-so-origin-header-can-be-sent-on-rn to main May 13, 2026 11:30
@andrascodes andrascodes dismissed SahilVasava’s stale review May 13, 2026 11:30

The base branch was changed.

@andrascodes andrascodes force-pushed the andras/fix-react-race-condition-between-initialize-and-isauthorized-in-rn branch from 23d330a to e185758 Compare May 13, 2026 11:31
@andrascodes andrascodes merged commit 85f3520 into main May 13, 2026
11 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