@@ -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