-
-
Notifications
You must be signed in to change notification settings - Fork 202
bug: rewrite throttle utility to robustly handle trailing edge #8988
Copy link
Copy link
Closed
Labels
aibugSomething isn't workingSomething isn't workingcoreCore framework functionalityCore framework functionality
Description
Context
The current throttle implementation in src/util/Function.mjs has two issues:
- Inefficiency: It clears and recreates
setTimeouton every call during the cooldown period solely to capture the latest arguments. - Fragility: It relies on a strict timing check
(Date.now() - lastRanDate) >= delayinside the timeout. If the browser fires the timeout even 1ms early (common jitter), the trailing call is silently dropped.
Objective
Rewrite throttle to use a standard, robust pattern:
- Leading Edge: Execute immediately if
now - lastRun > delay. - Trailing Edge: If inside cooldown, store the
latestArgs. Schedule a SINGLE timeout for the remaining time if one doesn't exist. - Execution: When the timeout fires, execute with
latestArgs, updatelastRun, and clear the timeout flag.
This ensures ScrollManager (and other components) never lose the final update event, preventing visual desyncs.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
aibugSomething isn't workingSomething isn't workingcoreCore framework functionalityCore framework functionality