Skip to content

perf: throttle scroll and debounce resize in VirtualList - #1371

Open
waterWang wants to merge 1 commit into
Fluxora-Org:mainfrom
waterWang:perf/virtual-list-throttle-scroll-resize
Open

perf: throttle scroll and debounce resize in VirtualList#1371
waterWang wants to merge 1 commit into
Fluxora-Org:mainfrom
waterWang:perf/virtual-list-throttle-scroll-resize

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Throttle the scroll event listener in VirtualList.tsx using requestAnimationFrame so updateRange runs at most once per frame during fling-scroll. Debounce the resize listener using the shared VIEWPORT_RESIZE_DEBOUNCE_MS (150ms) constant, consistent with the codebase's established pattern in Sidebar.tsx.

Changes

  • src/components/VirtualList.tsx: Added rafRef and resizeTimerRef to track pending animation frames and resize timeouts. Created handleScroll (rAF-throttled) and handleResize (debounced) closures. The cleanup function cancels any pending rAF or timeout to prevent state updates on unmounted components. Falls back to synchronous execution when requestAnimationFrame is unavailable (jsdom/SSR).

  • src/components/__tests__/VirtualList.test.tsx: Updated scroll tests to use vi.useFakeTimers() and vi.advanceTimersToNextFrame() after fireEvent.scroll, so the throttled rAF callback fires and test assertions pass. All 6 existing tests remain green.

Testing

  • All 6 VirtualList tests pass: NODE_ENV=development npx vitest run src/components/__tests__/VirtualList.test.tsx
  • RecipientStreams filter tests that use VirtualList also pass.
  • TypeScript build: tsc -b --noEmit shows no VirtualList-related errors.

Closes #711

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VirtualList.tsx scroll/resize listeners are unthrottled, unlike the codebase's established debounce pattern

1 participant