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) #146

Merged
merged 4 commits into from
Nov 25, 2024

Conversation

Coronon
Copy link
Contributor

@Coronon Coronon commented Nov 25, 2024

Reopen of #141 on a new branch name

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 25, 2024

🦋 Changeset detected

Latest commit: 87f8ebd

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

Copy link
Contributor

github-actions bot commented Nov 25, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
runed ✅ Ready (View Log) Visit Preview 87f8ebd

Copy link
Member

@huntabyte huntabyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@huntabyte huntabyte merged commit 5453240 into svecosystem:main Nov 25, 2024
4 checks passed
@Coronon Coronon deleted the fix/useDebounce-race-condition branch November 25, 2024 15: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
2 participants