Skip to content

Commit 5fa0987

Browse files
authored
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.
1 parent 2deacca commit 5fa0987

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

packages/next/src/server/render.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { IncomingMessage, ServerResponse } from 'http'
22
import type { ParsedUrlQuery } from 'querystring'
3+
import type { ReactDOMServerReadableStream } from 'react-dom/server'
34
import type { NextRouter } from '../shared/lib/router/router'
45
import type { HtmlProps } from '../shared/lib/html-context.shared-runtime'
56
import type { DomainLocale } from './config'
@@ -30,7 +31,6 @@ import type {
3031
SizeLimit,
3132
} from '../types'
3233
import type { UnwrapPromise } from '../lib/coalesced-function'
33-
import type { ReactReadableStream } from './stream-utils/node-web-streams-helper'
3434
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin'
3535
import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin'
3636
import type { PagesModule } from './route-modules/pages/module'
@@ -1305,7 +1305,7 @@ export async function renderToHTMLImpl(
13051305
renderShell: (
13061306
_App: AppType,
13071307
_Component: NextComponentType
1308-
) => Promise<ReactReadableStream>
1308+
) => Promise<ReactDOMServerReadableStream>
13091309
) {
13101310
const renderPage: RenderPage = async (
13111311
options: ComponentsEnhancer = {}

packages/next/src/server/stream-utils/node-web-streams-helper.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ReactDOMServerReadableStream } from 'react-dom/server'
12
import { getTracer } from '../lib/trace/tracer'
23
import { AppRenderSpan } from '../lib/trace/constants'
34
import { DetachedPromise } from '../../lib/detached-promise'
@@ -17,10 +18,6 @@ function voidCatch() {
1718
// and be unhandled
1819
}
1920

20-
export type ReactReadableStream = ReadableStream<Uint8Array> & {
21-
allReady?: Promise<void> | undefined
22-
}
23-
2421
// We can share the same encoder instance everywhere
2522
// Notably we cannot do the same for TextDecoder because it is stateful
2623
// when handling streaming data
@@ -221,7 +218,7 @@ export function renderToInitialFizzStream({
221218
}
222219
element: React.ReactElement
223220
streamOptions?: Parameters<typeof ReactDOMServer.renderToReadableStream>[1]
224-
}): Promise<ReactReadableStream> {
221+
}): Promise<ReactDOMServerReadableStream> {
225222
return getTracer().trace(AppRenderSpan.renderToReadableStream, async () =>
226223
ReactDOMServer.renderToReadableStream(element, streamOptions)
227224
)
@@ -678,7 +675,7 @@ export type ContinueStreamOptions = {
678675
}
679676

680677
export async function continueFizzStream(
681-
renderStream: ReactReadableStream,
678+
renderStream: ReactDOMServerReadableStream,
682679
{
683680
suffix,
684681
inlinedDataStream,
@@ -693,9 +690,8 @@ export async function continueFizzStream(
693690
// Suffix itself might contain close tags at the end, so we need to split it.
694691
const suffixUnclosed = suffix ? suffix.split(CLOSE_TAG, 1)[0] : null
695692

696-
// If we're generating static HTML and there's an `allReady` promise on the
697-
// stream, we need to wait for it to resolve before continuing.
698-
if (isStaticGeneration && 'allReady' in renderStream) {
693+
// If we're generating static HTML we need to wait for it to resolve before continuing.
694+
if (isStaticGeneration) {
699695
await renderStream.allReady
700696
}
701697

0 commit comments

Comments
 (0)