question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debouncing updates produces weird behaviour

See original GitHub issue

Using the hook returned from createLocalStorageStateHook produces weird behavior when debouncing updates.

Using a controlled input, with debouncing using a useEffect, the updates eventually propagates to all components (not always all) using the state.

Using an uncontrolled input, with normal debouncing, the updates seemingly propagates randomly to the components using the state.

LocalStorage is always updated.

We’ve simplified our case and created a reproducible example in this codesandbox:
https://codesandbox.io/s/use-local-storage-state-debounce-u3p7m?file=/src/App.tsx

I’ve quickly gone through the source for use-local-storage-state, and can’t find anything to indicate this should happen. I’m wondering if we’ve hit some limitation of React or something.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
astoilkovcommented, Nov 12, 2021

I fixed the issue and released an update. Thanks for the time to report and investigate the issue!

1reaction
astoilkovcommented, Oct 21, 2021

Thanks for reporting this and all the detailed information. I think I should fix this. It’s both slow and buggy for React 17 which I believe will be popular for some more time. At some point, I will remove it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using debounce within the React render cycle | by Chanon Roy
Debounce behaviour is helpful when we want additional control over when a function is called. When implemented properly, we can call a debounced...
Read more >
'debounce' shifts execution of 'later' callback #17210 - GitHub
Recently I've encountered a weird problem facing unexpected behaviour when using debounce . More specifically: for an unknown reason the result ...
Read more >
A Guide to Debouncing
Quite a lot, and every bounce of every switch was different. Many produced only high speed hash till a solid one or zero...
Read more >
What is the "debounce" function in JavaScript? - Stack Overflow
I have updated my answer to annotate the working version from the link. ... The important thing to note here is that debounce...
Read more >
Is debouncing the update of a context a good practice? - Reddit
My instinct is that debouncing one state update after another is likely to lead to weird behavior and/or bugs, but that's just my...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found