Fix blog category scroll behavior#3034
Conversation
Greptile SummaryThis PR fixes a scroll jump that occurred when switching blog categories by introducing
Confidence Score: 4/5The fix is targeted and safe to merge; the only concern is defensive over-engineering in the scroll restoration that could cause a minor UX glitch under fast interaction. The core logic — using noScroll: true + capturing/restoring the scroll position and narrowing the onNavigate condition — is correct and well-scoped. The triple window.scrollTo pattern, especially the 100 ms timeout, is the one rough edge: it will forcibly reset a user's scroll position if they move the page within 100 ms of clicking a category, which is a present behavioral quirk on the changed path rather than a speculative future risk. Only src/routes/blog/[[page]]/+page.svelte changed; the triple scroll restore in handleCategoryClick is worth a second look. Important Files Changed
Reviews (1): Last reviewed commit: "Fix blog category scroll behavior" | Re-trigger Greptile |
| await tick(); | ||
| window.scrollTo(scrollPosition); | ||
| requestAnimationFrame(() => window.scrollTo(scrollPosition)); | ||
| setTimeout(() => window.scrollTo(scrollPosition), 100); |
There was a problem hiding this comment.
Redundant and fragile triple scroll restoration
After goto with noScroll: true, the function fires window.scrollTo three separate times: once immediately, once in a requestAnimationFrame, and once in a setTimeout 100 ms later. The 100 ms timer is the problematic one — if the user intentionally scrolls within that window after clicking a category, the timer forcibly snaps them back to the pre-click position. Since goto is already called with noScroll: true, a single restore after await tick() should be sufficient; the duplicate RAF and timeout calls are fighting browser behavior empirically rather than addressing the root cause.
Fixes #3033