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
54 changes: 51 additions & 3 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ describe('ReactDOMFizzServer', () => {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
ReactDOMFizzServer = require('react-dom/server');
if (__EXPERIMENTAL__) {
ReactDOMFizzStatic = require('react-dom/static');
}
ReactDOMFizzStatic = require('react-dom/static');
Stream = require('stream');
Suspense = React.Suspense;
use = React.use;
Expand Down Expand Up @@ -10784,4 +10782,54 @@ Unfortunately that previous paragraph wasn't quite long enough so I'll continue
// Instead we assert that we never emitted the fallback of the Suspense boundary around the body.
expect(streamedContent).not.toContain(randomTag);
});

it('should be able to Suspend after aborting in the same component without hanging the render', async () => {
const controller = new AbortController();

const promise1 = new Promise(() => {});
function AbortAndSuspend() {
controller.abort('boom');
return React.use(promise1);
}

function App() {
return (
<html>
<body>
<Suspense fallback="loading...">
{/*
The particular code path that was problematic required the Suspend to happen in renderNode
rather than retryRenderTask so we render the aborting function inside a host component
intentionally here
*/}
<div>
<AbortAndSuspend />
</div>
</Suspense>
</body>
</html>
);
}

const errors = [];
await act(async () => {
const result = await ReactDOMFizzStatic.prerenderToNodeStream(<App />, {
signal: controller.signal,
onError(e) {
errors.push(e);
},
});

result.prelude.pipe(writable);
});

expect(errors).toEqual(['boom']);

expect(getVisibleChildren(document)).toEqual(
<html>
<head />
<body>loading...</body>
</html>,
);
});
});
8 changes: 6 additions & 2 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4155,7 +4155,9 @@ function renderNode(
getSuspendedThenable()
: thrownValue;

if (typeof x === 'object' && x !== null) {
if (request.status === ABORTING) {
// We are aborting so we can just bubble up to the task by falling through
} else if (typeof x === 'object' && x !== null) {
// $FlowFixMe[method-unbinding]
if (typeof x.then === 'function') {
const wakeable: Wakeable = (x: any);
Expand Down Expand Up @@ -4254,7 +4256,9 @@ function renderNode(
getSuspendedThenable()
: thrownValue;

if (typeof x === 'object' && x !== null) {
if (request.status === ABORTING) {
// We are aborting so we can just bubble up to the task by falling through
} else if (typeof x === 'object' && x !== null) {
// $FlowFixMe[method-unbinding]
if (typeof x.then === 'function') {
const wakeable: Wakeable = (x: any);
Expand Down
Loading