Skip to content

🐛 Call the committed callback in the unmount hook - #228

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

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

Conversation

@mbret

@mbret mbret commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Why

If React discards a render, for example a suspended transition, useUnmount calls the fn from that uncommitted render. So the wrong callback runs on unmount.

The docs for useMount, useEffectOnce and useUnmount promise "once" and "on unmount". StrictMode in development runs them twice or early.

  • Change: useUnmount reads fn through useLiveRef. The docs describe the StrictMode behaviour.
  • Gain: useUnmount calls the committed fn, and readers know why these hooks run twice in development.

What's new

Other changes

  • 📝 A useUnmount docs page
  • ✅ Tests for the latest fn and for a render that React discards

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


Generated by Claude Code

`useUnmount` wrote its `fn` into a ref during render. If React dropped
that render, for example a suspended transition, the unmount called a
`fn` from a render that never committed. The ref now comes from
`useLiveRef`, which updates after commit.

Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
…eUnmount early

In development, under StrictMode, React mounts each component twice.
`useMount` and `useEffectOnce` then run twice, and `useUnmount` runs
once while the component stays mounted. Their pages now say so, and
`useUnmount` gets a page.

Closes #224.

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 22:03
@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-03T22:05:34.720287Z a65f7f6 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.

@mbret
mbret merged commit 6dc6009 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.

useMount, useEffectOnce and useUnmount: StrictMode runs them twice, or before unmount

2 participants