Skip to content

fix(build): support _inlined segment paths in prefetchInlining for dynamic routes#90850

Closed
bensalmon-daylight wants to merge 2 commits intovercel:canaryfrom
bensalmon-daylight:fix/build-prefetch-inlining-segment-paths
Closed

fix(build): support _inlined segment paths in prefetchInlining for dynamic routes#90850
bensalmon-daylight wants to merge 2 commits intovercel:canaryfrom
bensalmon-daylight:fix/build-prefetch-inlining-segment-paths

Conversation

@bensalmon-daylight
Copy link
Contributor

@bensalmon-daylight bensalmon-daylight commented Mar 4, 2026

What

Handle _inlined segment paths during the build when prefetchInlining is enabled alongside dynamic routes.

Why

When prefetchInlining is enabled, segment data is bundled into /_inlined instead of per-segment /__PAGE__ entries. The build previously only looked for __PAGE__ in segmentPaths, throwing Invariant: missing __PAGE__ segmentPath for any dynamic route using prefetchInlining.

How

  • Check for /_inlined as a fallback when /__PAGE__ is not found in segmentPaths
  • Build routing rules that match /_inlined, /_tree, /_full, and bare .segment.rsc URLs
  • Only throw the invariant error when neither __PAGE__ nor _inlined is present

Test Plan

  • Added production test (test/production/app-dir/prefetch-inlining-dynamic-routes/) with a dynamic [slug] route and prefetchInlining: true
  • Verified the test fails with the old code (Invariant: missing __PAGE__ segmentPath)
  • Verified the test passes with the fix

Relevant PR

#90555

@nextjs-bot
Copy link
Collaborator

Allow CI Workflow Run

  • approve CI run for commit: 4804a54

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

acdlite added a commit that referenced this pull request Mar 5, 2026
When prefetchInlining is enabled, the segment data collection returns a
special key for the inlined response. Previously this key was
`/_inlined`, but the build validation code in
`packages/next/src/build/index.ts` expects segment paths to contain
`__PAGE__`. This caused builds to fail with "Invariant: missing __PAGE__
segmentPath" for any dynamic route using prefetchInlining.

Fix by using the same `PAGE_SEGMENT_KEY` (`__PAGE__`) constant for the
inlined segment response key, matching what the build code already
expects. This is consistent since the inlined response serves the same
role as the per-page segment data — it just bundles all segments
together.

Closes #90850

Co-authored-by: Ben Salmon <ben.salmon@daylightgroup.nz>

Co-authored-by: Ben Salmon <ben.salmon@daylightgroup.nz>
sokra pushed a commit that referenced this pull request Mar 6, 2026
When prefetchInlining is enabled, the segment data collection returns a
special key for the inlined response. Previously this key was
`/_inlined`, but the build validation code in
`packages/next/src/build/index.ts` expects segment paths to contain
`__PAGE__`. This caused builds to fail with "Invariant: missing __PAGE__
segmentPath" for any dynamic route using prefetchInlining.

Fix by using the same `PAGE_SEGMENT_KEY` (`__PAGE__`) constant for the
inlined segment response key, matching what the build code already
expects. This is consistent since the inlined response serves the same
role as the per-page segment data — it just bundles all segments
together.

Closes #90850

Co-authored-by: Ben Salmon <ben.salmon@daylightgroup.nz>

Co-authored-by: Ben Salmon <ben.salmon@daylightgroup.nz>
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.

2 participants