@@ -30,6 +30,7 @@ import type {
3030
3131import {
3232 writeChunk ,
33+ writeChunkAndReturn ,
3334 stringToChunk ,
3435 stringToPrecomputedChunk ,
3536} from 'react-server/src/ReactServerStreamConfig' ;
@@ -1427,11 +1428,14 @@ export function writeCompletedRoot(
14271428 responseState : ResponseState ,
14281429) : boolean {
14291430 const bootstrapChunks = responseState . bootstrapChunks ;
1430- let result = true ;
1431- for ( let i = 0 ; i < bootstrapChunks . length ; i ++ ) {
1432- result = writeChunk ( destination , bootstrapChunks [ i ] ) ;
1431+ let i = 0 ;
1432+ for ( ; i < bootstrapChunks . length - 1 ; i ++ ) {
1433+ writeChunk ( destination , bootstrapChunks [ i ] ) ;
14331434 }
1434- return result ;
1435+ if ( i < bootstrapChunks . length ) {
1436+ return writeChunkAndReturn ( destination , bootstrapChunks [ i ] ) ;
1437+ }
1438+ return true ;
14351439}
14361440
14371441// Structural Nodes
@@ -1450,7 +1454,7 @@ export function writePlaceholder(
14501454 writeChunk ( destination , responseState . placeholderPrefix ) ;
14511455 const formattedID = stringToChunk ( id . toString ( 16 ) ) ;
14521456 writeChunk ( destination , formattedID ) ;
1453- return writeChunk ( destination , placeholder2 ) ;
1457+ return writeChunkAndReturn ( destination , placeholder2 ) ;
14541458}
14551459
14561460// Suspense boundaries are encoded as comments.
@@ -1480,7 +1484,7 @@ export function writeStartCompletedSuspenseBoundary(
14801484 destination : Destination ,
14811485 responseState : ResponseState ,
14821486) : boolean {
1483- return writeChunk ( destination , startCompletedSuspenseBoundary ) ;
1487+ return writeChunkAndReturn ( destination , startCompletedSuspenseBoundary ) ;
14841488}
14851489export function writeStartPendingSuspenseBoundary (
14861490 destination : Destination ,
@@ -1496,31 +1500,31 @@ export function writeStartPendingSuspenseBoundary(
14961500 }
14971501
14981502 writeChunk ( destination , id ) ;
1499- return writeChunk ( destination , startPendingSuspenseBoundary2 ) ;
1503+ return writeChunkAndReturn ( destination , startPendingSuspenseBoundary2 ) ;
15001504}
15011505export function writeStartClientRenderedSuspenseBoundary (
15021506 destination : Destination ,
15031507 responseState : ResponseState ,
15041508) : boolean {
1505- return writeChunk ( destination , startClientRenderedSuspenseBoundary ) ;
1509+ return writeChunkAndReturn ( destination , startClientRenderedSuspenseBoundary ) ;
15061510}
15071511export function writeEndCompletedSuspenseBoundary (
15081512 destination : Destination ,
15091513 responseState : ResponseState ,
15101514) : boolean {
1511- return writeChunk ( destination , endSuspenseBoundary ) ;
1515+ return writeChunkAndReturn ( destination , endSuspenseBoundary ) ;
15121516}
15131517export function writeEndPendingSuspenseBoundary (
15141518 destination : Destination ,
15151519 responseState : ResponseState ,
15161520) : boolean {
1517- return writeChunk ( destination , endSuspenseBoundary ) ;
1521+ return writeChunkAndReturn ( destination , endSuspenseBoundary ) ;
15181522}
15191523export function writeEndClientRenderedSuspenseBoundary (
15201524 destination : Destination ,
15211525 responseState : ResponseState ,
15221526) : boolean {
1523- return writeChunk ( destination , endSuspenseBoundary ) ;
1527+ return writeChunkAndReturn ( destination , endSuspenseBoundary ) ;
15241528}
15251529
15261530const startSegmentHTML = stringToPrecomputedChunk ( '<div hidden id="' ) ;
@@ -1571,25 +1575,25 @@ export function writeStartSegment(
15711575 writeChunk ( destination , startSegmentHTML ) ;
15721576 writeChunk ( destination , responseState . segmentPrefix ) ;
15731577 writeChunk ( destination , stringToChunk ( id . toString ( 16 ) ) ) ;
1574- return writeChunk ( destination , startSegmentHTML2 ) ;
1578+ return writeChunkAndReturn ( destination , startSegmentHTML2 ) ;
15751579 }
15761580 case SVG_MODE : {
15771581 writeChunk ( destination , startSegmentSVG ) ;
15781582 writeChunk ( destination , responseState . segmentPrefix ) ;
15791583 writeChunk ( destination , stringToChunk ( id . toString ( 16 ) ) ) ;
1580- return writeChunk ( destination , startSegmentSVG2 ) ;
1584+ return writeChunkAndReturn ( destination , startSegmentSVG2 ) ;
15811585 }
15821586 case MATHML_MODE : {
15831587 writeChunk ( destination , startSegmentMathML ) ;
15841588 writeChunk ( destination , responseState . segmentPrefix ) ;
15851589 writeChunk ( destination , stringToChunk ( id . toString ( 16 ) ) ) ;
1586- return writeChunk ( destination , startSegmentMathML2 ) ;
1590+ return writeChunkAndReturn ( destination , startSegmentMathML2 ) ;
15871591 }
15881592 case HTML_TABLE_MODE : {
15891593 writeChunk ( destination , startSegmentTable ) ;
15901594 writeChunk ( destination , responseState . segmentPrefix ) ;
15911595 writeChunk ( destination , stringToChunk ( id . toString ( 16 ) ) ) ;
1592- return writeChunk ( destination , startSegmentTable2 ) ;
1596+ return writeChunkAndReturn ( destination , startSegmentTable2 ) ;
15931597 }
15941598 // TODO: For the rest of these, there will be extra wrapper nodes that never
15951599 // get deleted from the document. We need to delete the table too as part
@@ -1599,19 +1603,19 @@ export function writeStartSegment(
15991603 writeChunk ( destination , startSegmentTableBody ) ;
16001604 writeChunk ( destination , responseState . segmentPrefix ) ;
16011605 writeChunk ( destination , stringToChunk ( id . toString ( 16 ) ) ) ;
1602- return writeChunk ( destination , startSegmentTableBody2 ) ;
1606+ return writeChunkAndReturn ( destination , startSegmentTableBody2 ) ;
16031607 }
16041608 case HTML_TABLE_ROW_MODE : {
16051609 writeChunk ( destination , startSegmentTableRow ) ;
16061610 writeChunk ( destination , responseState . segmentPrefix ) ;
16071611 writeChunk ( destination , stringToChunk ( id . toString ( 16 ) ) ) ;
1608- return writeChunk ( destination , startSegmentTableRow2 ) ;
1612+ return writeChunkAndReturn ( destination , startSegmentTableRow2 ) ;
16091613 }
16101614 case HTML_COLGROUP_MODE : {
16111615 writeChunk ( destination , startSegmentColGroup ) ;
16121616 writeChunk ( destination , responseState . segmentPrefix ) ;
16131617 writeChunk ( destination , stringToChunk ( id . toString ( 16 ) ) ) ;
1614- return writeChunk ( destination , startSegmentColGroup2 ) ;
1618+ return writeChunkAndReturn ( destination , startSegmentColGroup2 ) ;
16151619 }
16161620 default : {
16171621 throw new Error ( 'Unknown insertion mode. This is a bug in React.' ) ;
@@ -1625,25 +1629,25 @@ export function writeEndSegment(
16251629 switch ( formatContext . insertionMode ) {
16261630 case ROOT_HTML_MODE :
16271631 case HTML_MODE : {
1628- return writeChunk ( destination , endSegmentHTML ) ;
1632+ return writeChunkAndReturn ( destination , endSegmentHTML ) ;
16291633 }
16301634 case SVG_MODE : {
1631- return writeChunk ( destination , endSegmentSVG ) ;
1635+ return writeChunkAndReturn ( destination , endSegmentSVG ) ;
16321636 }
16331637 case MATHML_MODE : {
1634- return writeChunk ( destination , endSegmentMathML ) ;
1638+ return writeChunkAndReturn ( destination , endSegmentMathML ) ;
16351639 }
16361640 case HTML_TABLE_MODE : {
1637- return writeChunk ( destination , endSegmentTable ) ;
1641+ return writeChunkAndReturn ( destination , endSegmentTable ) ;
16381642 }
16391643 case HTML_TABLE_BODY_MODE : {
1640- return writeChunk ( destination , endSegmentTableBody ) ;
1644+ return writeChunkAndReturn ( destination , endSegmentTableBody ) ;
16411645 }
16421646 case HTML_TABLE_ROW_MODE : {
1643- return writeChunk ( destination , endSegmentTableRow ) ;
1647+ return writeChunkAndReturn ( destination , endSegmentTableRow ) ;
16441648 }
16451649 case HTML_COLGROUP_MODE : {
1646- return writeChunk ( destination , endSegmentColGroup ) ;
1650+ return writeChunkAndReturn ( destination , endSegmentColGroup ) ;
16471651 }
16481652 default : {
16491653 throw new Error ( 'Unknown insertion mode. This is a bug in React.' ) ;
@@ -1790,7 +1794,7 @@ export function writeCompletedSegmentInstruction(
17901794 writeChunk ( destination , completeSegmentScript2 ) ;
17911795 writeChunk ( destination , responseState . placeholderPrefix ) ;
17921796 writeChunk ( destination , formattedID ) ;
1793- return writeChunk ( destination , completeSegmentScript3 ) ;
1797+ return writeChunkAndReturn ( destination , completeSegmentScript3 ) ;
17941798}
17951799
17961800const completeBoundaryScript1Full = stringToPrecomputedChunk (
@@ -1827,7 +1831,7 @@ export function writeCompletedBoundaryInstruction(
18271831 writeChunk ( destination , completeBoundaryScript2 ) ;
18281832 writeChunk ( destination , responseState . segmentPrefix ) ;
18291833 writeChunk ( destination , formattedContentID ) ;
1830- return writeChunk ( destination , completeBoundaryScript3 ) ;
1834+ return writeChunkAndReturn ( destination , completeBoundaryScript3 ) ;
18311835}
18321836
18331837const clientRenderScript1Full = stringToPrecomputedChunk (
@@ -1858,5 +1862,5 @@ export function writeClientRenderBoundaryInstruction(
18581862 }
18591863
18601864 writeChunk ( destination , boundaryID ) ;
1861- return writeChunk ( destination , clientRenderScript2 ) ;
1865+ return writeChunkAndReturn ( destination , clientRenderScript2 ) ;
18621866}
0 commit comments