File tree Expand file tree Collapse file tree 4 files changed +18
-10
lines changed Expand file tree Collapse file tree 4 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -634,13 +634,21 @@ export function unhideTextInstance(
634634 textInstance . nodeValue = text ;
635635}
636636
637- export function clearContainer ( container : Container ) : void {
638- if ( container . nodeType === ELEMENT_NODE ) {
639- ( ( container : any ) : Element ) . textContent = '' ;
640- } else if ( container . nodeType === DOCUMENT_NODE ) {
641- const body = ( ( container : any ) : Document ) . body ;
642- if ( body != null ) {
643- body . textContent = '' ;
637+ export function clearContainer ( container : Container , root : RootType ) : void {
638+ const legacyRootContainer = container . _reactRootContainer ;
639+ // If there is a legacy root container, check to see if the root
640+ // matches the root's container that we want to clear.
641+ if (
642+ legacyRootContainer == null ||
643+ legacyRootContainer . _internalRoot === root
644+ ) {
645+ if ( container . nodeType === ELEMENT_NODE ) {
646+ ( ( container : any ) : Element ) . textContent = '' ;
647+ } else if ( container . nodeType === DOCUMENT_NODE ) {
648+ const body = ( ( container : any ) : Document ) . body ;
649+ if ( body != null ) {
650+ body . textContent = '' ;
651+ }
644652 }
645653 }
646654}
Original file line number Diff line number Diff line change @@ -300,7 +300,7 @@ function commitBeforeMutationLifeCycles(
300300 if ( supportsMutation ) {
301301 if ( finishedWork . effectTag & Snapshot ) {
302302 const root = finishedWork . stateNode ;
303- clearContainer ( root . containerInfo ) ;
303+ clearContainer ( root . containerInfo , root ) ;
304304 }
305305 }
306306 return ;
Original file line number Diff line number Diff line change @@ -298,7 +298,7 @@ function commitBeforeMutationLifeCycles(
298298 if ( supportsMutation ) {
299299 if ( finishedWork . effectTag & Snapshot ) {
300300 const root = finishedWork . stateNode ;
301- clearContainer ( root . containerInfo ) ;
301+ clearContainer ( root . containerInfo , root ) ;
302302 }
303303 }
304304 return ;
Original file line number Diff line number Diff line change @@ -679,7 +679,7 @@ function completeWork(
679679 // If we hydrated, then we'll need to schedule an update for
680680 // the commit side-effects on the root.
681681 markUpdate ( workInProgress ) ;
682- } else if ( ! fiberRoot . hydrate && workInProgress . child !== null ) {
682+ } else if ( ! fiberRoot . hydrate ) {
683683 // Schedule an effect to clear this container at the start of the next commit.
684684 // This handles the case of React rendering into a container with previous children.
685685 // It's also safe to do for updates too, because current.child would only be null
You can’t perform that action at this time.
0 commit comments