nextjs - 💡(How to fix) Fix Scroll position restored to previous page’s height after browser back, when using cookie.set in server function within useEffect [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#86528Fetched 2026-04-08 02:10:27
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
4
Author
Timeline (top)
mentioned ×2subscribed ×2commented ×1issue_type_added ×1

Root Cause

Code Example

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.12.0
  npm: 10.5.0
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 16.1.0-canary.2 // Latest available version is detected (16.1.0-canary.2).
  eslint-config-next: 15.0.0-rc.0
  react: 19.0.0-rc-f994737d14-20240522
  react-dom: 19.0.0-rc-f994737d14-20240522
  typescript: 5.4.5
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/revalidate-scroll-restoration-forked-cx8xx7

To Reproduce

  1. Suppose there are two pages: Home and Page2.
  2. Home page has a height of 4000px. Navigate to Page2 (height: 2000px) from a Link component at the very bottom of the Home page.
  3. On Page2, use the browser back button (or router.back()).
  4. The scroll position on the Home page is restored to 2000px (the height of Page2), rather than the bottom of Home page (4000px).

Current vs. Expected behavior

Current behavior: After navigating from Home (height: 4000px) to Page2 (height: 2000px) from the bottom of Home, then navigating back, the Home page scroll position is restored to 2000px (Page2 height) instead of the previous 4000px.

Expected behavior: After navigating back, the Home page should restore the exact scroll position it had before navigation (i.e., 4000px).

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.12.0
  npm: 10.5.0
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 16.1.0-canary.2 // Latest available version is detected (16.1.0-canary.2).
  eslint-config-next: 15.0.0-rc.0
  react: 19.0.0-rc-f994737d14-20240522
  react-dom: 19.0.0-rc-f994737d14-20240522
  typescript: 5.4.5
Next.js Config:
  output: N/A

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

Linking and Navigating

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

next dev (local), next start (local)

Additional context

  • This appears to be closely related to (or possibly the same root cause as) issue https://github.com/vercel/next.js/issues/70716 .

  • This behavior seems inconsistent with the documentation, which states: "The default scrolling behavior of <Link> in Next.js is to maintain scroll position, similar to how browsers handle back and forwards navigation."

Questions/Suggestions: I believe this is a bug. If this is the intended behavior, then it would be helpful to mention such a scenario in the documentation as a caution.

extent analysis

TL;DR

The most likely fix for the scroll position restoration issue is to use the scroll property in the Link component or adjust the scroll restoration behavior in Next.js.

Guidance

  • Review the Next.js documentation to understand the default scrolling behavior and potential workarounds.
  • Consider using the scroll property in the Link component to control the scrolling behavior, such as scroll={false} to disable scrolling to the top of the page.
  • Investigate the relationship between this issue and the potentially related issue https://github.com/vercel/next.js/issues/70716 to determine if it's a known bug or intended behavior.
  • Verify the scroll restoration behavior in different scenarios, such as navigating between pages with different heights, to ensure the fix works as expected.

Notes

The provided environment information and package versions may be relevant to the issue, but without further investigation, it's unclear if they contribute to the problem. The issue may be specific to the next package version 16.1.0-canary.2 or the react and react-dom versions 19.0.0-rc-f994737d14-20240522.

Recommendation

Apply a workaround, such as using the scroll property in the Link component, as the issue may be related to the default scrolling behavior in Next.js, and adjusting this behavior may resolve the problem.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Scroll position restored to previous page’s height after browser back, when using cookie.set in server function within useEffect [1 comments, 2 participants]