Repository navigation
🐛 Ignore dropped renders in two React hooks - #226
Merged
Merged
Conversation
`useLiveRef` wrote the ref inside `useMemo`, during render. If React dropped that render, for example a suspended transition, the ref kept a value that the screen never showed. The ref now updates in a layout effect. `useStore` reads `defaultValue` during render, when it creates a store, so it reads `options.defaultValue` directly. Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
`useMemoCompare` wrote the last value into a ref inside `useMemo`, during render. After a render that React dropped, it compared new values with a value that never committed. An equal value then came back as a new reference, and effects that depend on it ran again. The last committed value now updates in a layout effect. An unchanged value skips `compare`. Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
35ba669 holds only the rename of the useLiveRef test file. A failed `git add` left its other changes unstaged. This commit adds them: - `useLiveRef` writes the ref in a layout effect, after commit, not inside `useMemo` during render. A render that React drops no longer leaves its value in the ref. - `useStore` reads `options.defaultValue` directly, because it creates a store during render. - A test drops a render with a suspended transition. - The useLiveRef docs page says that the ref holds the last committed value. Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
mbret
marked this pull request as ready for review
November 3, 2026 21:27
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dcf71cc037
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…compareFn A store subscribes in its constructor, during render, and useLiveRef now holds the last committed options at that time. If a render changed both the deps and `compareFn`, a synchronous source went through the old `compareFn`. With `of(1, 2)` and a change from `() => true` to `() => false`, the store kept `1`. While the store subscribes, `useStore` now uses the `compareFn` of the render that creates the store. Later values read it from the ref. Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
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.
Why
After React drops a render, for example a suspended transition,
useLiveRefanduseMemoComparekeep values that the screen never showed.useLiveRefthen givesuseObserve,useSubscribeEffectandusePersistSignalsoptions from props that never committed.useMemoComparereturns a new reference for an equal value, so effects that depend on it run again.useLiveRefref holds the last committed value, not the value of the current render.What's new
useLiveRefwrites its ref after commit (closes useLiveRef: a render that never commits leaves its value in the ref #222)useMemoComparecompares with the last committed value (closes useMemoCompare: a render that never commits changes what it compares against #223)Other changes
useStoreuses the current render's options when it creates a storeuseLiveRefdocs page says that the ref holds the last committed valueDetails
Reads during render
useStorecreates its store during render, and the store subscribes to the source in its constructor. The ref holds the last committed options at that time, souseStoreuses the options of the current render instead:defaultValuecomes fromoptionsdirectly.compareFnof the current render. Later values readcompareFnfrom the ref.useSubscribeEffectandusePersistSignalsread the ref only in callbacks, after commit.useMemoCompare
If
valuekeeps its identity,useMemoCompareskipscompare.🔍 Self-reviewed with selfcorrect-review
🤖 Made within harness coverage
🤖 Generated with Claude Code
https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm