Skip to content

Commit 8cf6f47

Browse files
committed
Keep track of inherited hoistables so we can forward them to newly discovered boundaries
Not just already blocked boundaries.
1 parent 24c84c7 commit 8cf6f47

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

packages/react-dom/src/__tests__/ReactDOMFloat-test.js

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5754,15 +5754,22 @@ body {
57545754
renderToPipeableStream(
57555755
<html>
57565756
<body>
5757-
<SuspenseList revealOrder="forwards">
5758-
<Suspense fallback="loading foo...">
5759-
<BlockedOn value="foo">
5760-
<link rel="stylesheet" href="foo" precedence="foo" />
5761-
foo
5757+
<Suspense fallback="loading...">
5758+
<SuspenseList revealOrder="forwards">
5759+
<Suspense fallback="loading foo...">
5760+
<BlockedOn value="foo">
5761+
<link rel="stylesheet" href="foo" precedence="foo" />
5762+
foo
5763+
</BlockedOn>
5764+
</Suspense>
5765+
<Suspense fallback="loading bar...">bar</Suspense>
5766+
<BlockedOn value="bar">
5767+
<Suspense fallback="loading baz...">
5768+
<BlockedOn value="baz">baz</BlockedOn>
5769+
</Suspense>
57625770
</BlockedOn>
5763-
</Suspense>
5764-
<Suspense fallback="loading bar...">bar</Suspense>
5765-
</SuspenseList>
5771+
</SuspenseList>
5772+
</Suspense>
57665773
</body>
57675774
</html>,
57685775
).pipe(writable);
@@ -5771,17 +5778,53 @@ body {
57715778
expect(getMeaningfulChildren(document)).toEqual(
57725779
<html>
57735780
<head />
5781+
<body>loading...</body>
5782+
</html>,
5783+
);
5784+
5785+
// unblock css loading
5786+
await act(() => {
5787+
resolveText('foo');
5788+
});
5789+
5790+
// bar is still blocking the whole list
5791+
expect(getMeaningfulChildren(document)).toEqual(
5792+
<html>
5793+
<head>
5794+
<link rel="stylesheet" href="foo" data-precedence="foo" />
5795+
</head>
5796+
<body>
5797+
{'loading...'}
5798+
<link as="style" href="foo" rel="preload" />
5799+
</body>
5800+
</html>,
5801+
);
5802+
5803+
// unblock inner loading states
5804+
await act(() => {
5805+
resolveText('bar');
5806+
});
5807+
5808+
expect(getMeaningfulChildren(document)).toEqual(
5809+
<html>
5810+
<head>
5811+
<link rel="stylesheet" href="foo" data-precedence="foo" />
5812+
</head>
57745813
<body>
57755814
{'loading foo...'}
57765815
{'loading bar...'}
5816+
{'loading baz...'}
5817+
<link as="style" href="foo" rel="preload" />
57775818
</body>
57785819
</html>,
57795820
);
57805821

5822+
// resolve the last boundary
57815823
await act(() => {
5782-
resolveText('foo');
5824+
resolveText('baz');
57835825
});
57845826

5827+
// still blocked on the css of the first row
57855828
expect(getMeaningfulChildren(document)).toEqual(
57865829
<html>
57875830
<head>
@@ -5790,6 +5833,7 @@ body {
57905833
<body>
57915834
{'loading foo...'}
57925835
{'loading bar...'}
5836+
{'loading baz...'}
57935837
<link as="style" href="foo" rel="preload" />
57945838
</body>
57955839
</html>,
@@ -5807,6 +5851,7 @@ body {
58075851
<body>
58085852
{'foo'}
58095853
{'bar'}
5854+
{'baz'}
58105855
<link as="style" href="foo" rel="preload" />
58115856
</body>
58125857
</html>,

packages/react-server/src/ReactFizzServer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ type SuspenseListRow = {
237237
pendingTasks: number, // The number of tasks, previous rows and inner suspense boundaries blocking this row.
238238
boundaries: null | Array<SuspenseBoundary>, // The boundaries in this row waiting to be unblocked by the previous row. (null means this row is not blocked)
239239
hoistables: HoistableState, // Any dependencies that this row depends on. Future rows need to also depend on it.
240+
inheritedHoistables: null | HoistableState, // Any dependencies that previous row depend on, that new boundaries of this row needs.
240241
together: boolean, // All the boundaries within this row must be revealed together.
241242
next: null | SuspenseListRow, // The next row blocked by this one.
242243
};
@@ -791,6 +792,10 @@ function createSuspenseBoundary(
791792
boundary.pendingTasks++;
792793
blockedBoundaries.push(boundary);
793794
}
795+
const inheritedHoistables = row.inheritedHoistables;
796+
if (inheritedHoistables !== null) {
797+
hoistHoistables(boundary.contentState, inheritedHoistables);
798+
}
794799
}
795800
return boundary;
796801
}
@@ -1691,6 +1696,10 @@ function unblockSuspenseListRow(
16911696
// Hoist any hoistables from the previous row into the next row so that it can be
16921697
// later transferred to all the rows.
16931698
hoistHoistables(unblockedRow.hoistables, inheritedHoistables);
1699+
// Mark the row itself for any newly discovered Suspense boundaries to inherit.
1700+
// This is different from hoistables because that also includes hoistables from
1701+
// all the boundaries below this row and not just previous rows.
1702+
unblockedRow.inheritedHoistables = inheritedHoistables;
16941703
}
16951704
// Unblocking the boundaries will decrement the count of this row but we keep it above
16961705
// zero so they never finish this row recursively.
@@ -1751,6 +1760,7 @@ function createSuspenseListRow(
17511760
pendingTasks: 1, // At first the row is blocked on attempting rendering itself.
17521761
boundaries: null,
17531762
hoistables: createHoistableState(),
1763+
inheritedHoistables: null,
17541764
together: false,
17551765
next: null,
17561766
};

0 commit comments

Comments
 (0)