Skip to content

fix(tanstack): keep the page's scroll when Studio shows a save - #809

Merged
tlgimenes merged 1 commit into
mainfrom
fix/tanstack-studio-refresh-keep-scroll
Nov 10, 2026
Merged

tlgimenes merged 1 commit into
mainfrom
fix/tanstack-studio-refresh-keep-scroll

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Why

With #808 live, a save in Studio's site editor re-renders a TanStack page through its router. After every load the router either restores the position saved for the URL or scrolls to the top, and router.invalidate() has no resetScroll option. So an editor working on the footer was scrolled back to the top on every save. The navigation path already passed resetScroll: false, but the invalidate after it, and the refresh for the page's own URL, didn't.

What

  • StudioRefresh runs each refresh with router.options.scrollRestoration set to a function that answers false. The router reads that as "leave the scroll alone", for both restoring and resetting. The site's own setting comes back two frames after the last render, so a later navigation scrolls as usual.
  • Overlapping refreshes share one override. A failed refresh also gives the setting back.
  • Next.js isn't affected: router.refresh() and router.replace(…, { scroll: false }) already keep the scroll.

Verification

  • On a deployed TanStack storefront scrolled to the footer (y≈7500), the page's own __decoStudioRefresh(location.href) went to y=0. Running the same router.invalidate() with scrollRestoration overridden like this kept it near the footer, and the page rendered the new data.
  • New tests in StudioRefresh.test.tsx: restoration answers false during the loads of both paths and is back to the site's value afterwards, including after a failed refresh.
  • bun run check passes. vitest run packages/tanstack: 194 pass.

🤖 Generated with Claude Code


Summary by cubic

Keeps the page's scroll position when Studio shows a save on TanStack pages. Previously, re-rendering the page through router.invalidate() made the router restore the URL's saved position or scroll to the top, so an editor working on the footer jumped back up on every save.

StudioRefresh now sets router.options.scrollRestoration to a function answering false while the refresh runs, which the router reads as "leave the scroll alone". The site's own setting is restored two frames after the last render; overlapping refreshes share the override, and a failed refresh also gives it back. Next.js was already unaffected, since router.refresh() and router.replace(…, { scroll: false }) keep the scroll.

Written for commit fb9a7a9. Summary will update on new commits.

View guided diff Turn on auto-fix

After every load TanStack Router restores the position saved for the URL
or scrolls to the top, and invalidate() takes no resetScroll: an editor
working on the footer was sent back up on every save. While a Studio
refresh runs, scrollRestoration is a function answering false, which the
router reads as "leave the scroll alone"; the site's own setting is back
two frames after the last render.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tlgimenes
tlgimenes requested a review from a team November 10, 2026 18:55
@tlgimenes
tlgimenes merged commit 6492e9c into main Nov 10, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 8.16.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

tlgimenes added a commit to deco-sites/demo-storefront that referenced this pull request Nov 10, 2026
8.16.1 keeps the page's scroll when Studio shows a save: the site editor's
preview no longer jumps to the top after each edit (decocms/blocks#809).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant