Conversation
- cached `document.documentElement.scrollHeight` and `window.innerHeight` in `scrollprogress` and `sectionnav` to prevent forced synchronous layouts during active scroll events and intersection observer callbacks. - implemented `resizeobserver` and tied into existing global debounced window resize handler to maintain layout accuracy. - updated `.jules/bolt.md` with learnings on layout thrashing.
|
👋 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. |
Deploying personal-website with
|
| Latest commit: |
6299288
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5af4c87b.personal-website-5ns.pages.dev |
| Branch Preview URL: | https://perf-cache-dimensions-scroll.personal-website-5ns.pages.dev |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6299288ae9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (window.scrollY < 100) { | ||
| bestSection = this.sections[0]?.id; | ||
| } else if (window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - 50) { | ||
| } else if (window.scrollY + this.cachedWindowHeight >= this.cachedDocHeight - 50) { |
There was a problem hiding this comment.
Recompute nav bounds when page height changes
SectionNav now relies on cachedDocHeight/cachedWindowHeight for the bottom-of-page override, but those caches are only refreshed in init() and on window resize; they are not updated when document height changes from normal runtime events (for example lazy-loaded images in index.html or other content expansion). In that case, handleIntersection compares window.scrollY against stale dimensions and can activate the last nav item too early or fail to activate it near the true bottom until a manual resize occurs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR caches document.documentElement.scrollHeight and window.innerHeight in the ScrollProgress and SectionNav objects to avoid querying DOM layout properties during scroll handlers and IntersectionObserver callbacks, reducing layout thrashing.
Changes:
- Added
cachedDocHeightandcachedWindowHeightproperties toScrollProgressandSectionNav, withcacheDimensions()methods to refresh them. - Added a
ResizeObserverinScrollProgress.init()to keep cached values up to date when document dimensions change. - Added
cacheDimensions()calls to the existing debounced window resize handler.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| script.js | Caches scroll/window dimensions in ScrollProgress and SectionNav; adds ResizeObserver for ScrollProgress; updates resize handler. |
| .jules/bolt.md | Documents the new caching convention for scroll-related DOM properties. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| // cache dimensions to prevent forced synchronous layouts during intersection observer callbacks | ||
| this.cacheDimensions(); |
| ## 2024-05-16 - [Frontend Performance: Caching getBoundingClientRect in Animation Loops] | ||
| **Learning:** Frequent calls to `getBoundingClientRect()` inside `requestAnimationFrame` loops or scroll handlers (like in `MagneticLetters`, `MobileTouchRepel`, and `ParallaxLayers`) cause significant layout thrashing and forced synchronous layouts, degrading rendering performance. | ||
| **Action:** Always pre-calculate and cache document-relative element positions during initialization (`init()`). Update this cache on window resize events and after custom fonts load (using `document.fonts.ready.then()`). During active animations (`animate()`, `update()`, etc.), calculate viewport-relative positions using the cached document coordinates minus the current scroll offset (`window.scrollX` / `window.scrollY`) instead of directly querying the DOM. No newline at end of file | ||
| **Action:** Always pre-calculate and cache document-relative element positions during initialization (`init()`). Update this cache on window resize events and after custom fonts load (using `document.fonts.ready.then()`). During active animations (`animate()`, `update()`, etc.), calculate viewport-relative positions using the cached document coordinates minus the current scroll offset (`window.scrollX` / `window.scrollY`) instead of directly querying the DOM.\n## 2026-03-16 - [Frontend Performance: Caching scrollHeight and innerHeight in Scroll/IntersectionObserver loops] |
| if (typeof MagneticLetters !== 'undefined') MagneticLetters.cachePositions(); | ||
| if (typeof MobileTouchRepel !== 'undefined') MobileTouchRepel.cachePositions(); | ||
| if (typeof ParallaxLayers !== 'undefined') ParallaxLayers.cachePositions(); | ||
| if (typeof ScrollProgress !== 'undefined') ScrollProgress.cacheDimensions(); |
💡 what: cached
document.documentElement.scrollHeightandwindow.innerHeightwithinscrollprogressandsectionnavobjects.🎯 why: repeatedly querying dom properties like
scrollheightandinnerheightwithin scroll event listeners and intersection observer callbacks forces synchronous layout calculations, leading to layout thrashing and reduced rendering performance.📊 impact: eliminates forced synchronous layouts during scrolling and intersection checking, maintaining a smoother 60fps experience, particularly noticeable on longer scrolls or lower-end devices.
🔬 measurement: run the frontend application and observe the performance timeline in devtools during scroll; forced layout recalculations related to
scrollprogressandsectionnavwill no longer appear. tests verified vianode --testand a playwright script.PR created automatically by Jules for task 11781990351487005585 started by @dttdrv