@@ -6,6 +6,7 @@ import type { DomainLocale } from './config'
6
6
import type {
7
7
AppType ,
8
8
DocumentInitialProps ,
9
+ DocumentType ,
9
10
DocumentProps ,
10
11
DocumentContext ,
11
12
NextComponentType ,
@@ -35,6 +36,7 @@ import {
35
36
UNSTABLE_REVALIDATE_RENAME_ERROR ,
36
37
} from '../lib/constants'
37
38
import {
39
+ NEXT_BUILTIN_DOCUMENT ,
38
40
SERVER_PROPS_ID ,
39
41
STATIC_PROPS_ID ,
40
42
STATIC_STATUS_PAGES ,
@@ -769,6 +771,7 @@ export async function renderToHTML(
769
771
770
772
const { html, head } = await docCtx . renderPage ( { enhanceApp } )
771
773
const styles = jsxStyleRegistry . styles ( { nonce : options . nonce } )
774
+ jsxStyleRegistry . flush ( )
772
775
return { html, head, styles }
773
776
} ,
774
777
}
@@ -1311,14 +1314,14 @@ export async function renderToHTML(
1311
1314
// 1. Using `Document.getInitialProps` in the Edge runtime.
1312
1315
// 2. Using the class component `Document` with concurrent features.
1313
1316
1314
- const builtinDocument = ( Document as any ) . __next_internal_document as
1315
- | typeof Document
1316
- | undefined
1317
+ const BuiltinFunctionalDocument : DocumentType | undefined = (
1318
+ Document as any
1319
+ ) [ NEXT_BUILTIN_DOCUMENT ]
1317
1320
1318
1321
if ( process . env . NEXT_RUNTIME === 'edge' && Document . getInitialProps ) {
1319
1322
// In the Edge runtime, `Document.getInitialProps` isn't supported.
1320
1323
// We throw an error here if it's customized.
1321
- if ( ! builtinDocument ) {
1324
+ if ( ! BuiltinFunctionalDocument ) {
1322
1325
throw new Error (
1323
1326
'`getInitialProps` in Document component is not supported with the Edge Runtime.'
1324
1327
)
@@ -1329,8 +1332,8 @@ export async function renderToHTML(
1329
1332
( isServerComponent || process . env . NEXT_RUNTIME === 'edge' ) &&
1330
1333
Document . getInitialProps
1331
1334
) {
1332
- if ( builtinDocument ) {
1333
- Document = builtinDocument
1335
+ if ( BuiltinFunctionalDocument ) {
1336
+ Document = BuiltinFunctionalDocument
1334
1337
} else {
1335
1338
throw new Error (
1336
1339
'`getInitialProps` in Document component is not supported with React Server Components.'
@@ -1433,6 +1436,7 @@ export async function renderToHTML(
1433
1436
}
1434
1437
1435
1438
if ( ! process . env . __NEXT_REACT_ROOT ) {
1439
+ // Enabling react legacy rendering mode: __NEXT_REACT_ROOT = false
1436
1440
if ( Document . getInitialProps ) {
1437
1441
const documentInitialPropsRes = await documentInitialProps ( )
1438
1442
if ( documentInitialPropsRes === null ) return null
@@ -1468,6 +1472,7 @@ export async function renderToHTML(
1468
1472
}
1469
1473
}
1470
1474
} else {
1475
+ // Enabling react concurrent rendering mode: __NEXT_REACT_ROOT = true
1471
1476
let renderStream : ReadableStream < Uint8Array > & {
1472
1477
allReady ?: Promise < void > | undefined
1473
1478
}
@@ -1534,13 +1539,11 @@ export async function renderToHTML(
1534
1539
// be streamed.
1535
1540
// Do not use `await` here.
1536
1541
generateStaticFlightDataIfNeeded ( )
1537
-
1538
1542
return await continueFromInitialStream ( {
1539
1543
renderStream,
1540
1544
suffix,
1541
1545
dataStream : serverComponentsInlinedTransformStream ?. readable ,
1542
- generateStaticHTML :
1543
- generateStaticHTML || ! process . env . __NEXT_REACT_ROOT ,
1546
+ generateStaticHTML,
1544
1547
flushEffectHandler,
1545
1548
} )
1546
1549
}
@@ -1572,8 +1575,8 @@ export async function renderToHTML(
1572
1575
1573
1576
return < Document { ...htmlProps } { ...docProps } />
1574
1577
}
1575
- let styles
1576
1578
1579
+ let styles
1577
1580
if ( hasDocumentGetInitialProps ) {
1578
1581
styles = docProps . styles
1579
1582
} else {
0 commit comments