perf: throttle scroll and debounce resize in VirtualList - #1371
Open
waterWang wants to merge 1 commit into
Open
Conversation
Wrap the scroll event listener in a requestAnimationFrame throttle so updateRange runs at most once per frame during fling-scroll. Debounce the resize listener using the shared VIEWPORT_RESIZE_DEBOUNCE_MS constant (150ms), consistent with the codebase's established pattern. Closes Fluxora-Org#711
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Throttle the
scrollevent listener inVirtualList.tsxusingrequestAnimationFramesoupdateRangeruns at most once per frame during fling-scroll. Debounce theresizelistener using the sharedVIEWPORT_RESIZE_DEBOUNCE_MS(150ms) constant, consistent with the codebase's established pattern inSidebar.tsx.Changes
src/components/VirtualList.tsx: AddedrafRefandresizeTimerRefto track pending animation frames and resize timeouts. CreatedhandleScroll(rAF-throttled) andhandleResize(debounced) closures. The cleanup function cancels any pending rAF or timeout to prevent state updates on unmounted components. Falls back to synchronous execution whenrequestAnimationFrameis unavailable (jsdom/SSR).src/components/__tests__/VirtualList.test.tsx: Updated scroll tests to usevi.useFakeTimers()andvi.advanceTimersToNextFrame()afterfireEvent.scroll, so the throttled rAF callback fires and test assertions pass. All 6 existing tests remain green.Testing
NODE_ENV=development npx vitest run src/components/__tests__/VirtualList.test.tsxtsc -b --noEmitshows no VirtualList-related errors.Closes #711