Skip to content

🐛 Run the latest callback when a debounced call fires - #227

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

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

Conversation

@mbret

@mbret mbret commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Why

A pending debounced call runs the func of the render that made it, with the props and state of that render. If a later render passes a new func, the pending call still uses the old one.

  • Change: a pending call runs the latest func when the delay ends.
  • Gain: a pending call sees the props and state of the latest render.

What's new

Other changes

  • ✅ Tests for the debounce, the latest func and both unmount options
  • 📝 A useDebounced docs page

Details

Unmount

cancelOnUnmount keeps its false default. So a pending call, such as the last save of a form, still runs after the component unmounts. Cancelling it would lose that work without an error.

Returned function

The returned function changes only when wait changes. Before, it also changed with each new func. The JSDoc no longer claims a default wait of 300 ms: the hook has no default.

Release

The branch holds a commit that changed the unmount default, with a BREAKING CHANGE: footer, and its revert. semantic-release ignores a reverted commit and its revert, so merging publishes a patch release. The commit analyzer returns patch for the branch commits.

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm

…test func

A call that was pending when the component unmounted still ran, unless
the caller passed `cancelOnUnmount: true`. A call also ran the `func`
of the render that made it, even if a later render passed a new one.

`cancelOnUnmount` now defaults to `true`, and a call runs the latest
`func` when the delay ends. The returned function changes only when
`wait` changes.

Closes #225.

Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm

BREAKING CHANGE: `useDebounced` cancels a pending call when the
component unmounts. To run it after the unmount, as before, pass
`{ cancelOnUnmount: false }`.
@mbret mbret self-assigned this Nov 3, 2026
@mbret
mbret marked this pull request as ready for review November 3, 2026 21:47
@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:49:13.511016Z 582063d 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.

…n the latest func"

This reverts commit 3869164.

Cancelling a pending call on unmount loses its work, such as the last
save of a form, without an error. Running it late is mostly harmless.
So `cancelOnUnmount` stays `false` by default. The next commit adds
the latest-func fix again, without the breaking change.

Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
A call ran the `func` of the render that made it, even if a later
render passed a new one. It now runs the latest `func`, and the
returned function changes only when `wait` changes.

`cancelOnUnmount` keeps its `false` default, so a pending call, such as
a save, still runs after the component unmounts.

Closes #225.

Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
@mbret mbret changed the title 💥 Cancel pending debounced calls on unmount by default 🐛 Run the latest callback when a debounced call fires Nov 3, 2026
@mbret
mbret merged commit 723b5ac into main Nov 3, 2026
3 of 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.

useDebounced: calls func after unmount by default, and runs the func of the calling render

2 participants