Skip to content

fix(nuxt): avoid syncing route too early when reused page remounts - #35440

Merged
danielroe merged 2 commits into
nuxt:mainfrom
raminjafary:fix/route-sync-reused-page
Jun 25, 2026
Merged

danielroe merged 2 commits into
nuxt:mainfrom
raminjafary:fix/route-sync-reused-page

Conversation

@raminjafary

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #33107

📚 Description

When a leaf component is reused across a navigation, the router plugin syncs the internal _route immediately so useRoute updates even though no <Suspense> boundary resolves (added in #34918 for navigating up the route tree).

That is only correct when the page key is unchanged. For catch-all and param routes (e.g. /items/1 → /items/2) the key changes, <NuxtPage> remounts the page, and Suspense.onResolve syncs the route once the new page has resolved — so the eager sync updates useRoute() before the page content has changed.

This gates the eager sync on the generated route key being unchanged; when it changes, the (delayed, correct) Suspense.onResolve sync is left to do the work.

Added two runtime tests: one asserting the route read outside <NuxtPage> does not update before a param navigation to the same component resolves, and one asserting a query-only navigation (same key, no remount) still syncs immediately (guards #34918).

When a leaf component is reused across a navigation, the router plugin
syncs the internal route immediately so that `useRoute` updates even
though no Suspense boundary resolves. This is only correct when the page
key is unchanged. For catch-all and param routes the key changes, the
page remounts, and Suspense resolves after the new page is ready, so the
immediate sync updates the route before the page content has changed.

Only sync eagerly when the generated route key is unchanged; otherwise
let `<NuxtPage>`'s `Suspense.onResolve` sync the route once the new page
has resolved.

Resolves nuxt#33107
@raminjafary
raminjafary requested a review from danielroe as a code owner June 25, 2026 09:45
@github-actions github-actions Bot added 5.x 🐛 bug Something isn't working as expected labels Jun 25, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@35440

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@35440

nuxt

npm i https://pkg.pr.new/nuxt@35440

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@35440

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@35440

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@35440

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@35440

commit: 8c607fa

@coderabbitai

This comment has been minimized.

@codspeed

codspeed Bot commented Jun 25, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 11.19%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 20 untouched benchmarks
⏩ 3 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ loadNuxt in the basic test fixture (dev) 331.7 ms 373.5 ms -11.19%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing raminjafary:fix/route-sync-reused-page (8c607fa) with main (91cb2fe)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@danielroe
danielroe added this pull request to the merge queue Jun 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 25, 2026
@danielroe
danielroe added this pull request to the merge queue Jun 25, 2026
Merged via the queue into nuxt:main with commit 34e1579 Jun 25, 2026
28 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 25, 2026
2 of 5 tasks
danielroe pushed a commit that referenced this pull request Jun 25, 2026
…35440)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
@github-actions github-actions Bot mentioned this pull request Jun 25, 2026
danielroe pushed a commit that referenced this pull request Jul 15, 2026
…35440)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
@github-actions github-actions Bot mentioned this pull request Jul 15, 2026
danielroe pushed a commit that referenced this pull request Jul 17, 2026
…35440)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useRoute updates before expected with catch-all to catch-all navigation.

2 participants