Skip to content

fix(nuxt): restore deferred query route before page is mounted - #35442

Merged
danielroe merged 5 commits into
nuxt:mainfrom
raminjafary:fix/prerender-query-restore-before-mount
Jun 25, 2026
Merged

danielroe merged 5 commits into
nuxt:mainfrom
raminjafary:fix/prerender-query-restore-before-mount

Conversation

@raminjafary

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #34651

📚 Description

On a prerendered (SSG) page whose URL carries a query (e.g. /products?active=true), Nuxt hydrates against the query-less prerendered markup and restores the real route afterwards. That restore ran in the app:suspense:resolve hook, which fires after the page's onMounted, so useRoute().query was still empty during onMounted (and <script setup>). This broke common patterns such as reading the query on mount.

<NuxtPage>'s Suspense onResolve runs synchronously when the page resolves — before the buffered mounted hooks flush. We restore the real route there instead: router.currentRoute is set synchronously (then history/URL are reconciled via router.replace) so the query is present in onMounted, while the hydration render itself stays query-less (no hydration mismatch). When no <NuxtPage> is rendered, it falls back to app:suspense:resolve as before.

When hydrating a prerendered page whose URL carries a query, the route is
kept query-less for the hydration render (to match the prerendered markup).
The real route was only restored in `app:suspense:resolve`, which runs after
the page's `onMounted`, so `useRoute().query` was empty in `onMounted` and
script setup on prerendered pages.

Restore the route as `<NuxtPage>`'s `Suspense` resolves — synchronously,
before mounted hooks flush — so the query is present in `onMounted`, while
the hydration render itself stays query-less and no hydration mismatch is
reintroduced. Falls back to `app:suspense:resolve` when no page is rendered.

Resolves nuxt#34651
@raminjafary
raminjafary requested a review from danielroe as a code owner June 25, 2026 12:32
@github-actions github-actions Bot added 5.x 🐛 bug Something isn't working as expected labels Jun 25, 2026
@coderabbitai

This comment has been minimized.

@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@35442

@nuxt/nitro-server

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: a5b7532

@codspeed

codspeed Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 10.59%

⚠️ 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) 325.8 ms 364.3 ms -10.59%

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/prerender-query-restore-before-mount (a5b7532) with main (4909725)

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 merged commit e077573 into nuxt:main Jun 25, 2026
28 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 25, 2026
2 of 5 tasks
@github-actions github-actions Bot mentioned this pull request Jun 25, 2026
@github-actions github-actions Bot mentioned this pull request Jul 15, 2026
@github-actions github-actions Bot mentioned this pull request Jul 18, 2026
Ibochkarev pushed a commit to translation-gang/nuxt that referenced this pull request Jul 24, 2026
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.

In nuxt 4.4.2 SSG, on page load query parameters are dissapearing and appearing again

2 participants