Skip to content

fix(app-router): restore shallow pathname on history traversal - #2829

Open
GtechGovind wants to merge 6 commits into
cloudflare:mainfrom
GtechGovind:agent/preserve-shallow-history-pathname
Open

fix(app-router): restore shallow pathname on history traversal#2829
GtechGovind wants to merge 6 commits into
cloudflare:mainfrom
GtechGovind:agent/preserve-shallow-history-pathname

Conversation

@GtechGovind

@GtechGovind GtechGovind commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • persist the destination URL on external history.pushState and history.replaceState entries
  • treat marked history traversal entries as shallow URL restores so App Router keeps the current rendered tree
  • restore entry-specific snapshots before the same-route popstate shortcut
  • synchronize usePathname and useSearchParams when popstate takes the same-route fast path
  • prune unreachable durable snapshots when a new branch starts from a metadata-less entry
  • add Next.js-compatible browser back/forward and multi-entry traversal regression coverage

Root cause

External History API calls updated Vinext's navigation-hook URL cache, but the App Router popstate fast path only restored history metadata and scroll position. It did not resynchronize the hooks or first restore an entry-specific tree when traversing to the same pathname and search. The pushed entry also lacked a marker that would let forward traversal reuse the current tree instead of attempting an RSC navigation.

Durable shallow snapshots were pruned by numeric traversal index when branching, but a traversal to an older metadata-less entry made that cutoff unknown. A later push discarded the browser's forward branch without releasing its durable React trees.

The new internal shallow URL metadata identifies those entries, snapshot restoration now runs before the same-route shortcut, and pushes from metadata-less entries clear the app-owned snapshot branch.

Fixes #1541.

Validation

  • ./node_modules/.bin/vp check
  • ./node_modules/.bin/vp test run tests/app-browser-history-controller.test.ts (22 passed)
  • ./node_modules/.bin/vp test run tests/shims.test.ts -t 'preserves App Router history metadata when external history calls provide caller state'
  • PLAYWRIGHT_PROJECT=app-router ./node_modules/.bin/playwright test tests/e2e/app-router/advanced.spec.ts -g 'Shallow Routing' (7 passed, 1 existing fixme skipped)

@GtechGovind
GtechGovind marked this pull request as ready for review August 6, 2026 17:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee5604e238

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/vinext/src/server/app-browser-entry.ts Outdated
@GtechGovind
GtechGovind marked this pull request as draft August 8, 2026 05:57
@GtechGovind
GtechGovind marked this pull request as ready for review August 8, 2026 06:42
@GtechGovind

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 126007f9e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/vinext/src/server/app-browser-history-controller.ts Outdated
Comment thread packages/vinext/src/shims/navigation.ts Outdated
@GtechGovind
GtechGovind marked this pull request as draft August 8, 2026 11:34
@GtechGovind
GtechGovind marked this pull request as ready for review August 8, 2026 12:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e4bdabd84

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/vinext/src/server/app-history-state.ts
Comment thread packages/vinext/src/server/app-browser-entry.ts
Comment thread packages/vinext/src/server/app-history-state.ts
@GtechGovind
GtechGovind marked this pull request as draft August 9, 2026 06:13
@GtechGovind
GtechGovind marked this pull request as ready for review August 9, 2026 06:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f54ae1f078

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/vinext/src/server/app-browser-entry.ts Outdated
Comment thread packages/vinext/src/server/app-history-state.ts Outdated

Copy link
Copy Markdown
Author

/bigbonk

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App Router: history.pushState with new pathname not reflected after back/forward

1 participant