Skip to content

Commit 1aa544d

Browse files
committed
Move writing queues to renderState
Bootstrapscripts, external runtime and resource queues are all expected to flush in the prerender. They're only needed by the prerender and then they can get dropped/reset. Threfore we can move them to the renderState.
1 parent 653905a commit 1aa544d

13 files changed

+259
-201
lines changed

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 173 additions & 145 deletions
Large diffs are not rendered by default.

packages/react-dom-bindings/src/server/ReactFizzConfigDOMLegacy.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,22 @@ export type RenderState = {
3939
startInlineScript: PrecomputedChunk,
4040
htmlChunks: null | Array<Chunk | PrecomputedChunk>,
4141
headChunks: null | Array<Chunk | PrecomputedChunk>,
42+
externalRuntimeScript: null | any,
43+
bootstrapChunks: Array<Chunk | PrecomputedChunk>,
4244
charsetChunks: Array<Chunk | PrecomputedChunk>,
4345
preconnectChunks: Array<Chunk | PrecomputedChunk>,
4446
importMapChunks: Array<Chunk | PrecomputedChunk>,
4547
preloadChunks: Array<Chunk | PrecomputedChunk>,
4648
hoistableChunks: Array<Chunk | PrecomputedChunk>,
49+
preconnects: Set<any>,
50+
fontPreloads: Set<any>,
51+
highImagePreloads: Set<any>,
52+
// usedImagePreloads: Set<any>,
53+
precedences: Map<string, Set<any>>,
54+
stylePrecedences: Map<string, any>,
55+
bootstrapScripts: Set<any>,
56+
scripts: Set<any>,
57+
bulkPreloads: Set<any>,
4758
boundaryResources: ?BoundaryResources,
4859
stylesToHoist: boolean,
4960
// This is an extra field for the legacy renderer
@@ -52,10 +63,17 @@ export type RenderState = {
5263

5364
export function createRenderState(
5465
resumableState: ResumableState,
55-
nonce: string | void,
5666
generateStaticMarkup: boolean,
5767
): RenderState {
58-
const renderState = createRenderStateImpl(resumableState, nonce);
68+
const renderState = createRenderStateImpl(
69+
resumableState,
70+
undefined,
71+
undefined,
72+
undefined,
73+
undefined,
74+
undefined,
75+
undefined,
76+
);
5977
return {
6078
// Keep this in sync with ReactFizzConfigDOM
6179
placeholderPrefix: renderState.placeholderPrefix,
@@ -64,11 +82,22 @@ export function createRenderState(
6482
startInlineScript: renderState.startInlineScript,
6583
htmlChunks: renderState.htmlChunks,
6684
headChunks: renderState.headChunks,
85+
externalRuntimeScript: renderState.externalRuntimeScript,
86+
bootstrapChunks: renderState.bootstrapChunks,
6787
charsetChunks: renderState.charsetChunks,
6888
preconnectChunks: renderState.preconnectChunks,
6989
importMapChunks: renderState.importMapChunks,
7090
preloadChunks: renderState.preloadChunks,
7191
hoistableChunks: renderState.hoistableChunks,
92+
preconnects: renderState.preconnects,
93+
fontPreloads: renderState.fontPreloads,
94+
highImagePreloads: renderState.highImagePreloads,
95+
// usedImagePreloads: renderState.usedImagePreloads,
96+
precedences: renderState.precedences,
97+
stylePrecedences: renderState.stylePrecedences,
98+
bootstrapScripts: renderState.bootstrapScripts,
99+
scripts: renderState.scripts,
100+
bulkPreloads: renderState.bulkPreloads,
72101
boundaryResources: renderState.boundaryResources,
73102
stylesToHoist: renderState.stylesToHoist,
74103

packages/react-dom/src/server/ReactDOMFizzServerBrowser.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import {
2626
createResumableState,
2727
createRenderState,
28+
resumeRenderState,
2829
createRootFormatContext,
2930
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
3031

@@ -96,10 +97,6 @@ function renderToReadableStream(
9697
}
9798
const resumableState = createResumableState(
9899
options ? options.identifierPrefix : undefined,
99-
options ? options.nonce : undefined,
100-
options ? options.bootstrapScriptContent : undefined,
101-
options ? options.bootstrapScripts : undefined,
102-
options ? options.bootstrapModules : undefined,
103100
options ? options.unstable_externalRuntimeSrc : undefined,
104101
);
105102
const request = createRequest(
@@ -108,6 +105,10 @@ function renderToReadableStream(
108105
createRenderState(
109106
resumableState,
110107
options ? options.nonce : undefined,
108+
options ? options.bootstrapScriptContent : undefined,
109+
options ? options.bootstrapScripts : undefined,
110+
options ? options.bootstrapModules : undefined,
111+
options ? options.unstable_externalRuntimeSrc : undefined,
111112
options ? options.importMap : undefined,
112113
),
113114
createRootFormatContext(options ? options.namespaceURI : undefined),
@@ -177,10 +178,9 @@ function resume(
177178
const request = resumeRequest(
178179
children,
179180
postponedState,
180-
createRenderState(
181+
resumeRenderState(
181182
postponedState.resumableState,
182183
options ? options.nonce : undefined,
183-
undefined, // importMap
184184
),
185185
options ? options.onError : undefined,
186186
onAllReady,

packages/react-dom/src/server/ReactDOMFizzServerBun.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ function renderToReadableStream(
8787
}
8888
const resumableState = createResumableState(
8989
options ? options.identifierPrefix : undefined,
90-
options ? options.nonce : undefined,
91-
options ? options.bootstrapScriptContent : undefined,
92-
options ? options.bootstrapScripts : undefined,
93-
options ? options.bootstrapModules : undefined,
9490
options ? options.unstable_externalRuntimeSrc : undefined,
9591
);
9692
const request = createRequest(
@@ -99,6 +95,10 @@ function renderToReadableStream(
9995
createRenderState(
10096
resumableState,
10197
options ? options.nonce : undefined,
98+
options ? options.bootstrapScriptContent : undefined,
99+
options ? options.bootstrapScripts : undefined,
100+
options ? options.bootstrapModules : undefined,
101+
options ? options.unstable_externalRuntimeSrc : undefined,
102102
options ? options.importMap : undefined,
103103
),
104104
createRootFormatContext(options ? options.namespaceURI : undefined),

packages/react-dom/src/server/ReactDOMFizzServerEdge.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import {
2626
createResumableState,
2727
createRenderState,
28+
resumeRenderState,
2829
createRootFormatContext,
2930
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
3031

@@ -96,10 +97,6 @@ function renderToReadableStream(
9697
}
9798
const resumableState = createResumableState(
9899
options ? options.identifierPrefix : undefined,
99-
options ? options.nonce : undefined,
100-
options ? options.bootstrapScriptContent : undefined,
101-
options ? options.bootstrapScripts : undefined,
102-
options ? options.bootstrapModules : undefined,
103100
options ? options.unstable_externalRuntimeSrc : undefined,
104101
);
105102
const request = createRequest(
@@ -108,6 +105,10 @@ function renderToReadableStream(
108105
createRenderState(
109106
resumableState,
110107
options ? options.nonce : undefined,
108+
options ? options.bootstrapScriptContent : undefined,
109+
options ? options.bootstrapScripts : undefined,
110+
options ? options.bootstrapModules : undefined,
111+
options ? options.unstable_externalRuntimeSrc : undefined,
111112
options ? options.importMap : undefined,
112113
),
113114
createRootFormatContext(options ? options.namespaceURI : undefined),
@@ -177,10 +178,9 @@ function resume(
177178
const request = resumeRequest(
178179
children,
179180
postponedState,
180-
createRenderState(
181+
resumeRenderState(
181182
postponedState.resumableState,
182183
options ? options.nonce : undefined,
183-
undefined, // importMap
184184
),
185185
options ? options.onError : undefined,
186186
onAllReady,

packages/react-dom/src/server/ReactDOMFizzServerNode.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import {
2828
createResumableState,
2929
createRenderState,
30+
resumeRenderState,
3031
createRootFormatContext,
3132
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
3233

@@ -76,10 +77,6 @@ type PipeableStream = {
7677
function createRequestImpl(children: ReactNodeList, options: void | Options) {
7778
const resumableState = createResumableState(
7879
options ? options.identifierPrefix : undefined,
79-
options ? options.nonce : undefined,
80-
options ? options.bootstrapScriptContent : undefined,
81-
options ? options.bootstrapScripts : undefined,
82-
options ? options.bootstrapModules : undefined,
8380
options ? options.unstable_externalRuntimeSrc : undefined,
8481
);
8582
return createRequest(
@@ -88,6 +85,10 @@ function createRequestImpl(children: ReactNodeList, options: void | Options) {
8885
createRenderState(
8986
resumableState,
9087
options ? options.nonce : undefined,
88+
options ? options.bootstrapScriptContent : undefined,
89+
options ? options.bootstrapScripts : undefined,
90+
options ? options.bootstrapModules : undefined,
91+
options ? options.unstable_externalRuntimeSrc : undefined,
9192
options ? options.importMap : undefined,
9293
),
9394
createRootFormatContext(options ? options.namespaceURI : undefined),
@@ -146,10 +147,9 @@ function resumeRequestImpl(
146147
return resumeRequest(
147148
children,
148149
postponedState,
149-
createRenderState(
150+
resumeRenderState(
150151
postponedState.resumableState,
151152
options ? options.nonce : undefined,
152-
undefined, // importMap
153153
),
154154
options ? options.onError : undefined,
155155
options ? options.onAllReady : undefined,

packages/react-dom/src/server/ReactDOMFizzStaticBrowser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ function prerender(
7474
}
7575
const resources = createResumableState(
7676
options ? options.identifierPrefix : undefined,
77-
undefined, // nonce is not compatible with prerendered bootstrap scripts
78-
options ? options.bootstrapScriptContent : undefined,
79-
options ? options.bootstrapScripts : undefined,
80-
options ? options.bootstrapModules : undefined,
8177
options ? options.unstable_externalRuntimeSrc : undefined,
8278
);
8379
const request = createPrerenderRequest(
8480
children,
8581
resources,
8682
createRenderState(
8783
resources,
88-
undefined, // nonce
84+
undefined, // nonce is not compatible with prerendered bootstrap scripts
85+
options ? options.bootstrapScriptContent : undefined,
86+
options ? options.bootstrapScripts : undefined,
87+
options ? options.bootstrapModules : undefined,
88+
options ? options.unstable_externalRuntimeSrc : undefined,
8989
options ? options.importMap : undefined,
9090
),
9191
createRootFormatContext(options ? options.namespaceURI : undefined),

packages/react-dom/src/server/ReactDOMFizzStaticEdge.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ function prerender(
7474
}
7575
const resources = createResumableState(
7676
options ? options.identifierPrefix : undefined,
77-
undefined, // nonce is not compatible with prerendered bootstrap scripts
78-
options ? options.bootstrapScriptContent : undefined,
79-
options ? options.bootstrapScripts : undefined,
80-
options ? options.bootstrapModules : undefined,
8177
options ? options.unstable_externalRuntimeSrc : undefined,
8278
);
8379
const request = createPrerenderRequest(
8480
children,
8581
resources,
8682
createRenderState(
8783
resources,
88-
undefined, // nonce
84+
undefined, // nonce is not compatible with prerendered bootstrap scripts
85+
options ? options.bootstrapScriptContent : undefined,
86+
options ? options.bootstrapScripts : undefined,
87+
options ? options.bootstrapModules : undefined,
88+
options ? options.unstable_externalRuntimeSrc : undefined,
8989
options ? options.importMap : undefined,
9090
),
9191
createRootFormatContext(options ? options.namespaceURI : undefined),

packages/react-dom/src/server/ReactDOMFizzStaticNode.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ function prerenderToNodeStream(
8888
}
8989
const resumableState = createResumableState(
9090
options ? options.identifierPrefix : undefined,
91-
undefined, // nonce is not compatible with prerendered bootstrap scripts
92-
options ? options.bootstrapScriptContent : undefined,
93-
options ? options.bootstrapScripts : undefined,
94-
options ? options.bootstrapModules : undefined,
9591
options ? options.unstable_externalRuntimeSrc : undefined,
9692
);
9793
const request = createPrerenderRequest(
9894
children,
9995
resumableState,
10096
createRenderState(
10197
resumableState,
102-
undefined, // nonce
98+
undefined, // nonce is not compatible with prerendered bootstrap scripts
99+
options ? options.bootstrapScriptContent : undefined,
100+
options ? options.bootstrapScripts : undefined,
101+
options ? options.bootstrapModules : undefined,
102+
options ? options.unstable_externalRuntimeSrc : undefined,
103103
options ? options.importMap : undefined,
104104
),
105105
createRootFormatContext(options ? options.namespaceURI : undefined),

packages/react-dom/src/server/ReactDOMLegacyServerImpl.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,11 @@ function renderToStringImpl(
6363
const resumableState = createResumableState(
6464
options ? options.identifierPrefix : undefined,
6565
undefined,
66-
undefined,
67-
undefined,
68-
undefined,
69-
undefined,
7066
);
7167
const request = createRequest(
7268
children,
7369
resumableState,
74-
createRenderState(resumableState, undefined, generateStaticMarkup),
70+
createRenderState(resumableState, generateStaticMarkup),
7571
createRootFormatContext(),
7672
Infinity,
7773
onError,

0 commit comments

Comments
 (0)