vercel / vercel/next.js

Quit / reopen Safari + back navigation - Content of latest visited page in history is persisted

Open
#90,080 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

linear: next Linking and Navigating locked Pages Router
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/quiet-tdd-rzgf2d

To Reproduce
  1. Open Safari browser
  2. Make sure Safari resumes with last session tabs when opening
    • On MacOS: configure the "Safari opens with" setting to "All windows from last session" or "All non-private windows from last session" (Safari > Settings > General > "Safari opens with")
    • On iOS this should be default behavior, haven't found a specific setting related to it
  3. Open the reproduction codesandbox standalone preview (https://rzgf2d-3000.csb.app/)
  4. Click the "Route 1" link
  5. Quit Safari browser
    • On MacOS via Toolbar > Right click Safari browser icon > Select "Quit"
    • On iOS:
      • Swipe up from the bottom to the middle of your screen and hold until you see the App Switcher
      • Swipe the Safari iOS browser app screen up and out of your screen to quit it
  6. Re-open Safari browser
    • Assert the "Route 1" codesandbox preview page is shown (or select that tab after reopening)
    • Assert the back button seems interactable and is not disabled
    • Assert the address bar ends with: /route-1
  7. Click the back button
    • Assert the "Route 1" page content is still showing (scroll position might change)
    • Assert the address bar actually points at /
Current vs. Expected behavior

Following the steps of reproduction, I would expect the content of the "Home" route to be shown after using the back button on the "Route 1" route, but the content of the "Route 1" route is persisted.

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:07:05 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 12
Binaries:
  Node: 20.19.5
  npm: 10.8.2
  Yarn: N/A
  pnpm: 10.11.0
Relevant Packages:
  next: 16.2.0-canary.48 // Latest available version is detected (16.2.0-canary.48).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Linking and Navigating, Pages Router

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local), Vercel (Deployed)

Additional context

General description: Opening a Next.JS site in Safari browser, navigating to different pages, quitting Safari browser and reopening it (resuming from that Next.JS site) and then trying to use the browser back button results in the actual route in address bar to update correctly, scroll might be updated (assumed restoration), but the contents of the latest page that was visited is persisted - never showing the actual previous pages content.

This mainly impacts users on iOS as just swiping away the browser app, while later reopening it, while you keep a Next.JS powered site open in a tab will result in this situation (assumed common browsing behavior) - With reported confusion and frustration for users as a result.

Reproducible on operating systems (including, but unknown if limited to):

  • MacOS Sequoia (15)
  • MacOS Tahoe (26)
  • iOS 26

Reproducible on browser(s):

  • MacOS: Safari browser
  • iOS: Any browser (assumed because of safari under the hood)

Reproduction steps tested on Chrome and Firefox on MacOS and behavior is as expected: pages back in history show as expected after quit and reopening of the browser.

I've not as of yet been able to pinpoint a specific Next.JS version that introduced this behavior, but it does affect both the Pages and App router in various Next.JS versions. It happens both when using next/link and regular anchor tags.

Versions / routers of Next.JS in projects where I've reproduced this issue:

  • Next.JS ^12.2.0 - Pages router - Hosted on vercel
  • Next.JS ^14.2.3 - Pages router - Hosted on vercel
  • Next.JS ^14.2.35 - App router - Hosted on vercel
  • Next.JS 15.5.9 - Pages router - Hosted on vercel
    • Tested local dev / build + start of this version, same behavior
  • Next.JS ^16.1.6 - App router - Hosted on vercel

Note: Similar behavior has anecdotally been reported to also apply when leaving a Next.JS site in iOS Safari browser tab open for long in the background and returning to it - reported duration was 3 hours, not reproduced yet, but assumed to be caused by similar underlying issue.

Note: So far this affects any Next.JS powered site I've tried to reproduce with, including https://vercel.com/ (tested through https://vercel.com/blog and navigating to blog post)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and the Pages Router navigation and history behavior described in the issue. Reproduce the Safari quit-and-reopen flow, then verify that using Back changes both the URL and rendered content from /route-1 to the Home route.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.