perf(nitro,schema): inline payload in HTML for cached routes + add payloadExtraction: 'client'#34410
perf(nitro,schema): inline payload in HTML for cached routes + add payloadExtraction: 'client'#34410
payloadExtraction: 'client'#34410Conversation
|
|
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/schema/src/types/schema.ts`:
- Around line 1134-1136: Update the JSDoc for the payloadExtraction property to
reflect both defaults: keep the historical "@default true" and add that when
future.compatibilityVersion >= 5 the resolver default becomes "'client'";
reference the payloadExtraction field and mention the condition using
future.compatibilityVersion so readers know migration behaviour explicitly
(e.g., "@default true — becomes 'client' when future.compatibilityVersion >=
5").
ℹ️ Review info
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
packages/nitro-server/src/index.tspackages/nitro-server/src/runtime/handlers/renderer.tspackages/nitro-server/src/runtime/utils/cache.tspackages/nitro-server/src/runtime/utils/renderer/payload.tspackages/schema/src/config/experimental.tspackages/schema/src/types/schema.ts
Merging this PR will not alter performance
Comparing Footnotes
|
…ayloadExtraction: 'client'`
Update default value documentation for payloadExtraction.
f07bb93 to
cf1a770
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/nitro-server/src/runtime/handlers/renderer.ts (1)
97-100:⚠️ Potential issue | 🟠 Major
payloadExtraction: falseallows payload extraction on cached runtime routes.The extraction condition at lines 97–100 handles prerender and runtime cached routes separately. The prerender branch correctly checks
NUXT_PAYLOAD_EXTRACTION, but the runtime branch (line 99) only checksNUXT_RUNTIME_PAYLOAD_EXTRACTIONwithout verifying the globalNUXT_PAYLOAD_EXTRACTIONflag. This permits payload extraction to trigger when the user setspayloadExtraction: false, contradicting the documented behaviour that extraction should be "disabled entirely" in that case.When triggered,
_PAYLOAD_EXTRACTIONcauses downstream side-effects: adding prerender headers (line 179), gating payload preloads (line 224), and affecting script placement (line 299).Fix
const _PAYLOAD_EXTRACTION = !ssrContext.noSSR && ( (import.meta.prerender && NUXT_PAYLOAD_EXTRACTION) - || (NUXT_RUNTIME_PAYLOAD_EXTRACTION && (routeOptions.isr || routeOptions.cache)) + || (NUXT_PAYLOAD_EXTRACTION && NUXT_RUNTIME_PAYLOAD_EXTRACTION && (routeOptions.isr || routeOptions.cache)) )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/nitro-server/src/runtime/handlers/renderer.ts` around lines 97 - 100, The conditional that sets _PAYLOAD_EXTRACTION allows runtime cached routes to extract payloads even when the global NUXT_PAYLOAD_EXTRACTION is false; update the expression initializing _PAYLOAD_EXTRACTION to require the global NUXT_PAYLOAD_EXTRACTION for both branches so payload extraction only runs when NUXT_PAYLOAD_EXTRACTION is true and either (import.meta.prerender && NUXT_PAYLOAD_EXTRACTION) or (NUXT_RUNTIME_PAYLOAD_EXTRACTION && NUXT_PAYLOAD_EXTRACTION && (routeOptions.isr || routeOptions.cache)); modify the initialization where _PAYLOAD_EXTRACTION is defined to include this additional check so downstream logic that reads _PAYLOAD_EXTRACTION (headers, payload preloads, script placement) respects the global payloadExtraction flag.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/nitro-server/src/runtime/handlers/renderer.ts`:
- Around line 97-100: The conditional that sets _PAYLOAD_EXTRACTION allows
runtime cached routes to extract payloads even when the global
NUXT_PAYLOAD_EXTRACTION is false; update the expression initializing
_PAYLOAD_EXTRACTION to require the global NUXT_PAYLOAD_EXTRACTION for both
branches so payload extraction only runs when NUXT_PAYLOAD_EXTRACTION is true
and either (import.meta.prerender && NUXT_PAYLOAD_EXTRACTION) or
(NUXT_RUNTIME_PAYLOAD_EXTRACTION && NUXT_PAYLOAD_EXTRACTION && (routeOptions.isr
|| routeOptions.cache)); modify the initialization where _PAYLOAD_EXTRACTION is
defined to include this additional check so downstream logic that reads
_PAYLOAD_EXTRACTION (headers, payload preloads, script placement) respects the
global payloadExtraction flag.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0b670d24-ad80-4075-a7ba-83891c1962f3
📒 Files selected for processing (7)
docs/3.guide/6.going-further/1.experimental-features.mdpackages/nitro-server/src/index.tspackages/nitro-server/src/runtime/handlers/renderer.tspackages/nitro-server/src/runtime/utils/cache.tspackages/nitro-server/src/runtime/utils/renderer/payload.tspackages/schema/src/config/experimental.tspackages/schema/src/types/schema.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/nitro-server/src/runtime/utils/renderer/payload.ts
- packages/schema/src/config/experimental.ts
- packages/nitro-server/src/index.ts
…ayloadExtraction: 'client'` (#34410) Co-authored-by: Sébastien Chopin <seb@nuxt.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
🔗 Linked issue
📚 Description
when a cached route (ISR/SWR) is rendered at runtime with payload extraction enabled, the HTML references an external
_payload.json.the browser immediately fetches this as a second request, which triggers a full SSR re-render of the same page just to extract the data portion. in a serverless environment, this can spin up a second lambda before the first response has even finished streaming...
this PR addresses this in two ways:
payloadExtraction: 'client'mode that inlines the full payload in the initial HTML response while still generating_payload.jsonfor client-side navigation (bypassing the issue entirely)_payload.jsonrequests (from client-side navigation) can be served without a full re-render when the HTML was already rendered in the same processThe new
payloadExtraction: 'client'is only default withcompatibilityVersion: 5, to avoid a breaking change, but the runtime cache should still solve the issue for these users.context
surveying the issues, spotted some requests for extraction even on the initial render
hence allowing 'true' to force extraction on server side as well. we might revisit as I think there's plenty of space for optimisation here