Skip to content

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

Open
bxff wants to merge 2 commits into
svecosystem:mainfrom
bxff:fix/debounce-cancel-uncaught-rejection
Open

fix(useDebounce, useThrottle): prevent unhandled rejection on cancel#413
bxff wants to merge 2 commits into
svecosystem: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

🦋 Changeset detected

Latest commit: 4da898d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
runed Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another 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

2 participants