Skip to content

Commit f5373e4

Browse files
committed
Add optimization to inline all boundaries at once if possible
1 parent 040fe3e commit f5373e4

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,14 +2444,16 @@ describe('ReactDOMServerPartialHydration', () => {
24442444

24452445
function App({showMore}) {
24462446
return (
2447-
<SuspenseList revealOrder="together">
2448-
{a}
2449-
{showMore ? (
2450-
<Suspense fallback="Loading B">
2451-
<AlwaysSuspend />
2452-
</Suspense>
2453-
) : null}
2454-
</SuspenseList>
2447+
<div>
2448+
<SuspenseList revealOrder="together">
2449+
{a}
2450+
{showMore ? (
2451+
<Suspense fallback="Loading B">
2452+
<AlwaysSuspend />
2453+
</Suspense>
2454+
) : null}
2455+
</SuspenseList>
2456+
</div>
24552457
);
24562458
}
24572459

packages/react-server/src/ReactFizzServer.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5394,14 +5394,39 @@ function flushSegment(
53945394
return flushSubtree(request, destination, segment, hoistableState);
53955395
}
53965396

5397+
const row = boundary.row;
5398+
if (
5399+
boundary.status === PENDING &&
5400+
row !== null &&
5401+
row.together &&
5402+
row.pendingTasks === row.boundaries.length
5403+
) {
5404+
// If we have a "together" row and all the pendingTasks are really the boundaries themselves,
5405+
// and we won't outline any of them then we can unblock this row early so that we can inline
5406+
// all the boundaries at once.
5407+
let allComplete = true;
5408+
for (let i = 0; i < row.boundaries.length; i++) {
5409+
const rowBoundary = row.boundaries[i];
5410+
if (
5411+
rowBoundary.pendingTasks !== 1 ||
5412+
isEligibleForOutlining(request, rowBoundary)
5413+
) {
5414+
allComplete = false;
5415+
break;
5416+
}
5417+
}
5418+
if (allComplete) {
5419+
unblockSuspenseListRow(request, row);
5420+
}
5421+
}
5422+
53975423
boundary.parentFlushed = true;
53985424
// This segment is a Suspense boundary. We need to decide whether to
53995425
// emit the content or the fallback now.
54005426
if (boundary.status === CLIENT_RENDERED) {
54015427
// Emit a client rendered suspense boundary wrapper.
54025428
// We never queue the inner boundary so we'll never emit its content or partial segments.
54035429

5404-
const row = boundary.row;
54055430
if (row !== null) {
54065431
// Since this boundary end up client rendered, we can unblock future suspense list rows.
54075432
// This means that they may appear out of order if the future rows succeed but this is
@@ -5500,7 +5525,6 @@ function flushSegment(
55005525
hoistHoistables(hoistableState, boundary.contentState);
55015526
}
55025527

5503-
const row = boundary.row;
55045528
if (row !== null && isEligibleForOutlining(request, boundary)) {
55055529
// Once we have written the boundary, we can unblock the row and let future
55065530
// rows be written. This may schedule new completed boundaries.

0 commit comments

Comments
 (0)