diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
index cca05ad88724..c06c506f9680 100644
--- a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
@@ -1106,7 +1106,13 @@ describe('ReactDOMFizzServer', () => {
expect(Scheduler).toFlushAndYield([]);
expectErrors(
errors,
- [['This Suspense boundary was aborted by the server.', expectedDigest]],
+ [
+ [
+ 'The server did not finish this Suspense boundary: signal is aborted without reason',
+ expectedDigest,
+ componentStack(['h1', 'Suspense', 'div', 'App']),
+ ],
+ ],
[
[
'The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.',
@@ -3057,6 +3063,178 @@ describe('ReactDOMFizzServer', () => {
);
});
+ // @gate experimental
+ it('Supports custom abort reasons with a string', async () => {
+ function App() {
+ return (
+
',
+ {
+ runScripts: 'dangerously',
+ },
+ );
+ document = jsdom.window.document;
+ container = document.getElementById('container');
+ });
+
+ it('refers users to apis that support Suspense when somethign suspends', () => {
+ function App({isClient}) {
+ return (
+
+
+ {isClient ? 'resolved' : }
+
+
+ );
+ }
+ container.innerHTML = ReactDOMFizzServer.renderToString(
+
,
+ );
+
+ const errors = [];
+ ReactDOMClient.hydrateRoot(container,
, {
+ onRecoverableError(error, errorInfo) {
+ errors.push(error.message);
+ },
+ });
+
+ expect(Scheduler).toFlushAndYield([]);
+ expect(errors.length).toBe(1);
+ if (__DEV__) {
+ expect(errors[0]).toBe(
+ 'The server did not finish this Suspense boundary: The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToReadableStream" which supports Suspense on the server',
+ );
+ } else {
+ expect(errors[0]).toBe(
+ 'The server could not finish this Suspense boundary, likely due to ' +
+ 'an error during server rendering. Switched to client rendering.',
+ );
+ }
+ });
});
});
diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js
index a625a8df0e2f..96dd22c4bafc 100644
--- a/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js
@@ -226,7 +226,7 @@ describe('ReactDOMFizzServer', () => {
expect(output.result).toBe('');
expect(reportedErrors).toEqual([
theError.message,
- 'This Suspense boundary was aborted by the server.',
+ 'The destination stream errored while writing data.',
]);
expect(reportedShellErrors).toEqual([theError]);
});
@@ -317,13 +317,11 @@ describe('ReactDOMFizzServer', () => {
expect(output.result).toContain('Loading');
expect(isCompleteCalls).toBe(0);
- abort();
+ abort(new Error('uh oh'));
await completed;
- expect(errors).toEqual([
- 'This Suspense boundary was aborted by the server.',
- ]);
+ expect(errors).toEqual(['uh oh']);
expect(output.error).toBe(undefined);
expect(output.result).toContain('Loading');
expect(isCompleteCalls).toBe(1);
@@ -365,8 +363,8 @@ describe('ReactDOMFizzServer', () => {
expect(errors).toEqual([
// There are two boundaries that abort
- 'This Suspense boundary was aborted by the server.',
- 'This Suspense boundary was aborted by the server.',
+ 'signal is aborted without reason',
+ 'signal is aborted without reason',
]);
expect(output.error).toBe(undefined);
expect(output.result).toContain('Loading');
@@ -603,7 +601,7 @@ describe('ReactDOMFizzServer', () => {
await completed;
expect(errors).toEqual([
- 'This Suspense boundary was aborted by the server.',
+ 'The destination stream errored while writing data.',
]);
expect(rendered).toBe(false);
expect(isComplete).toBe(true);
diff --git a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js
index f2ddab69cdd0..e8e7dffee5d6 100644
--- a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js
@@ -830,7 +830,7 @@ describe('ReactDOMServerHydration', () => {
} else {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
- "Caught [This Suspense boundary was aborted by the server.]",
+ "Caught [The server did not finish this Suspense boundary: The server used \\"renderToString\\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \\"renderToPipeableStream\\" which supports Suspense on the server]",
]
`);
}
@@ -865,7 +865,7 @@ describe('ReactDOMServerHydration', () => {
} else {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
- "Caught [This Suspense boundary was aborted by the server.]",
+ "Caught [The server did not finish this Suspense boundary: The server used \\"renderToString\\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \\"renderToPipeableStream\\" which supports Suspense on the server]",
]
`);
}
diff --git a/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
index c27eabe3e97d..e086448d6914 100644
--- a/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
+++ b/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
@@ -1674,11 +1674,17 @@ describe('ReactDOMServerPartialHydration', () => {
// we exclude fb bundles with partial renderer
if (__DEV__ && !usingPartialRenderer) {
expect(Scheduler).toFlushAndYield([
- 'This Suspense boundary was aborted by the server.',
+ 'The server did not finish this Suspense boundary: The server used' +
+ ' "renderToString" which does not support Suspense. If you intended' +
+ ' for this Suspense boundary to render the fallback content on the' +
+ ' server consider throwing an Error somewhere within the Suspense boundary.' +
+ ' If you intended to have the server wait for the suspended component' +
+ ' please switch to "renderToPipeableStream" which supports Suspense on the server',
]);
} else {
expect(Scheduler).toFlushAndYield([
- 'The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.',
+ 'The server could not finish this Suspense boundary, likely due to ' +
+ 'an error during server rendering. Switched to client rendering.',
]);
}
jest.runAllTimers();
@@ -1742,11 +1748,17 @@ describe('ReactDOMServerPartialHydration', () => {
// we exclude fb bundles with partial renderer
if (__DEV__ && !usingPartialRenderer) {
expect(Scheduler).toFlushAndYield([
- 'This Suspense boundary was aborted by the server.',
+ 'The server did not finish this Suspense boundary: The server used' +
+ ' "renderToString" which does not support Suspense. If you intended' +
+ ' for this Suspense boundary to render the fallback content on the' +
+ ' server consider throwing an Error somewhere within the Suspense boundary.' +
+ ' If you intended to have the server wait for the suspended component' +
+ ' please switch to "renderToPipeableStream" which supports Suspense on the server',
]);
} else {
expect(Scheduler).toFlushAndYield([
- 'The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.',
+ 'The server could not finish this Suspense boundary, likely due to ' +
+ 'an error during server rendering. Switched to client rendering.',
]);
}
// This will have exceeded the suspended time so we should timeout.
@@ -1815,11 +1827,17 @@ describe('ReactDOMServerPartialHydration', () => {
// we exclude fb bundles with partial renderer
if (__DEV__ && !usingPartialRenderer) {
expect(Scheduler).toFlushAndYield([
- 'This Suspense boundary was aborted by the server.',
+ 'The server did not finish this Suspense boundary: The server used' +
+ ' "renderToString" which does not support Suspense. If you intended' +
+ ' for this Suspense boundary to render the fallback content on the' +
+ ' server consider throwing an Error somewhere within the Suspense boundary.' +
+ ' If you intended to have the server wait for the suspended component' +
+ ' please switch to "renderToPipeableStream" which supports Suspense on the server',
]);
} else {
expect(Scheduler).toFlushAndYield([
- 'The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.',
+ 'The server could not finish this Suspense boundary, likely due to ' +
+ 'an error during server rendering. Switched to client rendering.',
]);
}
// This will have exceeded the suspended time so we should timeout.
@@ -2139,11 +2157,17 @@ describe('ReactDOMServerPartialHydration', () => {
// we exclude fb bundles with partial renderer
if (__DEV__ && !usingPartialRenderer) {
expect(Scheduler).toFlushAndYield([
- 'This Suspense boundary was aborted by the server.',
+ 'The server did not finish this Suspense boundary: The server used' +
+ ' "renderToString" which does not support Suspense. If you intended' +
+ ' for this Suspense boundary to render the fallback content on the' +
+ ' server consider throwing an Error somewhere within the Suspense boundary.' +
+ ' If you intended to have the server wait for the suspended component' +
+ ' please switch to "renderToPipeableStream" which supports Suspense on the server',
]);
} else {
expect(Scheduler).toFlushAndYield([
- 'The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.',
+ 'The server could not finish this Suspense boundary, likely due to ' +
+ 'an error during server rendering. Switched to client rendering.',
]);
}
@@ -2208,11 +2232,17 @@ describe('ReactDOMServerPartialHydration', () => {
// we exclude fb bundles with partial renderer
if (__DEV__ && !usingPartialRenderer) {
expect(Scheduler).toFlushAndYield([
- 'This Suspense boundary was aborted by the server.',
+ 'The server did not finish this Suspense boundary: The server used' +
+ ' "renderToString" which does not support Suspense. If you intended' +
+ ' for this Suspense boundary to render the fallback content on the' +
+ ' server consider throwing an Error somewhere within the Suspense boundary.' +
+ ' If you intended to have the server wait for the suspended component' +
+ ' please switch to "renderToPipeableStream" which supports Suspense on the server',
]);
} else {
expect(Scheduler).toFlushAndYield([
- 'The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.',
+ 'The server could not finish this Suspense boundary, likely due to ' +
+ 'an error during server rendering. Switched to client rendering.',
]);
}
jest.runAllTimers();
diff --git a/packages/react-dom/src/__tests__/ReactServerRendering-test.js b/packages/react-dom/src/__tests__/ReactServerRendering-test.js
index 23be43a7735a..c22846fa637f 100644
--- a/packages/react-dom/src/__tests__/ReactServerRendering-test.js
+++ b/packages/react-dom/src/__tests__/ReactServerRendering-test.js
@@ -562,6 +562,19 @@ describe('ReactDOMServer', () => {
'Bad lazy',
);
});
+
+ it('aborts synchronously any suspended tasks and renders their fallbacks', () => {
+ const promise = new Promise(res => {});
+ function Suspender() {
+ throw promise;
+ }
+ const response = ReactDOMServer.renderToStaticMarkup(
+
+
+ ,
+ );
+ expect(response).toEqual('fallback');
+ });
});
describe('renderToNodeStream', () => {
@@ -618,6 +631,41 @@ describe('ReactDOMServer', () => {
expect(response.read()).toBeNull();
});
});
+
+ it('should refer users to new apis when using suspense', async () => {
+ let resolve = null;
+ const promise = new Promise(res => {
+ resolve = () => {
+ resolved = true;
+ res();
+ };
+ });
+ let resolved = false;
+ function Suspender() {
+ if (resolved) {
+ return 'resolved';
+ }
+ throw promise;
+ }
+
+ let response;
+ expect(() => {
+ response = ReactDOMServer.renderToNodeStream(
+
+
+
+
+
,
+ );
+ }).toErrorDev(
+ 'renderToNodeStream is deprecated. Use renderToPipeableStream instead.',
+ {withoutStack: true},
+ );
+ await resolve();
+ expect(response.read().toString()).toEqual(
+ '
resolved
',
+ );
+ });
});
it('warns with a no-op when an async setState is triggered', () => {
diff --git a/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js b/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
index 35fbf0e6023c..fc35fdb28679 100644
--- a/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
+++ b/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
@@ -97,7 +97,7 @@ function renderToReadableStream(
if (options && options.signal) {
const signal = options.signal;
const listener = () => {
- abort(request);
+ abort(request, (signal: any).reason);
signal.removeEventListener('abort', listener);
};
signal.addEventListener('abort', listener);
diff --git a/packages/react-dom/src/server/ReactDOMFizzServerNode.js b/packages/react-dom/src/server/ReactDOMFizzServerNode.js
index c5318c2024aa..ce2b2e503086 100644
--- a/packages/react-dom/src/server/ReactDOMFizzServerNode.js
+++ b/packages/react-dom/src/server/ReactDOMFizzServerNode.js
@@ -28,8 +28,8 @@ function createDrainHandler(destination, request) {
return () => startFlowing(request, destination);
}
-function createAbortHandler(request) {
- return () => abort(request);
+function createAbortHandler(request, reason) {
+ return () => abort(request, reason);
}
type Options = {|
@@ -90,11 +90,26 @@ function renderToPipeableStream(
hasStartedFlowing = true;
startFlowing(request, destination);
destination.on('drain', createDrainHandler(destination, request));
- destination.on('close', createAbortHandler(request));
+ destination.on(
+ 'error',
+ createAbortHandler(
+ request,
+ // eslint-disable-next-line react-internal/prod-error-codes
+ new Error('The destination stream errored while writing data.'),
+ ),
+ );
+ destination.on(
+ 'close',
+ createAbortHandler(
+ request,
+ // eslint-disable-next-line react-internal/prod-error-codes
+ new Error('The destination stream closed early.'),
+ ),
+ );
return destination;
},
- abort() {
- abort(request);
+ abort(reason) {
+ abort(request, reason);
},
};
}
diff --git a/packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js b/packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js
index 168f38fc59db..71786e4b5078 100644
--- a/packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js
+++ b/packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js
@@ -7,104 +7,36 @@
* @flow
*/
-import ReactVersion from 'shared/ReactVersion';
-
import type {ReactNodeList} from 'shared/ReactTypes';
-import {
- createRequest,
- startWork,
- startFlowing,
- abort,
-} from 'react-server/src/ReactFizzServer';
-
-import {
- createResponseState,
- createRootFormatContext,
-} from './ReactDOMServerLegacyFormatConfig';
+import {version, renderToStringImpl} from './ReactDOMLegacyServerImpl';
type ServerOptions = {
identifierPrefix?: string,
};
-function onError() {
- // Non-fatal errors are ignored.
-}
-
-function renderToStringImpl(
- children: ReactNodeList,
- options: void | ServerOptions,
- generateStaticMarkup: boolean,
-): string {
- let didFatal = false;
- let fatalError = null;
- let result = '';
- const destination = {
- push(chunk) {
- if (chunk !== null) {
- result += chunk;
- }
- return true;
- },
- destroy(error) {
- didFatal = true;
- fatalError = error;
- },
- };
-
- let readyToStream = false;
- function onShellReady() {
- readyToStream = true;
- }
- const request = createRequest(
- children,
- createResponseState(
- generateStaticMarkup,
- options ? options.identifierPrefix : undefined,
- ),
- createRootFormatContext(),
- Infinity,
- onError,
- undefined,
- onShellReady,
- undefined,
- undefined,
- );
- startWork(request);
- // If anything suspended and is still pending, we'll abort it before writing.
- // That way we write only client-rendered boundaries from the start.
- abort(request);
- startFlowing(request, destination);
- if (didFatal) {
- throw fatalError;
- }
-
- if (!readyToStream) {
- // Note: This error message is the one we use on the client. It doesn't
- // really make sense here. But this is the legacy server renderer, anyway.
- // We're going to delete it soon.
- throw new Error(
- 'A component suspended while responding to synchronous input. This ' +
- 'will cause the UI to be replaced with a loading indicator. To fix, ' +
- 'updates that suspend should be wrapped with startTransition.',
- );
- }
-
- return result;
-}
-
function renderToString(
children: ReactNodeList,
options?: ServerOptions,
): string {
- return renderToStringImpl(children, options, false);
+ return renderToStringImpl(
+ children,
+ options,
+ false,
+ 'The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToReadableStream" which supports Suspense on the server',
+ );
}
function renderToStaticMarkup(
children: ReactNodeList,
options?: ServerOptions,
): string {
- return renderToStringImpl(children, options, true);
+ return renderToStringImpl(
+ children,
+ options,
+ true,
+ 'The server used "renderToStaticMarkup" which does not support Suspense. If you intended to have the server wait for the suspended component please switch to "renderToReadableStream" which supports Suspense on the server',
+ );
}
function renderToNodeStream() {
@@ -126,5 +58,5 @@ export {
renderToStaticMarkup,
renderToNodeStream,
renderToStaticNodeStream,
- ReactVersion as version,
+ version,
};
diff --git a/packages/react-dom/src/server/ReactDOMLegacyServerImpl.js b/packages/react-dom/src/server/ReactDOMLegacyServerImpl.js
new file mode 100644
index 000000000000..27e41b42e43a
--- /dev/null
+++ b/packages/react-dom/src/server/ReactDOMLegacyServerImpl.js
@@ -0,0 +1,97 @@
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ *
+ * @flow
+ */
+
+import ReactVersion from 'shared/ReactVersion';
+
+import type {ReactNodeList} from 'shared/ReactTypes';
+
+import {
+ createRequest,
+ startWork,
+ startFlowing,
+ abort,
+} from 'react-server/src/ReactFizzServer';
+
+import {
+ createResponseState,
+ createRootFormatContext,
+} from './ReactDOMServerLegacyFormatConfig';
+
+type ServerOptions = {
+ identifierPrefix?: string,
+};
+
+function onError() {
+ // Non-fatal errors are ignored.
+}
+
+function renderToStringImpl(
+ children: ReactNodeList,
+ options: void | ServerOptions,
+ generateStaticMarkup: boolean,
+ abortReason: string,
+): string {
+ let didFatal = false;
+ let fatalError = null;
+ let result = '';
+ const destination = {
+ push(chunk) {
+ if (chunk !== null) {
+ result += chunk;
+ }
+ return true;
+ },
+ destroy(error) {
+ didFatal = true;
+ fatalError = error;
+ },
+ };
+
+ let readyToStream = false;
+ function onShellReady() {
+ readyToStream = true;
+ }
+ const request = createRequest(
+ children,
+ createResponseState(
+ generateStaticMarkup,
+ options ? options.identifierPrefix : undefined,
+ ),
+ createRootFormatContext(),
+ Infinity,
+ onError,
+ undefined,
+ onShellReady,
+ undefined,
+ undefined,
+ );
+ startWork(request);
+ // If anything suspended and is still pending, we'll abort it before writing.
+ // That way we write only client-rendered boundaries from the start.
+ abort(request, abortReason);
+ startFlowing(request, destination);
+ if (didFatal) {
+ throw fatalError;
+ }
+
+ if (!readyToStream) {
+ // Note: This error message is the one we use on the client. It doesn't
+ // really make sense here. But this is the legacy server renderer, anyway.
+ // We're going to delete it soon.
+ throw new Error(
+ 'A component suspended while responding to synchronous input. This ' +
+ 'will cause the UI to be replaced with a loading indicator. To fix, ' +
+ 'updates that suspend should be wrapped with startTransition.',
+ );
+ }
+
+ return result;
+}
+
+export {renderToStringImpl, ReactVersion as version};
diff --git a/packages/react-dom/src/server/ReactDOMLegacyServerNode.js b/packages/react-dom/src/server/ReactDOMLegacyServerNode.js
index f5c6aa1f4600..26777fdc452c 100644
--- a/packages/react-dom/src/server/ReactDOMLegacyServerNode.js
+++ b/packages/react-dom/src/server/ReactDOMLegacyServerNode.js
@@ -23,11 +23,7 @@ import {
createRootFormatContext,
} from './ReactDOMServerLegacyFormatConfig';
-import {
- version,
- renderToString,
- renderToStaticMarkup,
-} from './ReactDOMLegacyServerBrowser';
+import {version, renderToStringImpl} from './ReactDOMLegacyServerImpl';
import {Readable} from 'stream';
@@ -109,6 +105,30 @@ function renderToStaticNodeStream(
return renderToNodeStreamImpl(children, options, true);
}
+function renderToString(
+ children: ReactNodeList,
+ options?: ServerOptions,
+): string {
+ return renderToStringImpl(
+ children,
+ options,
+ false,
+ 'The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToPipeableStream" which supports Suspense on the server',
+ );
+}
+
+function renderToStaticMarkup(
+ children: ReactNodeList,
+ options?: ServerOptions,
+): string {
+ return renderToStringImpl(
+ children,
+ options,
+ true,
+ 'The server used "renderToStaticMarkup" which does not support Suspense. If you intended to have the server wait for the suspended component please switch to "renderToPipeableStream" which supports Suspense on the server',
+ );
+}
+
export {
renderToString,
renderToStaticMarkup,
diff --git a/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js b/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js
index 857a374f3e81..652bf9a783be 100644
--- a/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js
+++ b/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js
@@ -191,8 +191,6 @@ describe('ReactDOMServerFB', () => {
const remaining = readResult(stream);
expect(remaining).toEqual('');
- expect(errors).toEqual([
- 'This Suspense boundary was aborted by the server.',
- ]);
+ expect(errors).toEqual(['signal is aborted without reason']);
});
});
diff --git a/packages/react-server/src/ReactFizzServer.js b/packages/react-server/src/ReactFizzServer.js
index 2b0a3d82e060..05ca9cd6c928 100644
--- a/packages/react-server/src/ReactFizzServer.js
+++ b/packages/react-server/src/ReactFizzServer.js
@@ -1530,10 +1530,9 @@ function abortTaskSoft(task: Task): void {
finishedTask(request, boundary, segment);
}
-function abortTask(task: Task): void {
+function abortTask(task: Task, request: Request, reason: mixed): void {
// This aborts the task and aborts the parent that it blocks, putting it into
// client rendered mode.
- const request: Request = this;
const boundary = task.blockedBoundary;
const segment = task.blockedSegment;
segment.status = ABORTED;
@@ -1553,12 +1552,28 @@ function abortTask(task: Task): void {
if (!boundary.forceClientRender) {
boundary.forceClientRender = true;
- const error = new Error(
- 'This Suspense boundary was aborted by the server.',
- );
+ let error =
+ reason === undefined
+ ? // eslint-disable-next-line react-internal/prod-error-codes
+ new Error('signal is aborted without reason')
+ : reason;
boundary.errorDigest = request.onError(error);
if (__DEV__) {
- captureBoundaryErrorDetailsDev(boundary, error);
+ const errorPrefix =
+ 'The server did not finish this Suspense boundary: ';
+ if (error && typeof error.message === 'string') {
+ error = errorPrefix + error.message;
+ } else {
+ // eslint-disable-next-line react-internal/safe-string-coercion
+ error = errorPrefix + String(error);
+ }
+ const previousTaskInDev = currentTaskInDEV;
+ currentTaskInDEV = task;
+ try {
+ captureBoundaryErrorDetailsDev(boundary, error);
+ } finally {
+ currentTaskInDEV = previousTaskInDev;
+ }
}
if (boundary.parentFlushed) {
request.clientRenderedBoundaries.push(boundary);
@@ -1567,7 +1582,9 @@ function abortTask(task: Task): void {
// If this boundary was still pending then we haven't already cancelled its fallbacks.
// We'll need to abort the fallbacks, which will also error that parent boundary.
- boundary.fallbackAbortableTasks.forEach(abortTask, request);
+ boundary.fallbackAbortableTasks.forEach(fallbackTask =>
+ abortTask(fallbackTask, request, reason),
+ );
boundary.fallbackAbortableTasks.clear();
request.allPendingTasks--;
@@ -2159,10 +2176,10 @@ export function startFlowing(request: Request, destination: Destination): void {
}
// This is called to early terminate a request. It puts all pending boundaries in client rendered state.
-export function abort(request: Request): void {
+export function abort(request: Request, reason: mixed): void {
try {
const abortableTasks = request.abortableTasks;
- abortableTasks.forEach(abortTask, request);
+ abortableTasks.forEach(task => abortTask(task, request, reason));
abortableTasks.clear();
if (request.destination !== null) {
flushCompletedQueues(request, request.destination);
diff --git a/scripts/error-codes/codes.json b/scripts/error-codes/codes.json
index 00748befe6d8..6c206f0cd6d1 100644
--- a/scripts/error-codes/codes.json
+++ b/scripts/error-codes/codes.json
@@ -419,5 +419,6 @@
"431": "React elements are not allowed in ServerContext",
"432": "This Suspense boundary was aborted by the server.",
"433": "useId can only be used while React is rendering",
- "434": "`dangerouslySetInnerHTML` does not make sense on
."
+ "434": "`dangerouslySetInnerHTML` does not make sense on .",
+ "435": "The server did not finish this Suspense boundary. The server used \"%s\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \"%s\" which supports Suspense on the server"
}
diff --git a/scripts/shared/inlinedHostConfigs.js b/scripts/shared/inlinedHostConfigs.js
index 4e47b4fd6ffc..3092f25391d0 100644
--- a/scripts/shared/inlinedHostConfigs.js
+++ b/scripts/shared/inlinedHostConfigs.js
@@ -69,6 +69,7 @@ module.exports = [
paths: [
'react-dom',
'react-server-dom-webpack',
+ 'react-dom/src/server/ReactDOMLegacyServerImpl.js', // not an entrypoint, but only usable in *Brower and *Node files
'react-dom/src/server/ReactDOMLegacyServerBrowser.js', // react-dom/server.browser
'react-dom/src/server/ReactDOMLegacyServerNode.js', // react-dom/server.node
'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.