Skip to content

Commit

Permalink
feat: emit segment data without ppr (#74959)
Browse files Browse the repository at this point in the history
Emit the segment prefetch data even when PPR is not enabled.
  • Loading branch information
wyattjoh authored Jan 16, 2025
1 parent d7017fe commit 5d2fc23
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions packages/next/src/export/routes/app-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export async function exportAppPage(
throw new Error(`Invariant: failed to get page data for ${path}`)
}

let segmentPaths
if (flightData) {
// If PPR is enabled, we want to emit a prefetch rsc file for the page
// instead of the standard rsc. This is because the standard rsc will
Expand All @@ -195,27 +194,6 @@ export async function exportAppPage(
htmlFilepath.replace(/\.html$/, RSC_PREFETCH_SUFFIX),
flightData
)

if (segmentData) {
// Emit the per-segment prefetch data. We emit them as separate files
// so that the cache handler has the option to treat each as a
// separate entry.
segmentPaths = []
const segmentsDir = htmlFilepath.replace(
/\.html$/,
RSC_SEGMENTS_DIR_SUFFIX
)

for (const [segmentPath, buffer] of segmentData) {
segmentPaths.push(segmentPath)
const segmentDataFilePath =
segmentPath === '/'
? segmentsDir + '/_index' + RSC_SEGMENT_SUFFIX
: segmentsDir + segmentPath + RSC_SEGMENT_SUFFIX

fileWriter.append(segmentDataFilePath, buffer)
}
}
} else {
// Writing the RSC payload to a file if we don't have PPR enabled.
fileWriter.append(
Expand All @@ -225,6 +203,28 @@ export async function exportAppPage(
}
}

let segmentPaths
if (segmentData) {
// Emit the per-segment prefetch data. We emit them as separate files
// so that the cache handler has the option to treat each as a
// separate entry.
segmentPaths = []
const segmentsDir = htmlFilepath.replace(
/\.html$/,
RSC_SEGMENTS_DIR_SUFFIX
)

for (const [segmentPath, buffer] of segmentData) {
segmentPaths.push(segmentPath)
const segmentDataFilePath =
segmentPath === '/'
? segmentsDir + '/_index' + RSC_SEGMENT_SUFFIX
: segmentsDir + segmentPath + RSC_SEGMENT_SUFFIX

fileWriter.append(segmentDataFilePath, buffer)
}
}

const headers: OutgoingHttpHeaders = { ...metadata.headers }

// If we're writing the file to disk, we know it's a prerender.
Expand Down

0 comments on commit 5d2fc23

Please sign in to comment.