Skip to content

Commit fc25111

Browse files
committed
Handle legacy root contains in clearContainer
Fix Fix Fix
1 parent 8d50a32 commit fc25111

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

packages/react-dom/src/client/ReactDOMHostConfig.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff 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
}

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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;

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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;

packages/react-reconciler/src/ReactFiberCompleteWork.old.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

packages/react-test-renderer/src/ReactTestHostConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function removeChild(
126126
parentInstance.children.splice(index, 1);
127127
}
128128

129-
export function clearContainer(container: Container): void {
129+
export function clearContainer(container: Container, root: Object): void {
130130
container.children.splice(0);
131131
}
132132

0 commit comments

Comments
 (0)