nextjs - ✅(Solved) Fix router.replace/push restores stale query parameters from router cache in static exports (16.2.0+ regression) [1 pull requests, 2 comments, 3 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#92187Fetched 2026-04-08 02:01:51
View on GitHub
Comments
2
Participants
3
Timeline
13
Reactions
2
Author
Timeline (top)
subscribed ×6commented ×2mentioned ×2cross-referenced ×1

Root Cause

Possibly related to #92152 (stale searchParams caching), which may share the same root cause in the router cache.

Fix Action

Fixed

PR fix notes

PR #92193: fix: align prefetched navigation URL with target search params

Description (problem / solution / changelog)

What?

Fix stale query params being restored on router.push/router.replace in static export navigation.

Why?

Cached prefetched entries reused old search state for the same pathname (regression in 16.2.0+).

How?

On same-path, different-search navigation, use target URL search as source of truth. Update route/metadata search state before applying cached navigation.

Fixes #92187

Changed files

  • packages/next/src/client/components/segment-cache/cache.ts (modified, +4/-4)
  • packages/next/src/client/components/segment-cache/navigation.ts (modified, +21/-4)

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:54:55 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16
Binaries:
  Node: 22.9.0
  npm: 10.8.3
  Yarn: 1.22.22
  pnpm: 9.15.4
Relevant Packages:
  next: 16.2.2 // Latest available version is detected (16.2.2).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 6.0.2
Next.js Config:
  output: export
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/azu/next-16.2.1-router-replace-params-bug

To Reproduce

  1. pnpm install && pnpm run build && pnpm run start
  2. Open http://localhost:3099/page-a?foo=bar&test=true directly in browser (full page load)
  3. Click "router.push('/page-b')" button — navigates to /page-b
  4. Click "router.replace('/page-a')" button
  5. Observe: URL becomes /page-a?foo=bar&test=true instead of /page-a

Summary

Scenario16.1.616.2.1
Visit /page-a?q=1router.push("/page-b")router.replace("/page-a")params clearedparams restored from cache

Current vs. Expected behavior

When calling router.replace("/page-a") with a path that has no query string, the URL should navigate to that exact path without any query parameters.

Instead, Next.js 16.2.2 restores query parameters from a previously cached navigation entry for that pathname. This affects window.location.href, useSearchParams(), and the browser address bar.

Works correctly on Next.js 16.1.6. Regression in 16.2.0+.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:54:55 PST 2026; root:xnu-12377.91.3~2/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16
Binaries:
  Node: 22.9.0
  npm: 10.8.3
  Yarn: 1.22.22
  pnpm: 9.15.4
Relevant Packages:
  next: 16.2.2 // Latest available version is detected (16.2.2).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 6.0.2
Next.js Config:
  output: export

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

Runtime

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

next start (local)

Additional context

  • Works correctly on Next.js 16.1.6, broken on 16.2.0, 16.2.1, 16.2.2
  • next dev works correctly — only the built static export is affected
  • Both router.replace and router.push are affected
  • Navigating to a different pathname clears params correctly; the bug only triggers when navigating to a pathname that was previously visited with query parameters
  • Automated test included in the repo: pnpm test (requires Playwright)

Possibly related to #92152 (stale searchParams caching), which may share the same root cause in the router cache.

extent analysis

TL;DR

Downgrade to Next.js 16.1.6 to avoid the query parameter restoration issue when using router.replace or router.push.

Guidance

  • Verify the issue by running the provided test case and observing the URL parameters after navigating between pages.
  • Check if the issue persists when using router.push instead of router.replace.
  • Consider using a temporary workaround, such as manually clearing the query parameters when navigating to a new page.
  • Review the related issue #92152 to see if it provides any additional insight into the root cause of the problem.

Example

No code snippet is provided as the issue is related to a specific version of Next.js and the provided repository already includes a test case.

Notes

The issue seems to be specific to Next.js versions 16.2.0 and later, and only affects the built static export, not next dev. The root cause is likely related to the router cache and stale searchParams caching.

Recommendation

Apply workaround: Downgrade to Next.js 16.1.6, as it is the last known version that does not exhibit this issue. This is a temporary solution until the root cause is addressed in a future version of Next.js.

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