Skip to content

perf: optimize scroll and resize handlers with requestAnimationFrame#24

Merged
Tugamer89 merged 3 commits into
mainfrom
perf-optimize-scroll-resize-11222783582423455654
May 25, 2026
Merged

perf: optimize scroll and resize handlers with requestAnimationFrame#24
Tugamer89 merged 3 commits into
mainfrom
perf-optimize-scroll-resize-11222783582423455654

Conversation

@Tugamer89
Copy link
Copy Markdown
Owner

What: Replaced setTimeout-based debouncing with requestAnimationFrame for scroll and resize event listeners in Home.js.
Why: setTimeout creates 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 fetchBooks is delayed until scrolling stops is eliminated, providing a seamless scroll experience.


PR created automatically by Jules for task 11222783582423455654 started by @Tugamer89

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>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Comment thread static/js/views/Home.js Outdated
clearTimeout(scrollDebounceTimer);
scrollDebounceTimer = setTimeout(onScroll, 100);
if (!isScrolling) {
window.requestAnimationFrame(() => {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer globalThis over window

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changed window.requestAnimationFrame to globalThis.requestAnimationFrame.

Comment thread static/js/views/Home.js Outdated
clearTimeout(resizeDebounceTimer);
resizeDebounceTimer = setTimeout(onResize, 100);
if (!isResizing) {
window.requestAnimationFrame(() => {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer globalThis over window

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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>
@Tugamer89 Tugamer89 temporarily deployed to perf-optimize-scroll-resize-11222783582423455654 - booklib PR #24 May 25, 2026 08:40 — with Render Destroyed
@sonarqubecloud
Copy link
Copy Markdown

@Tugamer89 Tugamer89 merged commit 04899b3 into main May 25, 2026
2 checks passed
@Tugamer89 Tugamer89 deleted the perf-optimize-scroll-resize-11222783582423455654 branch May 25, 2026 08:42
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.

1 participant