Repository navigation
fix: react #467 crash in useValueRef on suspense replay - #12499
Merged
Merged
Conversation
useValueRef only called `use(readyPromise)` while the ref was not ready. When a component suspended there and was replayed after the promise resolved, `ready` had flipped to true so `use` was skipped; React only switches back to the mount dispatcher inside `use`, so the following useSyncExternalStore threw "Update hook called on initial render" (crashing the Mask Network entrance in the X sidebar via ToolboxHintForWallet -> useGuideStepState). - Always call `use(readyPromise)` for ValueRefWithReady. - Mark readyPromise as fulfilled (React thenable protocol) so `use` returns synchronously once ready instead of suspending briefly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
|
This is strange, since react document (https://react.dev/reference/react/use#use-promise) states:
|
This branch was successfully deployed
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
Production crash (v2.37.0) on the Mask Network entrance in the X sidebar:
Root cause
useValueRefcalleduse(readyPromise)only while!ref.ready.useGuideStepStatereads two refs in a row. If the second ref isn't ready, the component suspends. When React replays it after the promise resolves,readyis alreadytrue, souseis skipped. React only switches from the update dispatcher back to the mount dispatcher insideuse, so the nextuseSyncExternalStorehitsupdateWorkInProgressHookwith no current fiber and throws #467.Fix
useValueRef: always calluse(readyPromise)forValueRefWithReady, so the hook order is the same on every render and replay.ValueRefWithReady: oncereadyPromiseresolves, mark it withstatus: 'fulfilled'andvalue(React's thenable protocol). That wayusereturns synchronously for refs that are already ready instead of suspending briefly.Testing
🤖 Generated with Claude Code