Unverified Commit f3f3d8a5 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Node.js streams: Add forkpoint for createCombinedPayloadStream (#92511)

## What?

Building on top of the changes in #92252. This PR implements similar
fork points for createCombinedPayloadStream
parent ce3b173e
...@@ -6048,13 +6048,20 @@ async function validateInstantConfigs( ...@@ -6048,13 +6048,20 @@ async function validateInstantConfigs(
const clientReferenceManifest = getClientReferenceManifest() const clientReferenceManifest = getClientReferenceManifest()
const renderFlightStream = process.env.__NEXT_USE_NODE_STREAMS
? renderToNodeFlightStream
: renderToWebFlightStream
const createDebugChannel = process.env.__NEXT_USE_NODE_STREAMS
? createNodeDebugChannel
: createWebDebugChannel
const { const {
cache, cache,
payload: initialRscPayload, payload: initialRscPayload,
stageEndTimes, stageEndTimes,
} = await collectStagedSegmentData( } = await collectStagedSegmentData(
ctx.componentMod, ctx.componentMod,
renderToWebFlightStream, renderFlightStream,
{ {
[RenderStage.Static]: accumulatedChunks.staticChunks, [RenderStage.Static]: accumulatedChunks.staticChunks,
[RenderStage.Runtime]: accumulatedChunks.runtimeChunks, [RenderStage.Runtime]: accumulatedChunks.runtimeChunks,
...@@ -6063,7 +6070,8 @@ async function validateInstantConfigs( ...@@ -6063,7 +6070,8 @@ async function validateInstantConfigs(
debugChunks, debugChunks,
startTime, startTime,
hasRuntimePrefetch, hasRuntimePrefetch,
clientReferenceManifest clientReferenceManifest,
createDebugChannel
) )
const { implicitTags, nonce, workStore } = ctx const { implicitTags, nonce, workStore } = ctx
...@@ -6131,13 +6139,14 @@ async function validateInstantConfigs( ...@@ -6131,13 +6139,14 @@ async function validateInstantConfigs(
const { stream: serverStream, debugStream } = const { stream: serverStream, debugStream } =
await createCombinedPayloadStream( await createCombinedPayloadStream(
ctx.componentMod, ctx.componentMod,
renderToWebFlightStream, renderFlightStream,
payloadResult.payload, payloadResult.payload,
extraChunksController, extraChunksController,
reactController.signal, reactController.signal,
clientReferenceManifest, clientReferenceManifest,
startTime, startTime,
isDebugChannelEnabled isDebugChannelEnabled,
createDebugChannel
) )
const instantValidationState = createInstantValidationState( const instantValidationState = createInstantValidationState(
......
...@@ -41,7 +41,7 @@ import { ...@@ -41,7 +41,7 @@ import {
createNodeStreamWithLateRelease, createNodeStreamWithLateRelease,
createNodeStreamFromChunks, createNodeStreamFromChunks,
} from './stream-utils' } from './stream-utils'
import { createWebDebugChannel } from '../debug-channel-server' import type { DebugChannelPair } from '../debug-channel-server'
import type { FlightComponentMod } from '../stream-ops' import type { FlightComponentMod } from '../stream-ops'
// eslint-disable-next-line import/no-extraneous-dependencies // eslint-disable-next-line import/no-extraneous-dependencies
...@@ -217,7 +217,8 @@ export async function collectStagedSegmentData( ...@@ -217,7 +217,8 @@ export async function collectStagedSegmentData(
fullPageDebugChunks: Uint8Array[] | null, fullPageDebugChunks: Uint8Array[] | null,
startTime: number, startTime: number,
hasRuntimePrefetch: boolean, hasRuntimePrefetch: boolean,
clientReferenceManifest: ClientReferenceManifest clientReferenceManifest: ClientReferenceManifest,
createDebugChannel: () => DebugChannelPair | undefined
) { ) {
const debugChannelAbortController = new AbortController() const debugChannelAbortController = new AbortController()
const debugStream = fullPageDebugChunks const debugStream = fullPageDebugChunks
...@@ -297,7 +298,7 @@ export async function collectStagedSegmentData( ...@@ -297,7 +298,7 @@ export async function collectStagedSegmentData(
cacheEntry: SegmentCacheItem cacheEntry: SegmentCacheItem
): Promise<void> => { ): Promise<void> => {
const segmentDebugChannel = cacheEntry.debugChunks const segmentDebugChannel = cacheEntry.debugChunks
? createWebDebugChannel() ? createDebugChannel()
: undefined : undefined
const itemStream = renderFlightStream( const itemStream = renderFlightStream(
...@@ -527,7 +528,8 @@ export async function createCombinedPayloadStream( ...@@ -527,7 +528,8 @@ export async function createCombinedPayloadStream(
renderSignal: AbortSignal, renderSignal: AbortSignal,
clientReferenceManifest: ClientReferenceManifest, clientReferenceManifest: ClientReferenceManifest,
startTime: number, startTime: number,
isDebugChannelEnabled: boolean isDebugChannelEnabled: boolean,
createDebugChannel: () => DebugChannelPair | undefined
) { ) {
// Collect all the chunks so that we're not dependent on timing of the render. // Collect all the chunks so that we're not dependent on timing of the render.
...@@ -536,7 +538,7 @@ export async function createCombinedPayloadStream( ...@@ -536,7 +538,7 @@ export async function createCombinedPayloadStream(
const allChunks: Uint8Array[] = [] const allChunks: Uint8Array[] = []
const debugChunks: Uint8Array[] | null = isDebugChannelEnabled ? [] : null const debugChunks: Uint8Array[] | null = isDebugChannelEnabled ? [] : null
const debugChannel = isDebugChannelEnabled ? createWebDebugChannel() : null const debugChannel = isDebugChannelEnabled ? createDebugChannel() : null
let streamFinished: Promise<any> let streamFinished: Promise<any>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment