Skip to content

fix: cancel correct debounced instance on unmount in useDebounceCallback#720

Open
haunc08 wants to merge 1 commit intojuliencrn:masterfrom
haunc08:fix/debounce-callback-cancel-on-unmount
Open

fix: cancel correct debounced instance on unmount in useDebounceCallback#720
haunc08 wants to merge 1 commit intojuliencrn:masterfrom
haunc08:fix/debounce-callback-cancel-on-unmount

Conversation

@haunc08
Copy link
Copy Markdown

@haunc08 haunc08 commented Apr 10, 2026

Summary

The useUnmount cleanup in useDebounceCallback was cancelling a separate debounced instance (created in useEffect) instead of the actual instance used by callers (created in useMemo). This meant pending debounced calls were never cancelled on unmount.

Changes

  • Store the debouncedFuncInstance from useMemo in the ref directly, so useUnmount cancels the correct instance
  • Remove the redundant useEffect that created a separate unused debounced instance
  • Add unit test verifying pending callbacks are cancelled on unmount

The unmount cleanup was cancelling a separate debounced instance created
in useEffect rather than the actual instance used by callers (created in
useMemo). Store the useMemo instance in the ref instead, and remove the
redundant useEffect.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 10, 2026

⚠️ No Changeset found

Latest commit: f980d77

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

2 participants