Skip to content

Commit f318360

Browse files
author
Brian Vaughn
committed
Check root.hydrate before scheduling root to be cleared
This avoids breaking support for ReactDOM.hydration in legacy mode with no fallback.
1 parent 317fb78 commit f318360

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,13 @@ function completeWork(
681681
// If we hydrated, then we'll need to schedule an update for
682682
// the commit side-effects on the root.
683683
markUpdate(workInProgress);
684-
} else {
684+
} else if (!fiberRoot.hydrate) {
685685
// Schedule an effect to clear this container at the start of the next commit.
686686
// This handles the case of React rendering into a container with previous children.
687687
// It's also safe to do for updates too, because current.child would only be null
688688
// if the previous render was null (so the the container would already be empty).
689+
//
690+
// The additional root.hydrate check is required for hydration in legacy mode with no fallback.
689691
workInProgress.effectTag |= Snapshot;
690692
}
691693
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,13 @@ 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 {
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
686686
// if the previous render was null (so the the container would already be empty).
687+
//
688+
// The additional root.hydrate check is required for hydration in legacy mode with no fallback.
687689
workInProgress.effectTag |= Snapshot;
688690
}
689691
}

0 commit comments

Comments
 (0)