Unverified Commit 5fa0987a authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Remove React 17 logic from Pages Router static generation (#82604)

`allReady` is available in all supported React versions so we can remove the conditional check.  The helper type can be replaced with the actual type from React.
parent 2deacca0
import type { IncomingMessage, ServerResponse } from 'http'
import type { ParsedUrlQuery } from 'querystring'
import type { ReactDOMServerReadableStream } from 'react-dom/server'
import type { NextRouter } from '../shared/lib/router/router'
import type { HtmlProps } from '../shared/lib/html-context.shared-runtime'
import type { DomainLocale } from './config'
......@@ -30,7 +31,6 @@ import type {
SizeLimit,
} from '../types'
import type { UnwrapPromise } from '../lib/coalesced-function'
import type { ReactReadableStream } from './stream-utils/node-web-streams-helper'
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin'
import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin'
import type { PagesModule } from './route-modules/pages/module'
......@@ -1305,7 +1305,7 @@ export async function renderToHTMLImpl(
renderShell: (
_App: AppType,
_Component: NextComponentType
) => Promise<ReactReadableStream>
) => Promise<ReactDOMServerReadableStream>
) {
const renderPage: RenderPage = async (
options: ComponentsEnhancer = {}
......
import type { ReactDOMServerReadableStream } from 'react-dom/server'
import { getTracer } from '../lib/trace/tracer'
import { AppRenderSpan } from '../lib/trace/constants'
import { DetachedPromise } from '../../lib/detached-promise'
......@@ -17,10 +18,6 @@ function voidCatch() {
// and be unhandled
}
export type ReactReadableStream = ReadableStream<Uint8Array> & {
allReady?: Promise<void> | undefined
}
// We can share the same encoder instance everywhere
// Notably we cannot do the same for TextDecoder because it is stateful
// when handling streaming data
......@@ -221,7 +218,7 @@ export function renderToInitialFizzStream({
}
element: React.ReactElement
streamOptions?: Parameters<typeof ReactDOMServer.renderToReadableStream>[1]
}): Promise<ReactReadableStream> {
}): Promise<ReactDOMServerReadableStream> {
return getTracer().trace(AppRenderSpan.renderToReadableStream, async () =>
ReactDOMServer.renderToReadableStream(element, streamOptions)
)
......@@ -678,7 +675,7 @@ export type ContinueStreamOptions = {
}
export async function continueFizzStream(
renderStream: ReactReadableStream,
renderStream: ReactDOMServerReadableStream,
{
suffix,
inlinedDataStream,
......@@ -693,9 +690,8 @@ export async function continueFizzStream(
// Suffix itself might contain close tags at the end, so we need to split it.
const suffixUnclosed = suffix ? suffix.split(CLOSE_TAG, 1)[0] : null
// If we're generating static HTML and there's an `allReady` promise on the
// stream, we need to wait for it to resolve before continuing.
if (isStaticGeneration && 'allReady' in renderStream) {
// If we're generating static HTML we need to wait for it to resolve before continuing.
if (isStaticGeneration) {
await renderStream.allReady
}
......
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