[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.
Sebastian Markbåge committed
May 16, 2025 at 14:53 UTC
c250b7d980864be49facf2306f06455e7f9e305d
2 files changed
+16
-1
packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js
+15
@@ -67,6 +67,21 @@ describe('ReactDOMFizzServerNode', () => {
67
expect(output.result).toMatchInlineSnapshot(`"<div>hello world</div>"`);
68
});
69
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
+
85
it('should emit DOCTYPE at the root of the document', async () => {
86
const {writable, output} = getTestWritable();
87
await act(() => {
packages/react-server/src/ReactFizzServer.js
+1
-1
@@ -4335,6 +4335,7 @@ function finishedTask(
4335
boundary: Root | SuspenseBoundary,
4336
segment: null | Segment,
4337
) {
4338
+ request.allPendingTasks--;
4339
if (boundary === null) {
4340
if (segment !== null && segment.parentFlushed) {
4341
if (request.completedRootSegment !== null) {
@@ -4417,7 +4418,6 @@ function finishedTask(
4418
}
4419
}
4420
4420
- request.allPendingTasks--;
4421
if (request.allPendingTasks === 0) {
4422
completeAll(request);
4423
}