nextjs - 💡(How to fix) Fix App Router: route groups can share prefetch cache key and affect back/forward restore [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#92334Fetched 2026-04-08 02:43:25
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

Root Cause

Link to the code that reproduces this issue

(Will add repro repo or test case in follow-up if needed.)

To Reproduce

  1. Use an App Router app with route groups (e.g. (marketing) and (shop)) that can resolve to the same pathname segments.
  2. Navigate between pages so prefetch entries are created.
  3. Trigger back/forward navigation where the router restores from cache.
  4. Observe that cache reuse can cross route-group boundaries.

Current vs. Expected behavior

  • Current: route cache/prefetch lookup can collide across entries that share the same URL-derived key but belong to different parallel route slots/route groups, leading to stale or incorrect restoration on browser back/forward.
  • Expected: cache entries should be isolated by parallel route slot so back/forward restores the correct tree per group/slot context.

Provide environment information

npx envinfo --system --binaries --browsers --npmPackages 'next,react,react-dom'

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

App Router

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

next dev (local) next build (local) next start (local)

Additional context

During investigation, parallelSlot was added to RouteCacheKey, but initially it did not affect cache behavior because keying still used vary-path generation that ignored this field in read paths. A robust fix appears to require routing parallelSlot through vary-path creation and all cache read/write sites so the effective cache key changes (not just the TS type). If useful, I can follow up with a focused regression test covering:

  • prefetch in one route group
  • back/forward restore in another group with same URL shape
  • assertion that the restored route tree matches the correct parallel slot context

Code Example

npx envinfo --system --binaries --browsers --npmPackages 'next,react,react-dom'
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

(Will add repro repo or test case in follow-up if needed.)

To Reproduce

  1. Use an App Router app with route groups (e.g. (marketing) and (shop)) that can resolve to the same pathname segments.
  2. Navigate between pages so prefetch entries are created.
  3. Trigger back/forward navigation where the router restores from cache.
  4. Observe that cache reuse can cross route-group boundaries.

Current vs. Expected behavior

  • Current: route cache/prefetch lookup can collide across entries that share the same URL-derived key but belong to different parallel route slots/route groups, leading to stale or incorrect restoration on browser back/forward.
  • Expected: cache entries should be isolated by parallel route slot so back/forward restores the correct tree per group/slot context.

Provide environment information

npx envinfo --system --binaries --browsers --npmPackages 'next,react,react-dom'

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

App Router

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

next dev (local) next build (local) next start (local)

Additional context

During investigation, parallelSlot was added to RouteCacheKey, but initially it did not affect cache behavior because keying still used vary-path generation that ignored this field in read paths. A robust fix appears to require routing parallelSlot through vary-path creation and all cache read/write sites so the effective cache key changes (not just the TS type). If useful, I can follow up with a focused regression test covering:

  • prefetch in one route group
  • back/forward restore in another group with same URL shape
  • assertion that the restored route tree matches the correct parallel slot context

extent analysis

TL;DR

Modify the cache key generation to include the parallelSlot field to prevent cache collisions across different route groups.

Guidance

  • Investigate how the vary-path generation can be updated to include the parallelSlot field, ensuring that cache keys are unique across different route groups.
  • Verify that the parallelSlot field is correctly propagated through all cache read/write operations to ensure effective cache key changes.
  • Consider adding a regression test to cover the scenario where prefetch occurs in one route group and back/forward restore occurs in another group with the same URL shape, to ensure the restored route tree matches the correct parallel slot context.
  • Review the RouteCacheKey implementation to ensure that the parallelSlot field is properly integrated and used in cache key generation.

Example

No specific code snippet can be provided without more context, but the fix likely involves updating the vary-path generation function to include the parallelSlot field, e.g., const cacheKey = generateVaryPath(route.path, parallelSlot);.

Notes

The provided information suggests that the issue is related to cache key generation and the lack of inclusion of the parallelSlot field. However, without more specific details about the implementation, it's difficult to provide a complete solution.

Recommendation

Apply a workaround by modifying the cache key generation to include the parallelSlot field, as this appears to be the root cause of the issue. This should prevent cache collisions across different route groups and ensure correct restoration of the route tree during back/forward navigation.

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