Skip to content

Commit 73c71ee

Browse files
committed
let fizz flush microtasks before flowing
1 parent f81d27c commit 73c71ee

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/next/src/server/stream-utils/node-web-streams-helper.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import type { ReactDOMServerReadableStream } from 'react-dom/server'
22
import { getTracer } from '../lib/trace/tracer'
33
import { AppRenderSpan } from '../lib/trace/constants'
44
import { DetachedPromise } from '../../lib/detached-promise'
5-
import { scheduleImmediate, atLeastOneTask } from '../../lib/scheduler'
5+
import {
6+
scheduleImmediate,
7+
atLeastOneTask,
8+
waitAtLeastOneReactRenderTask,
9+
} from '../../lib/scheduler'
610
import { ENCODED_TAGS } from './encoded-tags'
711
import {
812
indexOfUint8Array,
@@ -797,9 +801,13 @@ export async function continueFizzStream(
797801
// Suffix itself might contain close tags at the end, so we need to split it.
798802
const suffixUnclosed = suffix ? suffix.split(CLOSE_TAG, 1)[0] : null
799803

800-
// If we're generating static HTML we need to wait for it to resolve before continuing.
801804
if (isStaticGeneration) {
805+
// If we're generating static HTML we need to wait for it to resolve before continuing.
802806
await renderStream.allReady
807+
} else {
808+
// Otherwise, we want to make sure Fizz is done with all microtasky work
809+
// before we start pulling the stream and cause a flush.
810+
await waitAtLeastOneReactRenderTask()
803811
}
804812

805813
return chainTransformers(renderStream, [

0 commit comments

Comments
 (0)