Skip to content

Commit 012e490

Browse files
committed
[Fizz] Delay detachment of completed boundaries until reveal
1 parent a428189 commit 012e490

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export function revealCompletedBoundaries(batch) {
3434
for (let i = 0; i < batch.length; i += 2) {
3535
const suspenseIdNode = batch[i];
3636
const contentNode = batch[i + 1];
37+
// We can detach the content now.
38+
// Completions of boundaries within this contentNode will now find the boundary
39+
// in its designated place.
40+
contentNode.parentNode.removeChild(contentNode);
3741

3842
// Clear all the existing children. This is complicated because
3943
// there can be embedded Suspense boundaries in the fallback.
@@ -385,13 +389,16 @@ export function completeBoundary(suspenseBoundaryID, contentID) {
385389
// the segment. Regardless we can ignore this case.
386390
return;
387391
}
388-
// We'll detach the content node so that regardless of what happens next we don't leave in the tree.
389-
// This might also help by not causing recalcing each time we move a child from here to the target.
390-
contentNodeOuter.parentNode.removeChild(contentNodeOuter);
391392

392393
// Find the fallback's first element.
393394
const suspenseIdNodeOuter = document.getElementById(suspenseBoundaryID);
394395
if (!suspenseIdNodeOuter) {
396+
// We'll never reveal this boundary so we can remove its content immediately.
397+
// Otherwise we'll leave it in until we reveal it.
398+
// This is important in case this specific boundary contains other boundaries
399+
// that may get completed before we reveal this one.
400+
contentNodeOuter.parentNode.removeChild(contentNodeOuter);
401+
395402
// The user must have already navigated away from this tree.
396403
// E.g. because the parent was hydrated. That's fine there's nothing to do
397404
// but we have to make sure that we already deleted the container node.

0 commit comments

Comments
 (0)