-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(nuxt): preserve root route in isPrerendered check
#33476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
|
|
||
| // 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(/(?<=.)\/$/, '')) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please 🙏
There was a problem hiding this comment.
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!
isPrerendered check (#33443)isPrerendered check
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
|
Caution Review failedThe pull request is closed. WalkthroughChanges 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)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
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. Comment |
CodSpeed Performance ReportMerging #33476 will not alter performanceComparing Summary
|
…'t need normalization
|
thank you again ❤️ |
🔗 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 causeduseAsyncDatacallbacks 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()functionpackages/nuxt/src/core/runtime/nitro/renderer.ts- payload cache keypackages/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:previewNavigate from
/→/page→/Verify that
useAsyncDatadoesn't re-execute on navigation back to/