Skip to content

Commit 18c3ec1

Browse files
committed
This commit implements the onHeadersReady call
1 parent a1019fe commit 18c3ec1

File tree

15 files changed

+673
-157
lines changed

15 files changed

+673
-157
lines changed

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

Lines changed: 487 additions & 90 deletions
Large diffs are not rendered by default.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
*/
99

1010
import type {
11+
RenderState as BaseRenderState,
1112
ResumableState,
1213
BoundaryResources,
1314
StyleQueue,
1415
Resource,
16+
HeadersDescriptor,
1517
} from './ReactFizzConfigDOM';
1618

1719
import {
@@ -46,6 +48,14 @@ export type RenderState = {
4648
headChunks: null | Array<Chunk | PrecomputedChunk>,
4749
externalRuntimeScript: null | any,
4850
bootstrapChunks: Array<Chunk | PrecomputedChunk>,
51+
onHeaders: void | ((headers: HeadersDescriptor) => void),
52+
headers: null | {
53+
preconnects: string,
54+
fontPreloads: string,
55+
highImagePreloads: string,
56+
remainingCapacity: number,
57+
},
58+
resets: BaseRenderState['resets'],
4959
charsetChunks: Array<Chunk | PrecomputedChunk>,
5060
preconnectChunks: Array<Chunk | PrecomputedChunk>,
5161
importMapChunks: Array<Chunk | PrecomputedChunk>,
@@ -83,6 +93,7 @@ export function createRenderState(
8393
undefined,
8494
undefined,
8595
undefined,
96+
undefined,
8697
);
8798
return {
8899
// Keep this in sync with ReactFizzConfigDOM
@@ -94,6 +105,9 @@ export function createRenderState(
94105
headChunks: renderState.headChunks,
95106
externalRuntimeScript: renderState.externalRuntimeScript,
96107
bootstrapChunks: renderState.bootstrapChunks,
108+
onHeaders: renderState.onHeaders,
109+
headers: renderState.headers,
110+
resets: renderState.resets,
97111
charsetChunks: renderState.charsetChunks,
98112
preconnectChunks: renderState.preconnectChunks,
99113
importMapChunks: renderState.importMapChunks,
@@ -159,6 +173,7 @@ export {
159173
setCurrentlyRenderingBoundaryResourcesTarget,
160174
prepareHostDispatcher,
161175
resetResumableState,
176+
emitEarlyPreloads,
162177
} from './ReactFizzConfigDOM';
163178

164179
import escapeTextForBrowser from './escapeTextForBrowser';

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
* @flow
88
*/
99

10+
import type {PostponedState} from 'react-server/src/ReactFizzServer';
11+
import type {ReactNodeList, ReactFormState} from 'shared/ReactTypes';
1012
import type {
11-
PostponedState,
13+
BootstrapScriptDescriptor,
1214
HeadersDescriptor,
13-
} from 'react-server/src/ReactFizzServer';
14-
import type {ReactNodeList, ReactFormState} from 'shared/ReactTypes';
15-
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
15+
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
1616
import type {ImportMap} from '../shared/ReactDOMTypes';
1717

1818
import ReactVersion from 'shared/ReactVersion';
@@ -48,6 +48,7 @@ type Options = {
4848
importMap?: ImportMap,
4949
formState?: ReactFormState<any, any> | null,
5050
onHeaders?: (headers: Headers) => void,
51+
headersLengthHint?: number,
5152
};
5253

5354
type ResumeOptions = {
@@ -125,6 +126,8 @@ function renderToReadableStream(
125126
options ? options.bootstrapModules : undefined,
126127
options ? options.unstable_externalRuntimeSrc : undefined,
127128
options ? options.importMap : undefined,
129+
onHeadersImpl,
130+
options ? options.headersLengthHint : undefined,
128131
),
129132
createRootFormatContext(options ? options.namespaceURI : undefined),
130133
options ? options.progressiveChunkSize : undefined,
@@ -135,7 +138,6 @@ function renderToReadableStream(
135138
onFatalError,
136139
options ? options.onPostpone : undefined,
137140
options ? options.formState : undefined,
138-
onHeadersImpl,
139141
);
140142
if (options && options.signal) {
141143
const signal = options.signal;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
* @flow
88
*/
99

10-
import type {HeadersDescriptor} from 'react-server/src/ReactFizzServer';
1110
import type {ReactNodeList, ReactFormState} from 'shared/ReactTypes';
12-
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
11+
import type {
12+
BootstrapScriptDescriptor,
13+
HeadersDescriptor,
14+
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
1315
import type {ImportMap} from '../shared/ReactDOMTypes';
1416

1517
import ReactVersion from 'shared/ReactVersion';
@@ -43,6 +45,7 @@ type Options = {
4345
importMap?: ImportMap,
4446
formState?: ReactFormState<any, any> | null,
4547
onHeaders?: (headers: Headers) => void,
48+
headersLengthHint?: number,
4649
};
4750

4851
// TODO: Move to sub-classing ReadableStream.
@@ -113,6 +116,8 @@ function renderToReadableStream(
113116
options ? options.bootstrapModules : undefined,
114117
options ? options.unstable_externalRuntimeSrc : undefined,
115118
options ? options.importMap : undefined,
119+
onHeadersImpl,
120+
options ? options.headersLengthHint : undefined,
116121
),
117122
createRootFormatContext(options ? options.namespaceURI : undefined),
118123
options ? options.progressiveChunkSize : undefined,
@@ -123,7 +128,6 @@ function renderToReadableStream(
123128
onFatalError,
124129
options ? options.onPostpone : undefined,
125130
options ? options.formState : undefined,
126-
onHeadersImpl,
127131
);
128132
if (options && options.signal) {
129133
const signal = options.signal;

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
* @flow
88
*/
99

10+
import type {PostponedState} from 'react-server/src/ReactFizzServer';
11+
import type {ReactNodeList, ReactFormState} from 'shared/ReactTypes';
1012
import type {
11-
PostponedState,
13+
BootstrapScriptDescriptor,
1214
HeadersDescriptor,
13-
} from 'react-server/src/ReactFizzServer';
14-
import type {ReactNodeList, ReactFormState} from 'shared/ReactTypes';
15-
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
15+
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
1616
import type {ImportMap} from '../shared/ReactDOMTypes';
1717

1818
import ReactVersion from 'shared/ReactVersion';
@@ -48,6 +48,7 @@ type Options = {
4848
importMap?: ImportMap,
4949
formState?: ReactFormState<any, any> | null,
5050
onHeaders?: (headers: Headers) => void,
51+
headersLengthHint?: number,
5152
};
5253

5354
type ResumeOptions = {
@@ -125,6 +126,8 @@ function renderToReadableStream(
125126
options ? options.bootstrapModules : undefined,
126127
options ? options.unstable_externalRuntimeSrc : undefined,
127128
options ? options.importMap : undefined,
129+
onHeadersImpl,
130+
options ? options.headersLengthHint : undefined,
128131
),
129132
createRootFormatContext(options ? options.namespaceURI : undefined),
130133
options ? options.progressiveChunkSize : undefined,
@@ -135,7 +138,6 @@ function renderToReadableStream(
135138
onFatalError,
136139
options ? options.onPostpone : undefined,
137140
options ? options.formState : undefined,
138-
onHeadersImpl,
139141
);
140142
if (options && options.signal) {
141143
const signal = options.signal;
@@ -204,7 +206,6 @@ function resume(
204206
onShellReady,
205207
onShellError,
206208
onFatalError,
207-
undefined,
208209
options ? options.onPostpone : undefined,
209210
);
210211
if (options && options.signal) {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
* @flow
88
*/
99

10-
import type {
11-
Request,
12-
PostponedState,
13-
HeadersDescriptor,
14-
} from 'react-server/src/ReactFizzServer';
10+
import type {Request, PostponedState} from 'react-server/src/ReactFizzServer';
1511
import type {ReactNodeList, ReactFormState} from 'shared/ReactTypes';
1612
import type {Writable} from 'stream';
17-
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
13+
import type {
14+
BootstrapScriptDescriptor,
15+
HeadersDescriptor,
16+
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
1817
import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
1918
import type {ImportMap} from '../shared/ReactDOMTypes';
2019

@@ -65,6 +64,7 @@ type Options = {
6564
importMap?: ImportMap,
6665
formState?: ReactFormState<any, any> | null,
6766
onHeaders?: (headers: HeadersDescriptor) => void,
67+
headersLengthHint?: number,
6868
};
6969

7070
type ResumeOptions = {
@@ -99,6 +99,8 @@ function createRequestImpl(children: ReactNodeList, options: void | Options) {
9999
options ? options.bootstrapModules : undefined,
100100
options ? options.unstable_externalRuntimeSrc : undefined,
101101
options ? options.importMap : undefined,
102+
options ? options.onHeaders : undefined,
103+
options ? options.headersLengthHint : undefined,
102104
),
103105
createRootFormatContext(options ? options.namespaceURI : undefined),
104106
options ? options.progressiveChunkSize : undefined,
@@ -109,7 +111,6 @@ function createRequestImpl(children: ReactNodeList, options: void | Options) {
109111
undefined,
110112
options ? options.onPostpone : undefined,
111113
options ? options.formState : undefined,
112-
options ? options.onHeaders : undefined,
113114
);
114115
}
115116

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
*/
99

1010
import type {ReactNodeList} from 'shared/ReactTypes';
11-
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
1211
import type {
13-
PostponedState,
12+
BootstrapScriptDescriptor,
1413
HeadersDescriptor,
15-
} from 'react-server/src/ReactFizzServer';
14+
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
15+
import type {PostponedState} from 'react-server/src/ReactFizzServer';
1616
import type {ImportMap} from '../shared/ReactDOMTypes';
1717

1818
import ReactVersion from 'shared/ReactVersion';
@@ -45,6 +45,7 @@ type Options = {
4545
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
4646
importMap?: ImportMap,
4747
onHeaders?: (headers: Headers) => void,
48+
headersLengthHint?: number,
4849
};
4950

5051
type StaticResult = {
@@ -105,6 +106,8 @@ function prerender(
105106
options ? options.bootstrapModules : undefined,
106107
options ? options.unstable_externalRuntimeSrc : undefined,
107108
options ? options.importMap : undefined,
109+
onHeadersImpl,
110+
options ? options.headersLengthHint : undefined,
108111
),
109112
createRootFormatContext(options ? options.namespaceURI : undefined),
110113
options ? options.progressiveChunkSize : undefined,
@@ -114,7 +117,6 @@ function prerender(
114117
undefined,
115118
onFatalError,
116119
options ? options.onPostpone : undefined,
117-
onHeadersImpl,
118120
);
119121
if (options && options.signal) {
120122
const signal = options.signal;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
*/
99

1010
import type {ReactNodeList} from 'shared/ReactTypes';
11-
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
1211
import type {
13-
PostponedState,
12+
BootstrapScriptDescriptor,
1413
HeadersDescriptor,
15-
} from 'react-server/src/ReactFizzServer';
14+
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
15+
import type {PostponedState} from 'react-server/src/ReactFizzServer';
1616
import type {ImportMap} from '../shared/ReactDOMTypes';
1717

1818
import ReactVersion from 'shared/ReactVersion';
@@ -45,6 +45,7 @@ type Options = {
4545
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
4646
importMap?: ImportMap,
4747
onHeaders?: (headers: Headers) => void,
48+
headersLengthHint?: number,
4849
};
4950

5051
type StaticResult = {
@@ -104,6 +105,8 @@ function prerender(
104105
options ? options.bootstrapModules : undefined,
105106
options ? options.unstable_externalRuntimeSrc : undefined,
106107
options ? options.importMap : undefined,
108+
onHeadersImpl,
109+
options ? options.headersLengthHint : undefined,
107110
),
108111
createRootFormatContext(options ? options.namespaceURI : undefined),
109112
options ? options.progressiveChunkSize : undefined,
@@ -113,7 +116,6 @@ function prerender(
113116
undefined,
114117
onFatalError,
115118
options ? options.onPostpone : undefined,
116-
onHeadersImpl,
117119
);
118120
if (options && options.signal) {
119121
const signal = options.signal;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
*/
99

1010
import type {ReactNodeList} from 'shared/ReactTypes';
11-
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
1211
import type {
13-
PostponedState,
12+
BootstrapScriptDescriptor,
1413
HeadersDescriptor,
15-
} from 'react-server/src/ReactFizzServer';
14+
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
15+
import type {PostponedState} from 'react-server/src/ReactFizzServer';
1616
import type {ImportMap} from '../shared/ReactDOMTypes';
1717

1818
import {Writable, Readable} from 'stream';
@@ -46,6 +46,7 @@ type Options = {
4646
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
4747
importMap?: ImportMap,
4848
onHeaders?: (headers: HeadersDescriptor) => void,
49+
headersLengthHint?: number,
4950
};
5051

5152
type StaticResult = {
@@ -105,6 +106,8 @@ function prerenderToNodeStream(
105106
options ? options.bootstrapModules : undefined,
106107
options ? options.unstable_externalRuntimeSrc : undefined,
107108
options ? options.importMap : undefined,
109+
options ? options.onHeaders : undefined,
110+
options ? options.headersLengthHint : undefined,
108111
),
109112
createRootFormatContext(options ? options.namespaceURI : undefined),
110113
options ? options.progressiveChunkSize : undefined,
@@ -114,7 +117,6 @@ function prerenderToNodeStream(
114117
undefined,
115118
onFatalError,
116119
options ? options.onPostpone : undefined,
117-
options ? options.onHeaders : undefined,
118120
);
119121
if (options && options.signal) {
120122
const signal = options.signal;

packages/react-dom/src/shared/ReactDOMTypes.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type PreloadOptions = {
1717
integrity?: string,
1818
type?: string,
1919
nonce?: string,
20-
fetchPriority?: 'high' | 'low' | 'auto',
20+
fetchPriority?: FetchPriorityEnum,
2121
imageSrcSet?: string,
2222
imageSizes?: string,
2323
referrerPolicy?: string,
@@ -34,7 +34,7 @@ export type PreinitOptions = {
3434
crossOrigin?: string,
3535
integrity?: string,
3636
nonce?: string,
37-
fetchPriority?: 'high' | 'low' | 'auto',
37+
fetchPriority?: FetchPriorityEnum,
3838
};
3939
export type PreinitModuleOptions = {
4040
as?: string,
@@ -51,10 +51,11 @@ export type PreloadImplOptions = {
5151
integrity?: ?string,
5252
nonce?: ?string,
5353
type?: ?string,
54-
fetchPriority?: ?FetchPriorityEnum,
54+
fetchPriority?: ?string,
5555
referrerPolicy?: ?string,
5656
imageSrcSet?: ?string,
5757
imageSizes?: ?string,
58+
media?: ?string,
5859
};
5960
export type PreloadModuleImplOptions = {
6061
as?: ?string,
@@ -65,12 +66,12 @@ export type PreloadModuleImplOptions = {
6566
export type PreinitStyleOptions = {
6667
crossOrigin?: ?CrossOriginEnum,
6768
integrity?: ?string,
68-
fetchPriority?: ?FetchPriorityEnum,
69+
fetchPriority?: ?string,
6970
};
7071
export type PreinitScriptOptions = {
7172
crossOrigin?: ?CrossOriginEnum,
7273
integrity?: ?string,
73-
fetchPriority?: ?FetchPriorityEnum,
74+
fetchPriority?: ?string,
7475
nonce?: ?string,
7576
};
7677
export type PreinitModuleScriptOptions = {

0 commit comments

Comments
 (0)