Skip to content

Conversation

@Flo0806
Copy link
Member

@Flo0806 Flo0806 commented Oct 13, 2025

🔗 Linked issue

fixes #33443

📚 Description

Fixes root route (/) payload not loading during client-side navigation.

📝 Description

When navigating back to the root route / using <NuxtLink>, the prerendered payload was not being loaded. This caused useAsyncData callbacks to re-execute instead of using the cached payload data.
Root cause: The isPrerendered() function was converting / to an empty string '' when normalizing URLs, causing the manifest lookup to fail.
Solution: Updated the regex pattern from /\/$/ to /(?<=.)\/$$/ to only strip trailing slashes when there's at least one character before it, preserving the root route.

📦 Changes

Updated three files to use the new regex pattern consistently:

packages/nuxt/src/app/composables/payload.ts - isPrerendered() function
packages/nuxt/src/core/runtime/nitro/renderer.ts - payload cache key
packages/nuxt/src/app/plugins/router/scrollBehavior.client.ts - route comparison

✅ Checklist

All existing tests pass
No new tests needed (existing tests cover the functionality)

🧪 How to test

Create a Nuxt app with prerendering enabled
Run pnpm play:generate && pnpm play:preview
Navigate from //page/
Verify that useAsyncData doesn't re-execute on navigation back to /

@Flo0806 Flo0806 requested a review from danielroe as a code owner October 13, 2025 16:56
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.


// Hash routes on the same page, no page hook is fired so resolve here
if (to.path.replace(/\/$/, '') === from.path.replace(/\/$/, '')) {
if (to.path.replace(/(?<=.)\/$/, '') === from.path.replace(/(?<=.)\/$/, '')) {
Copy link
Member

Choose a reason for hiding this comment

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

we probably don't need to update here as all we care about is equality

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes... right. Should I revert it back and commit again?

Copy link
Member

Choose a reason for hiding this comment

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

yes please 🙏

Copy link
Member Author

Choose a reason for hiding this comment

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

With pleasure, and thank you for allowing me to participate!

@Flo0806 Flo0806 changed the title fix(app): preserve root route in isPrerendered check (#33443) fix(nuxt): preserve root route in isPrerendered check Oct 13, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 13, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: a1488aa

@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Changes adjust handling of trailing slashes for root paths. In packages/nuxt/src/app/composables/payload.ts, isPrerendered now preserves "/" and only trims a trailing slash for non-root URLs, affecting manifest/prerender checks accordingly. In packages/nitro-server/src/runtime/handlers/renderer.ts, the cache key for the root route is updated from an empty string to "/" while keeping trailing-slash trimming for other URLs. No public API surface changes are introduced.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the main change of preserving the root route in the isPrerendered check, matching the code modifications and bug fix.
Linked Issues Check ✅ Passed The changes directly address the linked issue by updating the trailing-slash regex in the isPrerendered function, payload cache key, and scroll behaviour comparison to preserve the root path and ensure the prerendered payload for "/" is correctly detected and used during client-side navigation.
Out of Scope Changes Check ✅ Passed All modifications are confined to normalising trailing slashes in functions related to prerendered payload and route comparison, with no unrelated or extraneous changes introduced outside the scope of preserving the root route payload.
Description Check ✅ Passed The description clearly outlines the linked issue, root cause, solution, and impacted files, directly relating to the changes in normalising the root route in payload handling.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1488aa and 1b05990.

📒 Files selected for processing (1)
  • packages/nitro-server/src/runtime/handlers/renderer.ts (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 13, 2025

CodSpeed Performance Report

Merging #33476 will not alter performance

Comparing Flo0806:fix/isprerendered-root-route (1b05990) with main (f3dc078)

Summary

✅ 10 untouched

@danielroe
Copy link
Member

thank you again ❤️

@danielroe danielroe merged commit f836eca into nuxt:main Oct 13, 2025
6 checks passed
@github-actions github-actions bot mentioned this pull request Oct 13, 2025
@github-actions github-actions bot mentioned this pull request Oct 23, 2025
@github-actions github-actions bot mentioned this pull request Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prerendered payload not loaded when navigating to root path

2 participants