Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -432,16 +432,25 @@ describe('ReactDOMFizzServer', () => {
}

const serverErrors = [];
const browserBailouts = [];
await act(() => {
const {pipe} = renderToPipeableStream(<App />, {
onError(error) {
serverErrors.push(error);
},
onBrowserBailout(error, errorInfo) {
browserBailouts.push({error, errorInfo});
},
});
pipe(writable);
});

expect(serverErrors).toEqual([]);
expect(browserBailouts).toHaveLength(1);
expect(browserBailouts[0].error).toBe(browserOnly);
expect(
normalizeCodeLocInfo(browserBailouts[0].errorInfo.componentStack),
).toBe(componentStack(['BrowserOnly', 'Suspense', 'div', 'App']));
expect(getVisibleChildren(container)).toEqual(
<div>
<span>Fallback</span>
Expand DownExpand Up@@ -548,13 +557,17 @@ describe('ReactDOMFizzServer', () => {
}

const reportedErrors = [];
const browserBailouts = [];
let shellReady = false;
let shellError;
await act(() => {
renderToPipeableStream(<BrowserOnly />, {
onError(error) {
reportedErrors.push(error);
},
onBrowserBailout(error) {
browserBailouts.push(error);
},
onShellReady() {
shellReady = true;
},
Expand All@@ -573,11 +586,9 @@ describe('ReactDOMFizzServer', () => {
expect(shellError.stack).toContain('BrowserOnly');
expect(shellError.cause).toBe(browserValue);
expect(shellError.cause.stack).toContain('createBrowserValue');
expect(shellError.cause.message).toContain(
'`use(browser())` can only be used inside a `<Suspense>` boundary',
);
expect(shellReady).toBe(false);
expect(reportedErrors).toEqual([shellError]);
expect(browserBailouts).toEqual([]);
});

// @gate enableBrowserAPI
Expand DownExpand Up@@ -607,12 +618,17 @@ describe('ReactDOMFizzServer', () => {
}

const serverErrors = [];
const browserBailouts = [];
const browserValue = ReactDOM.browser();
let abort;
await act(() => {
const controls = renderToPipeableStream(<App />, {
onError(error) {
serverErrors.push(error);
},
onBrowserBailout(error) {
browserBailouts.push(error);
},
});
abort = controls.abort;
controls.pipe(writable);
Expand All@@ -627,10 +643,11 @@ describe('ReactDOMFizzServer', () => {
);

await act(() => {
abort(ReactDOM.browser());
abort(browserValue);
});

expect(serverErrors).toEqual([]);
expect(browserBailouts).toEqual([browserValue, browserValue]);

isClient = true;
const recoverableErrors = [];
Expand DownExpand Up@@ -662,6 +679,7 @@ describe('ReactDOMFizzServer', () => {
}

const reportedErrors = [];
const browserBailouts = [];
let shellReady = false;
let shellError;
let abort;
Expand All@@ -670,6 +688,9 @@ describe('ReactDOMFizzServer', () => {
onError(error) {
reportedErrors.push(error);
},
onBrowserBailout(error) {
browserBailouts.push(error);
},
onShellReady() {
shellReady = true;
},
Expand All@@ -693,6 +714,7 @@ describe('ReactDOMFizzServer', () => {
expect(shellError.cause).toBe(browserValue);
expect(shellReady).toBe(false);
expect(reportedErrors).toEqual([shellError]);
expect(browserBailouts).toEqual([]);
});

// @gate enableBrowserAPI
Expand All@@ -704,6 +726,7 @@ describe('ReactDOMFizzServer', () => {
}

const reportedErrors = [];
const browserBailouts = [];
await act(() => {
const {pipe} = renderToPipeableStream(
<Suspense fallback={<span>Fallback</span>}>
Expand All@@ -713,12 +736,16 @@ describe('ReactDOMFizzServer', () => {
onError(error) {
reportedErrors.push(error);
},
onBrowserBailout(error) {
browserBailouts.push(error);
},
},
);
pipe(writable);
});

expect(reportedErrors).toEqual([browserValue]);
expect(browserBailouts).toEqual([]);
expect(getVisibleChildren(container)).toEqual(<span>Fallback</span>);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,6 +53,7 @@ type Options = {
progressiveChunkSize?: number,
signal?: AbortSignal,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
Expand All@@ -64,6 +65,7 @@ type ResumeOptions = {
nonce?: NonceOption,
signal?: AbortSignal,
onError?: (error: mixed) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
};

Expand DownExpand Up@@ -141,6 +143,7 @@ function renderToReadableStream(
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
onShellReady,
onShellError,
Expand DownExpand Up@@ -211,6 +214,7 @@ function resume(
options ? options.nonce : undefined,
),
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
onShellReady,
onShellError,
Expand Down
2 changes: 2 additions & 0 deletions packages/react-dom/src/server/ReactDOMFizzServerBun.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,6 +49,7 @@ type Options = {
progressiveChunkSize?: number,
signal?: AbortSignal,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
Expand DownExpand Up@@ -131,6 +132,7 @@ function renderToReadableStream(
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
onShellReady,
onShellError,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-dom/src/server/ReactDOMFizzServerEdge.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,6 +53,7 @@ type Options = {
progressiveChunkSize?: number,
signal?: AbortSignal,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
Expand All@@ -64,6 +65,7 @@ type ResumeOptions = {
nonce?: NonceOption,
signal?: AbortSignal,
onError?: (error: mixed) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
};

Expand DownExpand Up@@ -141,6 +143,7 @@ function renderToReadableStream(
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
onShellReady,
onShellError,
Expand DownExpand Up@@ -211,6 +214,7 @@ function resume(
options ? options.nonce : undefined,
),
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
onShellReady,
onShellError,
Expand Down
6 changes: 6 additions & 0 deletions packages/react-dom/src/server/ReactDOMFizzServerNode.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,6 +76,7 @@ type Options = {
onShellError?: (error: mixed) => void,
onAllReady?: () => void,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
formState?: ReactFormState<any, any> | null,
Expand All@@ -89,6 +90,7 @@ type ResumeOptions = {
onShellError?: (error: mixed) => void,
onAllReady?: () => void,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
};

type PipeableStream = {
Expand DownExpand Up@@ -120,6 +122,7 @@ function createRequestImpl(children: ReactNodeList, options: void | Options) {
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
options ? options.onAllReady : undefined,
options ? options.onShellReady : undefined,
options ? options.onShellError : undefined,
Expand DownExpand Up@@ -278,6 +281,7 @@ function renderToReadableStream(
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
onShellReady,
onShellError,
Expand DownExpand Up@@ -313,6 +317,7 @@ function resumeRequestImpl(
options ? options.nonce : undefined,
),
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
options ? options.onAllReady : undefined,
options ? options.onShellReady : undefined,
options ? options.onShellError : undefined,
Expand DownExpand Up@@ -415,6 +420,7 @@ function resume(
options ? options.nonce : undefined,
),
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
onShellReady,
onShellError,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-dom/src/server/ReactDOMFizzStaticBrowser.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,6 +53,7 @@ type Options = {
progressiveChunkSize?: number,
signal?: AbortSignal,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
onHeaders?: (headers: Headers) => void,
Expand DownExpand Up@@ -124,6 +125,7 @@ function prerender(
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
undefined,
undefined,
Expand All@@ -149,6 +151,7 @@ type ResumeOptions = {
nonce?: NonceOption,
signal?: AbortSignal,
onError?: (error: mixed) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
};

Expand DownExpand Up@@ -189,6 +192,7 @@ function resumeAndPrerender(
postponedState,
resumeRenderState(postponedState.resumableState, undefined),
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
undefined,
undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-dom/src/server/ReactDOMFizzStaticEdge.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,6 +53,7 @@ type Options = {
progressiveChunkSize?: number,
signal?: AbortSignal,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
onHeaders?: (headers: Headers) => void,
Expand DownExpand Up@@ -123,6 +124,7 @@ function prerender(
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
undefined,
undefined,
Expand All@@ -148,6 +150,7 @@ type ResumeOptions = {
nonce?: NonceOption,
signal?: AbortSignal,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
};

function resumeAndPrerender(
Expand DownExpand Up@@ -187,6 +190,7 @@ function resumeAndPrerender(
postponedState,
resumeRenderState(postponedState.resumableState, undefined),
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
undefined,
undefined,
Expand Down
6 changes: 6 additions & 0 deletions packages/react-dom/src/server/ReactDOMFizzStaticNode.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,6 +57,7 @@ type Options = {
progressiveChunkSize?: number,
signal?: AbortSignal,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
unstable_externalRuntimeSrc?: string | BootstrapScriptDescriptor,
importMap?: ImportMap,
onHeaders?: (headers: HeadersDescriptor) => void,
Expand DownExpand Up@@ -155,6 +156,7 @@ function prerenderToNodeStream(
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
undefined,
undefined,
Expand DownExpand Up@@ -245,6 +247,7 @@ function prerender(
createRootFormatContext(options ? options.namespaceURI : undefined),
options ? options.progressiveChunkSize : undefined,
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
undefined,
undefined,
Expand All@@ -270,6 +273,7 @@ type ResumeOptions = {
nonce?: NonceOption,
signal?: AbortSignal,
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
onBrowserBailout?: (error: mixed, errorInfo: ErrorInfo) => void,
};

function resumeAndPrerenderToNodeStream(
Expand DownExpand Up@@ -299,6 +303,7 @@ function resumeAndPrerenderToNodeStream(
postponedState,
resumeRenderState(postponedState.resumableState, undefined),
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
undefined,
undefined,
Expand DownExpand Up@@ -365,6 +370,7 @@ function resumeAndPrerender(
postponedState,
resumeRenderState(postponedState.resumableState, undefined),
options ? options.onError : undefined,
options ? options.onBrowserBailout : undefined,
onAllReady,
undefined,
undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/react-dom/src/server/ReactDOMLegacyServerImpl.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -72,6 +72,7 @@ function renderToStringImpl(
Infinity,
onError,
undefined,
undefined,
onShellReady,
undefined,
undefined,
Expand Down
Loading
Loading