perf: optimize scroll and resize handlers with requestAnimationFrame#24
Conversation
Replaced `setTimeout`-based debouncing with `requestAnimationFrame` for `scroll` and `resize` event listeners in `Home.js`. This change improves UI rendering performance and responsiveness by syncing these updates with the browser's paint cycle, preventing main thread blocking and ensuring smoother continuous scrolling. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
| clearTimeout(scrollDebounceTimer); | ||
| scrollDebounceTimer = setTimeout(onScroll, 100); | ||
| if (!isScrolling) { | ||
| window.requestAnimationFrame(() => { |
There was a problem hiding this comment.
Prefer globalThis over window
There was a problem hiding this comment.
Done. Changed window.requestAnimationFrame to globalThis.requestAnimationFrame.
| clearTimeout(resizeDebounceTimer); | ||
| resizeDebounceTimer = setTimeout(onResize, 100); | ||
| if (!isResizing) { | ||
| window.requestAnimationFrame(() => { |
There was a problem hiding this comment.
Prefer globalThis over window
Replaced `setTimeout`-based debouncing with `requestAnimationFrame` for `scroll` and `resize` event listeners in `Home.js`. This change improves UI rendering performance and responsiveness by syncing these updates with the browser's paint cycle, preventing main thread blocking and ensuring smoother continuous scrolling. Updated to use globalThis per review feedback. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|



What: Replaced
setTimeout-based debouncing withrequestAnimationFrameforscrollandresizeevent listeners inHome.js.Why:
setTimeoutcreates artificial delays and forces execution out of sync with the display's refresh rate, leading to visual jank and delayed infinite scroll triggers.Impact: Synchronizes scroll-bound logic with the browser paint cycle, resulting in significantly smoother UI rendering and more responsive infinite scroll triggering during rapid continuous scrolling.
Measurement: Compare scrolling behavior before and after on a long list of books. The "stuck" feeling where
fetchBooksis delayed until scrolling stops is eliminated, providing a seamless scroll experience.PR created automatically by Jules for task 11222783582423455654 started by @Tugamer89