react-timing-hooks icon indicating copy to clipboard operation
react-timing-hooks copied to clipboard

fix: make useThrottle resilient to remounting

Open deltaidea opened this issue 2 weeks ago • 0 comments

The cleanup function cleared the timeout without resetting the timeout ref, so in strict mode (or in general when React calls cleanup but then ends up not unmounting) the effect would get stuck, never actually calling the callback.

See: https://react.dev/learn/lifecycle-of-reactive-effects#how-react-verifies-that-your-effect-can-re-synchronize

I've encountered this bug while using Next.js in watch mode. Happy I could track it down to the root cause. The additional unit test fails without the proposed change.

deltaidea avatar Dec 19 '25 13:12 deltaidea