Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: useDebounce race condition (#139) #141

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Coronon
Copy link

@Coronon Coronon commented Nov 2, 2024

Rewrite useDebounce to gracefully handle new debounced calls while a previous call is running.
We isolate all actual callback invocations from each other by using a new set of timeout, promise, resolve and reject when their previously associated callback begins to run.

Fixes #139

Current broken reproduction:
https://stackblitz.com/edit/sveltejs-kit-template-default-bpdvwu?file=src%2Froutes%2F%2Bpage.svelte

New working reproduction:
https://stackblitz.com/edit/sveltejs-kit-template-default-uvrj4j?file=src%2Froutes%2F%2Bpage.svelte

This PR should also greatly improve DX for #134 which I would implement after this is merged :)

Copy link

changeset-bot bot commented Nov 2, 2024

🦋 Changeset detected

Latest commit: 6d15216

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

@Coronon Coronon marked this pull request as draft November 2, 2024 01:51
@Coronon Coronon marked this pull request as ready for review November 2, 2024 01:56
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 race condition when already running -> can lose new call
1 participant