Skip to content

fix(useDebounce, useThrottle): prevent unhandled rejection on cancel#413

Open
bxff wants to merge 1 commit intosvecosystem:mainfrom
bxff:fix/debounce-cancel-uncaught-rejection
Open

fix(useDebounce, useThrottle): prevent unhandled rejection on cancel#413
bxff wants to merge 1 commit intosvecosystem:mainfrom
bxff:fix/debounce-cancel-uncaught-rejection

Conversation

@bxff
Copy link
Copy Markdown

@bxff bxff commented Mar 7, 2026

Calling cancel() rejects the pending promise with "Cancelled", which throws an Uncaught (in promise) Cancelled error when the caller doesn't have a .catch() handler attached (fire-and-forget usage).

This adds an internal no-op .catch() to the promise when it's created, so the rejection is always handled internally. Callers who explicitly use .catch() or await + try/catch still receive the rejection as before.

The same fix is applied to useThrottle which has the identical issue (noted in the comments on #365).

Closes #365

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 7, 2026

⚠️ No Changeset found

Latest commit: 7e1a82c

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

@bxff bxff closed this Mar 7, 2026
Add an internal no-op .catch() handler to the promise created by
useDebounce and useThrottle. This prevents 'Uncaught (in promise)
Cancelled' errors when cancel() is called without the caller having
attached a .catch() handler.

Callers who explicitly handle rejections (via .catch() or try/catch
with await) are unaffected.

Closes svecosystem#365
@bxff bxff reopened this Mar 7, 2026
@bxff bxff force-pushed the fix/debounce-cancel-uncaught-rejection branch from 84f51bf to 7e1a82c Compare March 7, 2026 20:41
@bxff bxff changed the title fix(useDebounce, useThrottle): resolve instead of reject on cancel fix(useDebounce, useThrottle): prevent unhandled rejection on cancel Mar 7, 2026
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.

useDebounce cancel throws uncaught promise error

1 participant