-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat(nuxt): enable payload extraction for ISR/SWR routes #33467
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
base: main
Are you sure you want to change the base?
Conversation
|
|
WalkthroughPayload extraction in packages/nuxt/src/core/runtime/nitro/handlers/renderer.ts now triggers when prerendering or when routeOptions.isr or routeOptions.swr are defined, provided payload extraction is enabled and SSR is not disabled. The x-nitro-prerender header is only emitted when running in explicit prerender mode (import.meta.prerender). Tests add ISR and SWR payload checks in test/basic.test.ts, add isr.vue and swr.vue pages under test/fixtures/basic/app/pages, extend test/fixtures/basic/nuxt.config.ts with route rules for /isr and /swr, add NitroRouteRules typings for isr/swr in multiple declaration files, and update three server bundle size snapshots in test/bundle.test.ts (each increased by ~1k). Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (5)
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 |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
packages/nuxt/src/core/runtime/nitro/handlers/renderer.ts(2 hunks)test/basic.test.ts(1 hunks)test/bundle.test.ts(1 hunks)test/fixtures/basic/app/pages/isr.vue(1 hunks)test/fixtures/basic/app/pages/swr.vue(1 hunks)test/fixtures/basic/nuxt.config.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
test/basic.test.tstest/fixtures/basic/nuxt.config.tspackages/nuxt/src/core/runtime/nitro/handlers/renderer.tstest/bundle.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Write unit tests for core functionality using
vitest
Files:
test/basic.test.tstest/bundle.test.ts
**/*.vue
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use
<script setup lang="ts">and the composition API when creating Vue components
Files:
test/fixtures/basic/app/pages/swr.vuetest/fixtures/basic/app/pages/isr.vue
🧬 Code graph analysis (1)
test/basic.test.ts (2)
packages/nuxt/src/app/composables/payload.ts (1)
parsePayload(143-145)test/utils.ts (1)
parsePayload(93-95)
🪛 GitHub Check: build
packages/nuxt/src/core/runtime/nitro/handlers/renderer.ts
[failure] 127-127:
Property 'swr' does not exist on type 'NitroRouteRules'.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: code
🔇 Additional comments (6)
test/bundle.test.ts (1)
120-120: LGTM!The 1k reduction in server bundle size is consistent with the payload extraction optimisations introduced by this PR.
packages/nuxt/src/core/runtime/nitro/handlers/renderer.ts (1)
181-184: Correctly narrows prerender header emission to explicit prerender mode.The conditional emission of the
x-nitro-prerenderheader only whenimport.meta.prerenderis true properly distinguishes between prerendering and ISR/SWR caching scenarios. This ensures the header is only set when Nitro should actually prerender the payload file.test/fixtures/basic/app/pages/swr.vue (1)
1-10: LGTM!The SWR test page correctly uses
useFetchwith a unique key (swr-data) to enable payload extraction testing for SWR routes.test/basic.test.ts (1)
2628-2648: Comprehensive ISR/SWR payload rendering tests.The tests correctly:
- Trigger route caching by fetching the page first
- Fetch the corresponding
_payload.jsonfile- Parse and validate the payload structure
- Verify the expected data keys (
isr-dataandswr-data) exist as arraysThis pattern ensures that payload extraction works correctly for both ISR and SWR route rules.
test/fixtures/basic/app/pages/isr.vue (1)
1-10: LGTM!The ISR test page correctly uses
useFetchwith a unique key (isr-data) to enable payload extraction testing for ISR routes.test/fixtures/basic/nuxt.config.ts (1)
191-192: Route rules correctly configured for ISR/SWR testing.The route rules enable ISR and SWR behaviour with 60-second cache durations, which is appropriate for test scenarios and aligns with the new test pages and payload extraction tests.
| @@ -0,0 +1,16 @@ | |||
| // Type augmentations for nitropack types used in runtime | |||
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.
Not sure how to avoid this...
Related comment: https://github.com/nuxt/nuxt/pull/33467/files#r2424570521
Any feedback on how to improve it is more than welcome!
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #33467 will not alter performanceComparing Summary
|
🔗 Linked issue:
Resolves: #32635
📚 Description:
This enables payload extraction for routes using the ISR and SWR caching strategies.
Previously, payload extraction only worked for pages that were prerendered at build time (
_payload.jsonfiles). Pages using ISR or SWR route rules could not generate payloads, which meant that:This PR modifies the renderer logic to enable payload extraction when routes have 'isr' or 'swr' route rules defined. This allows Nuxt apps to benefit from cached payloads on CDN platforms such as Vercel and Netlify.
✅ Test coverage:
Comprehensive tests for ISR and SWR payload extraction have been added to the basic fixture test suite.
The related PR (#33158) is too broad, as it could enable payload extraction for regular SSR routes that don't benefit from it. This could potentially create unnecessary files and cache entries.