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

useDebounce race condition when already running -> can lose new call #139

Closed
Coronon opened this issue Nov 2, 2024 · 0 comments · Fixed by #146
Closed

useDebounce race condition when already running -> can lose new call #139

Coronon opened this issue Nov 2, 2024 · 0 comments · Fixed by #146

Comments

@Coronon
Copy link
Contributor

Coronon commented Nov 2, 2024

Describe the bug

While working on #134 I noticed that all scheduled calls will resolve the callback and then call reset, which sets timeout to undefined. I first though that this could lead to calls that are debounced while the callback handler is already running to not be cancelable. It turns out that they can simply get completely lost:
When the setTimeout is finally called, resolve can already be null from the previous runs reset call, which will lead to the actual callback to never be called.

While I don't think the later callback should simply be lost, this could be one of those: "It's a feature, not a bug" instances. Either way the behavior should be clearly documented.

Reproduction

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

Logs

No response

System Info

System:
    OS: macOS 15.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 24.22 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.1.0 - /opt/homebrew/bin/node
    npm: 10.9.0 - /opt/homebrew/bin/npm
    pnpm: 9.12.3 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 130.0.6723.92
    Safari: 18.1

Severity

annoyance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant