Skip to content

Fix blog category scroll behavior#3034

Open
NathenDT wants to merge 1 commit into
appwrite:mainfrom
NathenDT:main
Open

Fix blog category scroll behavior#3034
NathenDT wants to merge 1 commit into
appwrite:mainfrom
NathenDT:main

Conversation

@NathenDT
Copy link
Copy Markdown

@NathenDT NathenDT commented Jun 2, 2026

Fixes #3033

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 2, 2026

Greptile Summary

This PR fixes a scroll jump that occurred when switching blog categories by introducing handleCategoryClick, which captures the scroll position before a goto call and restores it afterward. It also tightens the onNavigate scroll-to-header logic so it only fires on true pagination transitions (same search params, different page number, link type), preventing the header scroll from triggering on category changes.

  • handleCategoryClick uses goto with noScroll: true and keepFocus: true, then restores the captured scroll position three times (immediate, requestAnimationFrame, and setTimeout at 100 ms) — the 100 ms timeout is redundant and can override intentional user scrolling within that window.
  • getBlogPageNumber replaces a raw parseInt call with a safe parser that falls back to 1 on NaN, and data-sveltekit-noscroll is correctly added to the category links to cover modified-click fallthrough paths.

Confidence Score: 4/5

The 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

Filename Overview
src/routes/blog/[[page]]/+page.svelte Adds handleCategoryClick to preserve scroll position on category navigation and refines onNavigate to only auto-scroll to the articles header on true pagination transitions; minor issue with triple-redundant window.scrollTo calls including a 100 ms timeout that can interrupt intentional user scrolling.

Reviews (1): Last reviewed commit: "Fix blog category scroll behavior" | Re-trigger Greptile

Comment on lines +121 to +124
await tick();
window.scrollTo(scrollPosition);
requestAnimationFrame(() => window.scrollTo(scrollPosition));
setTimeout(() => window.scrollTo(scrollPosition), 100);
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.

P2 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.

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.

Bug: On the blogs page, filtering by category scrolls to the top.

1 participant