⚡ Bolt: Optimized scroll event listeners and DOM queries#124
Conversation
- Added state tracking to `scrollTopBtn` visibility logic to prevent redundant `classList` mutations on every frame.
- Added `{ passive: true }` to `scrollTopBtn` listener for non-blocking scrolling.
- Added state tracking to `navBtns` active class logic to only update the DOM when the active section changes.
- Cached `#systemTime` lookup in `updateSystemTime` to prevent O(N) DOM querying.
Co-authored-by: kaitoartz <56949089+kaitoartz@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. |
💡 What:
isScrollTopVisibleandcurrentActiveBtn) to scroll event listeners injs/script.js.{ passive: true }to thescrollTopBtnscroll event listener.#systemTimeDOM lookup outside of theupdateSystemTimeperiodic function.🎯 Why:
Unconditional DOM mutations (
classList.add/remove) inside high-frequency scroll handlers cause layout thrashing and unnecessary CPU overhead. Similarly, querying the DOM on every interval tick wastes CPU resources over time. Passive event listeners ensure the browser can scroll smoothly without waiting for the JS event loop to complete.📊 Impact:
Eliminates layout thrashing and redundant DOM writes during scrolling. Removes an O(N) DOM lookup that fired every second. Improves overall scroll framerate and reduces background CPU/battery usage.
🔬 Measurement:
Check
index.htmlin the browser, verify that scrolling up and down properly reveals the scroll-to-top button and updates the active nav link, and check the system time updates accurately. Use DevTools Performance tab to observe fewer DOM updates and style recalculations during scrolling.PR created automatically by Jules for task 4674792295466490664 started by @kaitoartz