From 3d56c0eebeef689db779d8da2e03f3a9fa6ba32b Mon Sep 17 00:00:00 2001 From: Josh Story Date: Fri, 12 Aug 2022 12:43:50 -0700 Subject: [PATCH] nits and errors --- .../src/server/ReactDOMServerFormatConfig.js | 27 +++---------------- packages/react-server/src/ReactFizzServer.js | 13 ++++----- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/packages/react-dom/src/server/ReactDOMServerFormatConfig.js b/packages/react-dom/src/server/ReactDOMServerFormatConfig.js index 16924daf4e708..e9601b38a79a8 100644 --- a/packages/react-dom/src/server/ReactDOMServerFormatConfig.js +++ b/packages/react-dom/src/server/ReactDOMServerFormatConfig.js @@ -243,26 +243,6 @@ export function getChildFormatContext( return parentContext; } -function isPreambleInsertion(type: string): boolean { - switch (type) { - case 'html': - case 'head': { - return true; - } - } - return false; -} - -function isPostambleInsertion(type: string): boolean { - switch (type) { - case 'body': - case 'html': { - return true; - } - } - return false; -} - export type SuspenseBoundaryID = null | PrecomputedChunk; export const UNINITIALIZED_SUSPENSE_BOUNDARY_ID: SuspenseBoundaryID = null; @@ -1264,7 +1244,7 @@ function pushStartHead( responseState: ResponseState, ): ReactNodeList { // Preamble type is nullable for feature off cases but is guaranteed when feature is on - target = enableFloat && isPreambleInsertion(tag) ? (preamble: any) : target; + target = enableFloat ? (preamble: any) : target; return pushStartGenericElement(target, props, tag, responseState); } @@ -1278,7 +1258,7 @@ function pushStartHtml( responseState: ResponseState, ): ReactNodeList { // Preamble type is nullable for feature off cases but is guaranteed when feature is on - target = enableFloat && isPreambleInsertion(tag) ? (preamble: any) : target; + target = enableFloat ? (preamble: any) : target; if (formatContext.insertionMode === ROOT_HTML_MODE) { // If we're rendering the html tag and we're at the root (i.e. not in foreignObject) @@ -1657,8 +1637,7 @@ export function pushEndInstance( case 'body': case 'html': // Preamble type is nullable for feature off cases but is guaranteed when feature is on - target = - enableFloat && isPostambleInsertion(type) ? (postamble: any) : target; + target = enableFloat ? (postamble: any) : target; // Intentional fallthrough default: { target.push(endTag1, stringToChunk(type), endTag2); diff --git a/packages/react-server/src/ReactFizzServer.js b/packages/react-server/src/ReactFizzServer.js index 384c50a106330..84db02300fb82 100644 --- a/packages/react-server/src/ReactFizzServer.js +++ b/packages/react-server/src/ReactFizzServer.js @@ -2081,7 +2081,6 @@ function flushCompletedQueues( // we expect the preamble to be tiny and will ignore backpressure writeChunk(destination, preamble[i]); } - preamble.length = 0; } flushSegment(request, destination, completedRootSegment); @@ -2159,7 +2158,6 @@ function flushCompletedQueues( } largeBoundaries.splice(0, i); } finally { - let allComplete = false; if ( request.allPendingTasks === 0 && request.pingedTasks.length === 0 && @@ -2168,7 +2166,6 @@ function flushCompletedQueues( // We don't need to check any partially completed segments because // either they have pending task or they're complete. ) { - allComplete = true; if (enableFloat) { const postamble: Array< Chunk | PrecomputedChunk, @@ -2176,12 +2173,9 @@ function flushCompletedQueues( for (let i = 0; i < postamble.length; i++) { writeChunk(destination, postamble[i]); } - postamble.length = 0; } - } - completeWriting(destination); - flushBuffered(destination); - if (allComplete) { + completeWriting(destination); + flushBuffered(destination); if (__DEV__) { if (request.abortableTasks.size !== 0) { console.error( @@ -2191,6 +2185,9 @@ function flushCompletedQueues( } // We're done. close(destination); + } else { + completeWriting(destination); + flushBuffered(destination); } } }