Skip to content

🐛 Ignore dropped renders in two React hooks - #226

Merged
mbret merged 4 commits into
mainfrom
claude/awesome-bell-2a040j
Nov 3, 2026
Merged

mbret merged 4 commits into
mainfrom
claude/awesome-bell-2a040j

Conversation

@mbret

@mbret mbret commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Why

After React drops a render, for example a suspended transition, useLiveRef and useMemoCompare keep values that the screen never showed. useLiveRef then gives useObserve, useSubscribeEffect and usePersistSignals options from props that never committed. useMemoCompare returns a new reference for an equal value, so effects that depend on it run again.

  • Change: both hooks write their ref in a layout effect, after commit, not during render.
  • Gain: a dropped render leaves both hooks as the last commit left them.
  • Cost: during render, the useLiveRef ref holds the last committed value, not the value of the current render.

What's new

Other changes

  • 🐛 useStore uses the current render's options when it creates a store
  • ✅ A test per hook drops a render with a suspended transition
  • 📝 The useLiveRef docs page says that the ref holds the last committed value

Details

Reads during render

useStore creates its store during render, and the store subscribes to the source in its constructor. The ref holds the last committed options at that time, so useStore uses the options of the current render instead:

  • defaultValue comes from options directly.
  • While the store subscribes, a synchronous source goes through the compareFn of the current render. Later values read compareFn from the ref.

useSubscribeEffect and usePersistSignals read the ref only in callbacks, after commit.

useMemoCompare

If value keeps its identity, useMemoCompare skips compare.

🔍 Self-reviewed with selfcorrect-review
🤖 Made within harness coverage

🤖 Generated with Claude Code

https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm

`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 mbret self-assigned this Nov 3, 2026
@mbret
mbret marked this pull request as ready for review November 3, 2026 21:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T21:30:19.245108Z dcf71cc Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/lib/binding/useObserve/useStore.ts Resolved
…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
@mbret
mbret merged commit 18c268b into main Nov 3, 2026
4 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.

useMemoCompare: a render that never commits changes what it compares against useLiveRef: a render that never commits leaves its value in the ref

2 participants