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 7, 2023
1 parent 57ca924 commit 6523996
Show file tree
Hide file tree
Showing 15 changed files with 767 additions and 156 deletions.
662 changes: 573 additions & 89 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOMLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
*/

import type {
RenderState as BaseRenderState,
ResumableState,
BoundaryResources,
StyleQueue,
Resource,
HeadersDescriptor,
} from './ReactFizzConfigDOM';

import {
Expand Down Expand Up @@ -46,6 +48,14 @@ 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,
},
resets: BaseRenderState['resets'],
charsetChunks: Array<Chunk | PrecomputedChunk>,
preconnectChunks: Array<Chunk | PrecomputedChunk>,
importMapChunks: Array<Chunk | PrecomputedChunk>,
Expand Down Expand Up @@ -83,6 +93,7 @@ export function createRenderState(
undefined,
undefined,
undefined,
undefined,
);
return {
// Keep this in sync with ReactFizzConfigDOM
Expand All @@ -94,6 +105,9 @@ export function createRenderState(
headChunks: renderState.headChunks,
externalRuntimeScript: renderState.externalRuntimeScript,
bootstrapChunks: renderState.bootstrapChunks,
onHeaders: renderState.onHeaders,
headers: renderState.headers,
resets: renderState.resets,
charsetChunks: renderState.charsetChunks,
preconnectChunks: renderState.preconnectChunks,
importMapChunks: renderState.importMapChunks,
Expand Down Expand Up @@ -159,6 +173,7 @@ export {
setCurrentlyRenderingBoundaryResourcesTarget,
prepareHostDispatcher,
resetResumableState,
emitEarlyPreloads,
} from './ReactFizzConfigDOM';

import escapeTextForBrowser from './escapeTextForBrowser';
Expand Down
12 changes: 7 additions & 5 deletions packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* @flow
*/

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

import ReactVersion from 'shared/ReactVersion';
Expand Down Expand Up @@ -48,6 +48,7 @@ type Options = {
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
onHeaders?: (headers: Headers) => void,
maxHeadersLength?: 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.maxHeadersLength : 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
10 changes: 7 additions & 3 deletions packages/react-dom/src/server/ReactDOMFizzServerBun.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
* @flow
*/

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

import ReactVersion from 'shared/ReactVersion';
Expand Down Expand Up @@ -43,6 +45,7 @@ type Options = {
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
onHeaders?: (headers: Headers) => void,
maxHeadersLength?: number,
};

// TODO: Move to sub-classing ReadableStream.
Expand Down Expand Up @@ -113,6 +116,8 @@ function renderToReadableStream(
options ? options.bootstrapModules : undefined,
options ? options.unstable_externalRuntimeSrc : undefined,
options ? options.importMap : undefined,
onHeadersImpl,
options ? options.maxHeadersLength : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -123,7 +128,6 @@ function renderToReadableStream(
onFatalError,
options ? options.onPostpone : undefined,
options ? options.formState : undefined,
onHeadersImpl,
);
if (options && options.signal) {
const signal = options.signal;
Expand Down
13 changes: 7 additions & 6 deletions packages/react-dom/src/server/ReactDOMFizzServerEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* @flow
*/

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

import ReactVersion from 'shared/ReactVersion';
Expand Down Expand Up @@ -48,6 +48,7 @@ type Options = {
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
onHeaders?: (headers: Headers) => void,
maxHeadersLength?: 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.maxHeadersLength : 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 Expand Up @@ -204,7 +206,6 @@ function resume(
onShellReady,
onShellError,
onFatalError,
undefined,
options ? options.onPostpone : undefined,
);
if (options && options.signal) {
Expand Down
17 changes: 10 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 All @@ -27,6 +26,7 @@ import {
startFlowing,
stopFlowing,
abort,
prepareForStartFlowingIfBeforeAllReady,
} from 'react-server/src/ReactFizzServer';

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

type ResumeOptions = {
Expand Down Expand Up @@ -99,6 +100,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.maxHeadersLength : undefined,
),
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
Expand All @@ -109,7 +112,6 @@ function createRequestImpl(children: ReactNodeList, options: void | Options) {
undefined,
options ? options.onPostpone : undefined,
options ? options.formState : undefined,
options ? options.onHeaders : undefined,
);
}

Expand All @@ -128,6 +130,7 @@ function renderToPipeableStream(
);
}
hasStartedFlowing = true;
prepareForStartFlowingIfBeforeAllReady(request);
startFlowing(request, destination);
destination.on('drain', createDrainHandler(destination, request));
destination.on(
Expand Down
10 changes: 6 additions & 4 deletions packages/react-dom/src/server/ReactDOMFizzStaticBrowser.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 ReactVersion from 'shared/ReactVersion';
Expand Down Expand Up @@ -45,6 +45,7 @@ type Options = {
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
onHeaders?: (headers: Headers) => void,
maxHeadersLength?: 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.maxHeadersLength : 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
10 changes: 6 additions & 4 deletions packages/react-dom/src/server/ReactDOMFizzStaticEdge.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 ReactVersion from 'shared/ReactVersion';
Expand Down Expand Up @@ -45,6 +45,7 @@ type Options = {
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
onHeaders?: (headers: Headers) => void,
maxHeadersLength?: 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.maxHeadersLength : 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,
maxHeadersLength?: 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.maxHeadersLength : 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
Loading

0 comments on commit 6523996

Please sign in to comment.