Skip to content

Commit c250b7d

Browse files
authored
[Fizz] Should be considered complete inside onShellReady callback (#33295)
We decremented `allPendingTasks` after invoking `onShellReady`. Which means that in that scope it wasn't considered fully complete. Since the pattern for flushing in Node.js is to start piping in `onShellReady` and that's how you can get sync behavior, this led us to think that we had more work left to do. For example we emitted the `writeShellTimeInstruction` in this scenario before.
1 parent 4448b18 commit c250b7d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ describe('ReactDOMFizzServerNode', () => {
6767
expect(output.result).toMatchInlineSnapshot(`"<div>hello world</div>"`);
6868
});
6969

70+
it('flush fully if piping in on onShellReady', async () => {
71+
const {writable, output} = getTestWritable();
72+
await act(() => {
73+
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
74+
<div>hello world</div>,
75+
{
76+
onShellReady() {
77+
pipe(writable);
78+
},
79+
},
80+
);
81+
});
82+
expect(output.result).toMatchInlineSnapshot(`"<div>hello world</div>"`);
83+
});
84+
7085
it('should emit DOCTYPE at the root of the document', async () => {
7186
const {writable, output} = getTestWritable();
7287
await act(() => {

packages/react-server/src/ReactFizzServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4335,6 +4335,7 @@ function finishedTask(
43354335
boundary: Root | SuspenseBoundary,
43364336
segment: null | Segment,
43374337
) {
4338+
request.allPendingTasks--;
43384339
if (boundary === null) {
43394340
if (segment !== null && segment.parentFlushed) {
43404341
if (request.completedRootSegment !== null) {
@@ -4417,7 +4418,6 @@ function finishedTask(
44174418
}
44184419
}
44194420

4420-
request.allPendingTasks--;
44214421
if (request.allPendingTasks === 0) {
44224422
completeAll(request);
44234423
}

0 commit comments

Comments
 (0)