@@ -30,6 +30,7 @@ import type { |
30 | 30 |
|
31 | 31 | import { |
32 | 32 | writeChunk, |
| 33 | + writeChunkAndReturn, |
33 | 34 | stringToChunk, |
34 | 35 | stringToPrecomputedChunk, |
35 | 36 | } from 'react-server/src/ReactServerStreamConfig'; |
@@ -1427,11 +1428,14 @@ export function writeCompletedRoot( |
1427 | 1428 | responseState: ResponseState, |
1428 | 1429 | ): boolean { |
1429 | 1430 | 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]); |
1433 | 1434 | } |
1434 | | - return result; |
| 1435 | + if (i < bootstrapChunks.length) { |
| 1436 | + return writeChunkAndReturn(destination, bootstrapChunks[i]); |
| 1437 | + } |
| 1438 | + return true; |
1435 | 1439 | } |
1436 | 1440 |
|
1437 | 1441 | // Structural Nodes |
@@ -1450,7 +1454,7 @@ export function writePlaceholder( |
1450 | 1454 | writeChunk(destination, responseState.placeholderPrefix); |
1451 | 1455 | const formattedID = stringToChunk(id.toString(16)); |
1452 | 1456 | writeChunk(destination, formattedID); |
1453 | | - return writeChunk(destination, placeholder2); |
| 1457 | + return writeChunkAndReturn(destination, placeholder2); |
1454 | 1458 | } |
1455 | 1459 |
|
1456 | 1460 | // Suspense boundaries are encoded as comments. |
@@ -1480,7 +1484,7 @@ export function writeStartCompletedSuspenseBoundary( |
1480 | 1484 | destination: Destination, |
1481 | 1485 | responseState: ResponseState, |
1482 | 1486 | ): boolean { |
1483 | | - return writeChunk(destination, startCompletedSuspenseBoundary); |
| 1487 | + return writeChunkAndReturn(destination, startCompletedSuspenseBoundary); |
1484 | 1488 | } |
1485 | 1489 | export function writeStartPendingSuspenseBoundary( |
1486 | 1490 | destination: Destination, |
@@ -1496,31 +1500,31 @@ export function writeStartPendingSuspenseBoundary( |
1496 | 1500 | } |
1497 | 1501 |
|
1498 | 1502 | writeChunk(destination, id); |
1499 | | - return writeChunk(destination, startPendingSuspenseBoundary2); |
| 1503 | + return writeChunkAndReturn(destination, startPendingSuspenseBoundary2); |
1500 | 1504 | } |
1501 | 1505 | export function writeStartClientRenderedSuspenseBoundary( |
1502 | 1506 | destination: Destination, |
1503 | 1507 | responseState: ResponseState, |
1504 | 1508 | ): boolean { |
1505 | | - return writeChunk(destination, startClientRenderedSuspenseBoundary); |
| 1509 | + return writeChunkAndReturn(destination, startClientRenderedSuspenseBoundary); |
1506 | 1510 | } |
1507 | 1511 | export function writeEndCompletedSuspenseBoundary( |
1508 | 1512 | destination: Destination, |
1509 | 1513 | responseState: ResponseState, |
1510 | 1514 | ): boolean { |
1511 | | - return writeChunk(destination, endSuspenseBoundary); |
| 1515 | + return writeChunkAndReturn(destination, endSuspenseBoundary); |
1512 | 1516 | } |
1513 | 1517 | export function writeEndPendingSuspenseBoundary( |
1514 | 1518 | destination: Destination, |
1515 | 1519 | responseState: ResponseState, |
1516 | 1520 | ): boolean { |
1517 | | - return writeChunk(destination, endSuspenseBoundary); |
| 1521 | + return writeChunkAndReturn(destination, endSuspenseBoundary); |
1518 | 1522 | } |
1519 | 1523 | export function writeEndClientRenderedSuspenseBoundary( |
1520 | 1524 | destination: Destination, |
1521 | 1525 | responseState: ResponseState, |
1522 | 1526 | ): boolean { |
1523 | | - return writeChunk(destination, endSuspenseBoundary); |
| 1527 | + return writeChunkAndReturn(destination, endSuspenseBoundary); |
1524 | 1528 | } |
1525 | 1529 |
|
1526 | 1530 | const startSegmentHTML = stringToPrecomputedChunk('<div hidden id="'); |
@@ -1571,25 +1575,25 @@ export function writeStartSegment( |
1571 | 1575 | writeChunk(destination, startSegmentHTML); |
1572 | 1576 | writeChunk(destination, responseState.segmentPrefix); |
1573 | 1577 | writeChunk(destination, stringToChunk(id.toString(16))); |
1574 | | - return writeChunk(destination, startSegmentHTML2); |
| 1578 | + return writeChunkAndReturn(destination, startSegmentHTML2); |
1575 | 1579 | } |
1576 | 1580 | case SVG_MODE: { |
1577 | 1581 | writeChunk(destination, startSegmentSVG); |
1578 | 1582 | writeChunk(destination, responseState.segmentPrefix); |
1579 | 1583 | writeChunk(destination, stringToChunk(id.toString(16))); |
1580 | | - return writeChunk(destination, startSegmentSVG2); |
| 1584 | + return writeChunkAndReturn(destination, startSegmentSVG2); |
1581 | 1585 | } |
1582 | 1586 | case MATHML_MODE: { |
1583 | 1587 | writeChunk(destination, startSegmentMathML); |
1584 | 1588 | writeChunk(destination, responseState.segmentPrefix); |
1585 | 1589 | writeChunk(destination, stringToChunk(id.toString(16))); |
1586 | | - return writeChunk(destination, startSegmentMathML2); |
| 1590 | + return writeChunkAndReturn(destination, startSegmentMathML2); |
1587 | 1591 | } |
1588 | 1592 | case HTML_TABLE_MODE: { |
1589 | 1593 | writeChunk(destination, startSegmentTable); |
1590 | 1594 | writeChunk(destination, responseState.segmentPrefix); |
1591 | 1595 | writeChunk(destination, stringToChunk(id.toString(16))); |
1592 | | - return writeChunk(destination, startSegmentTable2); |
| 1596 | + return writeChunkAndReturn(destination, startSegmentTable2); |
1593 | 1597 | } |
1594 | 1598 | // TODO: For the rest of these, there will be extra wrapper nodes that never |
1595 | 1599 | // get deleted from the document. We need to delete the table too as part |
@@ -1599,19 +1603,19 @@ export function writeStartSegment( |
1599 | 1603 | writeChunk(destination, startSegmentTableBody); |
1600 | 1604 | writeChunk(destination, responseState.segmentPrefix); |
1601 | 1605 | writeChunk(destination, stringToChunk(id.toString(16))); |
1602 | | - return writeChunk(destination, startSegmentTableBody2); |
| 1606 | + return writeChunkAndReturn(destination, startSegmentTableBody2); |
1603 | 1607 | } |
1604 | 1608 | case HTML_TABLE_ROW_MODE: { |
1605 | 1609 | writeChunk(destination, startSegmentTableRow); |
1606 | 1610 | writeChunk(destination, responseState.segmentPrefix); |
1607 | 1611 | writeChunk(destination, stringToChunk(id.toString(16))); |
1608 | | - return writeChunk(destination, startSegmentTableRow2); |
| 1612 | + return writeChunkAndReturn(destination, startSegmentTableRow2); |
1609 | 1613 | } |
1610 | 1614 | case HTML_COLGROUP_MODE: { |
1611 | 1615 | writeChunk(destination, startSegmentColGroup); |
1612 | 1616 | writeChunk(destination, responseState.segmentPrefix); |
1613 | 1617 | writeChunk(destination, stringToChunk(id.toString(16))); |
1614 | | - return writeChunk(destination, startSegmentColGroup2); |
| 1618 | + return writeChunkAndReturn(destination, startSegmentColGroup2); |
1615 | 1619 | } |
1616 | 1620 | default: { |
1617 | 1621 | throw new Error('Unknown insertion mode. This is a bug in React.'); |
@@ -1625,25 +1629,25 @@ export function writeEndSegment( |
1625 | 1629 | switch (formatContext.insertionMode) { |
1626 | 1630 | case ROOT_HTML_MODE: |
1627 | 1631 | case HTML_MODE: { |
1628 | | - return writeChunk(destination, endSegmentHTML); |
| 1632 | + return writeChunkAndReturn(destination, endSegmentHTML); |
1629 | 1633 | } |
1630 | 1634 | case SVG_MODE: { |
1631 | | - return writeChunk(destination, endSegmentSVG); |
| 1635 | + return writeChunkAndReturn(destination, endSegmentSVG); |
1632 | 1636 | } |
1633 | 1637 | case MATHML_MODE: { |
1634 | | - return writeChunk(destination, endSegmentMathML); |
| 1638 | + return writeChunkAndReturn(destination, endSegmentMathML); |
1635 | 1639 | } |
1636 | 1640 | case HTML_TABLE_MODE: { |
1637 | | - return writeChunk(destination, endSegmentTable); |
| 1641 | + return writeChunkAndReturn(destination, endSegmentTable); |
1638 | 1642 | } |
1639 | 1643 | case HTML_TABLE_BODY_MODE: { |
1640 | | - return writeChunk(destination, endSegmentTableBody); |
| 1644 | + return writeChunkAndReturn(destination, endSegmentTableBody); |
1641 | 1645 | } |
1642 | 1646 | case HTML_TABLE_ROW_MODE: { |
1643 | | - return writeChunk(destination, endSegmentTableRow); |
| 1647 | + return writeChunkAndReturn(destination, endSegmentTableRow); |
1644 | 1648 | } |
1645 | 1649 | case HTML_COLGROUP_MODE: { |
1646 | | - return writeChunk(destination, endSegmentColGroup); |
| 1650 | + return writeChunkAndReturn(destination, endSegmentColGroup); |
1647 | 1651 | } |
1648 | 1652 | default: { |
1649 | 1653 | throw new Error('Unknown insertion mode. This is a bug in React.'); |
@@ -1790,7 +1794,7 @@ export function writeCompletedSegmentInstruction( |
1790 | 1794 | writeChunk(destination, completeSegmentScript2); |
1791 | 1795 | writeChunk(destination, responseState.placeholderPrefix); |
1792 | 1796 | writeChunk(destination, formattedID); |
1793 | | - return writeChunk(destination, completeSegmentScript3); |
| 1797 | + return writeChunkAndReturn(destination, completeSegmentScript3); |
1794 | 1798 | } |
1795 | 1799 |
|
1796 | 1800 | const completeBoundaryScript1Full = stringToPrecomputedChunk( |
@@ -1827,7 +1831,7 @@ export function writeCompletedBoundaryInstruction( |
1827 | 1831 | writeChunk(destination, completeBoundaryScript2); |
1828 | 1832 | writeChunk(destination, responseState.segmentPrefix); |
1829 | 1833 | writeChunk(destination, formattedContentID); |
1830 | | - return writeChunk(destination, completeBoundaryScript3); |
| 1834 | + return writeChunkAndReturn(destination, completeBoundaryScript3); |
1831 | 1835 | } |
1832 | 1836 |
|
1833 | 1837 | const clientRenderScript1Full = stringToPrecomputedChunk( |
@@ -1858,5 +1862,5 @@ export function writeClientRenderBoundaryInstruction( |
1858 | 1862 | } |
1859 | 1863 |
|
1860 | 1864 | writeChunk(destination, boundaryID); |
1861 | | - return writeChunk(destination, clientRenderScript2); |
| 1865 | + return writeChunkAndReturn(destination, clientRenderScript2); |
1862 | 1866 | } |