Skip to content

Conversation

@onmax
Copy link
Contributor

@onmax onmax commented Oct 12, 2025

🔗 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.json files). Pages using ISR or SWR route rules could not generate payloads, which meant that:

  • Navigation to these pages could not use cached payloads.
  • API calls had to be re-made with every client-side navigation
  • CDNs could not cache the payload files alongside the HTML.

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.

@onmax onmax requested a review from danielroe as a code owner October 12, 2025 16:46
@bolt-new-by-stackblitz
Copy link

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

@coderabbitai
Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

Payload 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)
Check name Status Explanation
Title Check ✅ Passed The title “feat(nuxt): enable payload extraction for ISR/SWR routes” concisely and accurately summarises the primary change by highlighting the new feature and its scope within the Nuxt framework.
Linked Issues Check ✅ Passed The changes implement the requested feature by extending the renderer to extract payloads for ISR and SWR route rules, updating type declarations to support isr and swr options, and adding comprehensive tests that validate payload JSON generation for these routes in accordance with issue #32635.
Out of Scope Changes Check ✅ Passed All modifications, including renderer logic changes, type augmentations, test fixtures, and snapshot updates, directly support enabling payload extraction for ISR/SWR and align with the linked issue objectives without introducing unrelated functionality.
Description Check ✅ Passed The pull request description clearly explains the linked issue, outlines the change to enable payload extraction for ISR and SWR routes, and notes the added test coverage, making it directly relevant to the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 07cca77 and 8752732.

📒 Files selected for processing (3)
  • packages/nuxt/src/app/types/augments.ts (2 hunks)
  • packages/nuxt/src/core/runtime/nitro.d.ts (1 hunks)
  • packages/nuxt/src/core/templates.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/nuxt/src/app/types/augments.ts
  • packages/nuxt/src/core/templates.ts
  • packages/nuxt/src/core/runtime/nitro.d.ts
⏰ 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)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (5)
packages/nuxt/src/core/templates.ts (2)

420-428: LGTM! ISR and SWR type augmentations added consistently.

The additions follow the existing pattern for NitroRouteRules augmentation within the generated template. The types are correctly defined as optional with number | boolean to support both boolean flags and TTL values in seconds.


447-455: LGTM! Augmentations correctly mirrored for nitropack/types module.

The type augmentations are appropriately duplicated for the nitropack/types module to ensure consistency across both import paths.

packages/nuxt/src/app/types/augments.ts (2)

4-17: LGTM! ISR and SWR route rules correctly added to nitropack module.

The augmentation follows the established pattern for NitroRouteRules, with the new fields properly typed as optional number | boolean to support both boolean enablement and numeric TTL values.


19-33: LGTM! Augmentations correctly mirrored for nitropack/types module.

The type augmentations are appropriately duplicated for the nitropack/types module, ensuring type consistency across different import paths.

packages/nuxt/src/core/runtime/nitro.d.ts (1)

1-16: Incorrect duplication claim; only nitro.d.ts defines isr/swr
The isr and swr fields appear solely in packages/nuxt/src/core/runtime/nitro.d.ts (in module 'nitropack' and 'nitropack/types'). No definitions exist in templates.ts or augments.ts. Confirm if both module declarations are needed; otherwise adjust only within nitro.d.ts.

Likely an incorrect or invalid review comment.


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.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between cf102e8 and d907fa9.

📒 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.ts
  • test/fixtures/basic/nuxt.config.ts
  • packages/nuxt/src/core/runtime/nitro/handlers/renderer.ts
  • test/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.ts
  • test/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.vue
  • test/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-prerender header only when import.meta.prerender is 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 useFetch with 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:

  1. Trigger route caching by fetching the page first
  2. Fetch the corresponding _payload.json file
  3. Parse and validate the payload structure
  4. Verify the expected data keys (isr-data and swr-data) exist as arrays

This 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 useFetch with 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
Copy link
Contributor Author

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!

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 12, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 8752732

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 12, 2025

CodSpeed Performance Report

Merging #33467 will not alter performance

Comparing onmax:feat/payload-extraction-isr-swr (8752732) with main (cf102e8)

Summary

✅ 10 untouched

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.

Payload extraction should be possible to enable for non-prerendered pages

1 participant