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