diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js index 87d04bdd07655..93e30aa2305be 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js @@ -105,12 +105,10 @@ describe('ReactDOMFizzServer', () => { , - { - onCompleteAll() { - isComplete = true; - }, - }, ); + + stream.allReady.then(() => (isComplete = true)); + await jest.runAllTimers(); expect(isComplete).toBe(false); // Resolve the loading. diff --git a/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js b/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js index a07967ca34f98..768c73640710c 100644 --- a/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js +++ b/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js @@ -32,23 +32,34 @@ type Options = {| bootstrapModules?: Array, progressiveChunkSize?: number, signal?: AbortSignal, - onCompleteAll?: () => void, onError?: (error: mixed) => void, |}; +// TODO: Move to sub-classing ReadableStream. +type ReactDOMServerReadableStream = ReadableStream & { + allReady: Promise, +}; + function renderToReadableStream( children: ReactNodeList, options?: Options, -): Promise { +): Promise { return new Promise((resolve, reject) => { + let onCompleteAll; + const allReady = new Promise(resolve => { + onCompleteAll = resolve; + }); + function onCompleteShell() { - const stream = new ReadableStream({ + const stream: ReactDOMServerReadableStream = new ReadableStream({ type: 'bytes', pull(controller) { startFlowing(request, controller); }, cancel(reason) {}, }); + // TODO: Move to sub-classing ReadableStream. + stream.allReady = allReady; resolve(stream); } function onErrorShell(error: mixed) { @@ -66,7 +77,7 @@ function renderToReadableStream( createRootFormatContext(options ? options.namespaceURI : undefined), options ? options.progressiveChunkSize : undefined, options ? options.onError : undefined, - options ? options.onCompleteAll : undefined, + onCompleteAll, onCompleteShell, onErrorShell, );