Repository navigation
Conversation
throttle and scheduleIdle reset their flag only after the callback returned. If the callback threw once, every later call was ignored. A call made from inside the callback was also dropped, since the flag was still set. Reset the flag before calling the callback. leadingAndTrailing now resets its state in a finally block for the same reason.
🦋 Changeset detectedLatest commit: 7ec3181 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
throttlesetsisThrottled = falseonly aftercallback(...lastArgs)returns. So if the callback throws once, the flag staystrueand every later call returns early. The throttled function is dead for the rest of the component's life, with no error after the first one:The same line also drops a call made from inside the callback (for example a callback that schedules the next poll), because the flag is still
trueat that moment.scheduleIdlehas the same code.leadingAndTrailingbuilds on these and also keeps its ownstateatTrailingwhen the trailing call throws, so its next leading call is skipped too.Change:
throttle/scheduleIdle: reset the flag before calling the callback.leadingAndTrailing: resetstatein afinally. I kept the order there as is, so a call made from inside its trailing callback doesn't turn into a sync recursive leading call.Tests: 3 new cases in
throttle.test.ts(throw inthrottle, call from insidethrottle, throw inleadingAndTrailing(throttle)) and a newschedule-idle.test.tsthat stubsrequestIdleCallbackbefore import (jsdom doesn't have it, so the module picks the fallback otherwise). The 5 new cases fail on main and pass here.scheduledclient (34) + ssr (5) tests,memoandboundstests (they usethrottle), eslint, prettier and tsc are clean. Patch changeset included.Summary by CodeRabbit