Skip to content

tanstack: iOS Safari restores bfcache pages at the top (router-core sets scrollRestoration=manual on persisted pageshow) #835

Open

Description

@aline-pereira

Package: @decocms/tanstack 7.x (seen on 7.86.0, @tanstack/router-core 1.171.34, @tanstack/react-router 1.170.41).

What happens

On iOS Safari, a page restored from the back/forward cache comes back at the top, even though the browser kept the page (pageshow.persisted === true). Long listings lose the reader's place on every "back" from a product page once the document is bfcache-eligible.

Why

createDecoRouter enables scrollRestoration by default. router-core then registers, in the router constructor (setupScrollRestoration, scroll-restoration.js, from TanStack/router#8519):

addEventListener("pagehide", () => { history.scrollRestoration = "auto"; /* snapshot */ });
addEventListener("pageshow", (event) => {
  if (event.persisted) history.scrollRestoration = "manual";
});

On iOS, the persisted pageshow is dispatched before WebKit restores the bfcache scroll position. With "manual" set there, WebKit skips its own restoration, and no navigation happens on a bfcache resume, so the router does not restore it either. Result: scrollY = 0. TanStack/router#8519 itself notes that bfcache resume on Safari was not verified.

Evidence (real iPhone, iOS Safari)

deco-sites/oficina-tanstack, listing /todas-as-roupas served with a bfcache-eligible document (Cache-Control: private, no-cache), "load more" to 80–160 products, scroll down, open a product, swipe back. An on-page diagnostic panel recorded pageshow.persisted and scrollY:

Build bfcache scroll after back
as is yes 0 (was 14 829)
+ a pageshow listener registered after the router that sets history.scrollRestoration = "auto" when persisted yes exact, 3/3 (14 811, 22 483, 29 906)

Details and videos: deco-sites/oficina-tanstack#665 (comments of 17/11).

Prior art

SvelteKit restores the current entry's position synchronously inside the persisted pageshow handler (sveltejs/kit#17255); Remix handled iOS scroll on bfcache resume (remix-run/remix#12011).

Proposal

In createDecoRouter, after the router is created (so after router-core's listener), on a persisted pageshow: put "auto" back so the browser restores, then hand scroll back to the router ("manual") on the first scroll event, or after a short timeout when nothing scrolls. PR to follow against 7.x. Worth also reporting upstream in TanStack/router.

Activity

  1. github-actions commented on Nov 18, 2026

    @github-actions

    🎉 This issue has been resolved in version 7.87.1 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions