Skip to content

Commit

Permalink
This commit implements the onHeadersReady call
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Nov 3, 2023
1 parent c2664fc commit c8dcce2
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 115 deletions.
421 changes: 346 additions & 75 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOMLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
BoundaryResources,
StyleQueue,
Resource,
HeadersDescriptor,
} from './ReactFizzConfigDOM';

import {
Expand Down Expand Up @@ -46,6 +47,13 @@ export type RenderState = {
headChunks: null | Array<Chunk | PrecomputedChunk>,
externalRuntimeScript: null | any,
bootstrapChunks: Array<Chunk | PrecomputedChunk>,
onHeaders: void | ((headers: HeadersDescriptor) => void),
headers: null | {
preconnects: string,
fontPreloads: string,
highImagePreloads: string,
remainingCapacity: number,
},
charsetChunks: Array<Chunk | PrecomputedChunk>,
preconnectChunks: Array<Chunk | PrecomputedChunk>,
importMapChunks: Array<Chunk | PrecomputedChunk>,
Expand Down Expand Up @@ -83,6 +91,7 @@ export function createRenderState(
undefined,
undefined,
undefined,
undefined,
);
return {
// Keep this in sync with ReactFizzConfigDOM
Expand All @@ -94,6 +103,8 @@ export function createRenderState(
headChunks: renderState.headChunks,
externalRuntimeScript: renderState.externalRuntimeScript,
bootstrapChunks: renderState.bootstrapChunks,
onHeaders: renderState.onHeaders,
headers: renderState.headers,
charsetChunks: renderState.charsetChunks,
preconnectChunks: renderState.preconnectChunks,
importMapChunks: renderState.importMapChunks,
Expand Down
4 changes: 3 additions & 1 deletion packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Options = {
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
onHeaders?: (headers: Headers) => void,
headersLengthHint?: number,
};

type ResumeOptions = {
Expand Down Expand Up @@ -125,6 +126,8 @@ function renderToReadableStream(
options ? options.bootstrapModules : undefined,
options ? options.unstable_externalRuntimeSrc : undefined,
options ? options.importMap : undefined,
onHeadersImpl,
options ? options.headersLengthHint : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -135,7 +138,6 @@ function renderToReadableStream(
onFatalError,
options ? options.onPostpone : undefined,
options ? options.formState : undefined,
onHeadersImpl,
);
if (options && options.signal) {
const signal = options.signal;
Expand Down
4 changes: 3 additions & 1 deletion packages/react-dom/src/server/ReactDOMFizzServerBun.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Options = {
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
onHeaders?: (headers: Headers) => void,
headersLengthHint?: number,
};

// TODO: Move to sub-classing ReadableStream.
Expand Down Expand Up @@ -113,6 +114,8 @@ function renderToReadableStream(
options ? options.bootstrapModules : undefined,
options ? options.unstable_externalRuntimeSrc : undefined,
options ? options.importMap : undefined,
onHeadersImpl,
options ? options.headersLengthHint : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -123,7 +126,6 @@ function renderToReadableStream(
onFatalError,
options ? options.onPostpone : undefined,
options ? options.formState : undefined,
onHeadersImpl,
);
if (options && options.signal) {
const signal = options.signal;
Expand Down
4 changes: 3 additions & 1 deletion packages/react-dom/src/server/ReactDOMFizzServerEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Options = {
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
onHeaders?: (headers: Headers) => void,
headersLengthHint?: number,
};

type ResumeOptions = {
Expand Down Expand Up @@ -125,6 +126,8 @@ function renderToReadableStream(
options ? options.bootstrapModules : undefined,
options ? options.unstable_externalRuntimeSrc : undefined,
options ? options.importMap : undefined,
onHeadersImpl,
options ? options.headersLengthHint : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -135,7 +138,6 @@ function renderToReadableStream(
onFatalError,
options ? options.onPostpone : undefined,
options ? options.formState : undefined,
onHeadersImpl,
);
if (options && options.signal) {
const signal = options.signal;
Expand Down
15 changes: 8 additions & 7 deletions packages/react-dom/src/server/ReactDOMFizzServerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
* @flow
*/

import type {
Request,
PostponedState,
HeadersDescriptor,
} from 'react-server/src/ReactFizzServer';
import type {Request, PostponedState} from 'react-server/src/ReactFizzServer';
import type {ReactNodeList, ReactFormState} from 'shared/ReactTypes';
import type {Writable} from 'stream';
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
import type {
BootstrapScriptDescriptor,
HeadersDescriptor,
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
import type {Destination} from 'react-server/src/ReactServerStreamConfigNode';
import type {ImportMap} from '../shared/ReactDOMTypes';

Expand Down Expand Up @@ -65,6 +64,7 @@ type Options = {
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
onHeaders?: (headers: HeadersDescriptor) => void,
headersLengthHint?: number,
};

type ResumeOptions = {
Expand Down Expand Up @@ -99,6 +99,8 @@ function createRequestImpl(children: ReactNodeList, options: void | Options) {
options ? options.bootstrapModules : undefined,
options ? options.unstable_externalRuntimeSrc : undefined,
options ? options.importMap : undefined,
options ? options.onHeaders : undefined,
options ? options.headersLengthHint : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -109,7 +111,6 @@ function createRequestImpl(children: ReactNodeList, options: void | Options) {
undefined,
options ? options.onPostpone : undefined,
options ? options.formState : undefined,
options ? options.onHeaders : undefined,
);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/react-dom/src/server/ReactDOMFizzStaticBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Options = {
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
onHeaders?: (headers: Headers) => void,
headersLengthHint?: number,
};

type StaticResult = {
Expand Down Expand Up @@ -105,6 +106,8 @@ function prerender(
options ? options.bootstrapModules : undefined,
options ? options.unstable_externalRuntimeSrc : undefined,
options ? options.importMap : undefined,
onHeadersImpl,
options ? options.headersLengthHint : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -114,7 +117,6 @@ function prerender(
undefined,
onFatalError,
options ? options.onPostpone : undefined,
onHeadersImpl,
);
if (options && options.signal) {
const signal = options.signal;
Expand Down
4 changes: 3 additions & 1 deletion packages/react-dom/src/server/ReactDOMFizzStaticEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Options = {
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
onHeaders?: (headers: Headers) => void,
headersLengthHint?: number,
};

type StaticResult = {
Expand Down Expand Up @@ -104,6 +105,8 @@ function prerender(
options ? options.bootstrapModules : undefined,
options ? options.unstable_externalRuntimeSrc : undefined,
options ? options.importMap : undefined,
onHeadersImpl,
options ? options.headersLengthHint : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -113,7 +116,6 @@ function prerender(
undefined,
onFatalError,
options ? options.onPostpone : undefined,
onHeadersImpl,
);
if (options && options.signal) {
const signal = options.signal;
Expand Down
10 changes: 6 additions & 4 deletions packages/react-dom/src/server/ReactDOMFizzStaticNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
*/

import type {ReactNodeList} from 'shared/ReactTypes';
import type {BootstrapScriptDescriptor} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
import type {
PostponedState,
BootstrapScriptDescriptor,
HeadersDescriptor,
} from 'react-server/src/ReactFizzServer';
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
import type {PostponedState} from 'react-server/src/ReactFizzServer';
import type {ImportMap} from '../shared/ReactDOMTypes';

import {Writable, Readable} from 'stream';
Expand Down Expand Up @@ -46,6 +46,7 @@ type Options = {
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
onHeaders?: (headers: HeadersDescriptor) => void,
headersLengthHint?: number,
};

type StaticResult = {
Expand Down Expand Up @@ -105,6 +106,8 @@ function prerenderToNodeStream(
options ? options.bootstrapModules : undefined,
options ? options.unstable_externalRuntimeSrc : undefined,
options ? options.importMap : undefined,
options ? options.onHeaders : undefined,
options ? options.headersLengthHint : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -114,7 +117,6 @@ function prerenderToNodeStream(
undefined,
onFatalError,
options ? options.onPostpone : undefined,
options ? options.onHeaders : undefined,
);
if (options && options.signal) {
const signal = options.signal;
Expand Down
10 changes: 5 additions & 5 deletions packages/react-dom/src/shared/ReactDOMTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type PreloadOptions = {
integrity?: string,
type?: string,
nonce?: string,
fetchPriority?: 'high' | 'low' | 'auto',
fetchPriority?: FetchPriorityEnum,
imageSrcSet?: string,
imageSizes?: string,
referrerPolicy?: string,
Expand All @@ -34,7 +34,7 @@ export type PreinitOptions = {
crossOrigin?: string,
integrity?: string,
nonce?: string,
fetchPriority?: 'high' | 'low' | 'auto',
fetchPriority?: FetchPriorityEnum,
};
export type PreinitModuleOptions = {
as?: string,
Expand All @@ -51,7 +51,7 @@ export type PreloadImplOptions = {
integrity?: ?string,
nonce?: ?string,
type?: ?string,
fetchPriority?: ?FetchPriorityEnum,
fetchPriority?: ?string,
referrerPolicy?: ?string,
imageSrcSet?: ?string,
imageSizes?: ?string,
Expand All @@ -65,12 +65,12 @@ export type PreloadModuleImplOptions = {
export type PreinitStyleOptions = {
crossOrigin?: ?CrossOriginEnum,
integrity?: ?string,
fetchPriority?: ?FetchPriorityEnum,
fetchPriority?: ?string,
};
export type PreinitScriptOptions = {
crossOrigin?: ?CrossOriginEnum,
integrity?: ?string,
fetchPriority?: ?FetchPriorityEnum,
fetchPriority?: ?string,
nonce?: ?string,
};
export type PreinitModuleScriptOptions = {
Expand Down
Loading

0 comments on commit c8dcce2

Please sign in to comment.