fix(react): drop non-simple params from fetchAccessToken (Hermes V1) - #368
fix(react): drop non-simple params from fetchAccessToken (Hermes V1)#368ramonclaudio wants to merge 1 commit into
Conversation
|
@ramonclaudio is attempting to deploy a commit to the Convex Team on Vercel. A member of the Team first needs to authorize it. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughfetchAccessToken was refactored to return an explicit new Promise wrapper. It still short-circuits to cachedToken when present (unless forceRefreshToken), reuses pendingTokenRef for concurrent callers, calls authClient.convex.token({ fetchOptions: { throw: false } }) for new requests, updates/clears cachedToken on success/failure, and always clears pendingTokenRef in finally; resolution/rejection from in-flight requests is routed through the wrapper’s resolve/reject. Sequence Diagram(s)sequenceDiagram
participant Consumer
participant fetchAccessToken
participant Cache as cachedToken
participant Pending as pendingTokenRef
participant API as authClient.convex.token()
Consumer->>fetchAccessToken: request token
fetchAccessToken->>Cache: check cachedToken
alt cachedToken present
Cache-->>fetchAccessToken: return cached token
fetchAccessToken-->>Consumer: resolve(token)
else no cached token
fetchAccessAccessToken->>Pending: check pendingTokenRef
alt pending in flight
Pending-->>fetchAccessToken: existing promise
fetchAccessToken-->>Consumer: attach then(resolve,reject)
else fetch new
fetchAccessToken->>API: token({ throw: false })
API-->>fetchAccessToken: token or error
fetchAccessToken->>Cache: update or clear cachedToken
fetchAccessToken-->>Consumer: resolve/reject via outer callbacks
fetchAccessToken->>Pending: clear in finally
end
end
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
b1550be to
53c46f0
Compare
|
Might this be fixed upstream in the Expo 56 preview? |
@dowski the expo team did patch it upstream, but only at the babel preset level (expo/expo#45601). That covers SDK 56 users on Filed facebook/react-native#56816 to port the same babel transforms into Leaving it up to @erquhart to decide what to do here! |
|
Thanks Ray - holdilng this until expo 56 is closer to stable, would hope this would be addressed upstream. |
53c46f0 to
428390d
Compare
Hermes V1 (250829098.x, RN 0.85 / Expo SDK 56) miscompiles async functions with non-simple params: await resolves to undefined while the body runs later, so useConvexAuth().isAuthenticated never flips true after sign-in, sign-up, or sign-out. Take a plain identifier param and read forceRefreshToken in the body so Hermes sees simple params. Behavior is unchanged. Drop once bundled Hermes ships the fix (facebook/hermes#2030, #2045, #2046). Ref facebook/hermes#1761.
428390d to
aa67695
Compare
|
@erquhart going to close this out. Expo SDK 56 is stable and the The real fix belongs in Hermes, which is what the RN team recommended on my port (react-native#56816). I opened hermes#2045 and #2046 to go with the existing #2030, and expect them to land eventually. Thanks! |
After sign-in on Expo SDK 56 (RN
0.85.3),useConvexAuth().isAuthenticatednever flips totrue. The session lands and/convex/tokenreturns a JWT, but the bridge stays paused. Same on sign-up and sign-out.Cause: Hermes V1 bug facebook/hermes#1761. An async function with non-simple params (destructuring, defaults, or rest) miscompiles when the build preserves native async, so
await fn()resolves toundefinedwhile the body runs later.fetchAccessTokenhit this, and convex-js reads theundefinedas "no token" and silently de-auths.Who hits it (preserve-async builds only, default pipelines are safe):
babel-preset-expobelow56.0.6(fixed upstream in56.0.6via expo/expo#45601, now the default).0.86+withunstable_preserveAsync.Fix: give
fetchAccessTokensimple params (plain options arg,forceRefreshTokenread in the body, still async/await). Hermes then compiles it correctly on any pipeline.The real fix is in Hermes (facebook/hermes#2030, #2045, #2046, all open). Revert this once a bundled Hermes ships them.
Repro: ramonclaudio/convex-better-auth-368-repro. Build, typecheck, and lint clean. Tests unchanged.