Skip to content

Commit 34da5aa

Browse files
authored
Only treat updates to lazy as a new mount in legacy mode (#24530)
* Only treat updates to lazy as a new mount in legacy mode * Update name and swap current check * Flip order back
1 parent 7d9e17a commit 34da5aa

File tree

2 files changed

+40
-80
lines changed

2 files changed

+40
-80
lines changed

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

+20-40
Original file line numberDiff line numberDiff line change
@@ -1110,16 +1110,8 @@ function updateClassComponent(
11101110
const instance = workInProgress.stateNode;
11111111
let shouldUpdate;
11121112
if (instance === null) {
1113-
if (current !== null) {
1114-
// A class component without an instance only mounts if it suspended
1115-
// inside a non-concurrent tree, in an inconsistent state. We want to
1116-
// treat it like a new mount, even though an empty version of it already
1117-
// committed. Disconnect the alternate pointers.
1118-
current.alternate = null;
1119-
workInProgress.alternate = null;
1120-
// Since this is conceptually a new fiber, schedule a Placement effect
1121-
workInProgress.flags |= Placement;
1122-
}
1113+
resetSuspendedCurrentOnMountInLegacyMode(current, workInProgress);
1114+
11231115
// In the initial pass we might need to construct the instance.
11241116
constructClassInstance(workInProgress, Component, nextProps);
11251117
mountClassInstance(workInProgress, Component, nextProps, renderLanes);
@@ -1469,16 +1461,7 @@ function mountLazyComponent(
14691461
elementType,
14701462
renderLanes,
14711463
) {
1472-
if (_current !== null) {
1473-
// A lazy component only mounts if it suspended inside a non-
1474-
// concurrent tree, in an inconsistent state. We want to treat it like
1475-
// a new mount, even though an empty version of it already committed.
1476-
// Disconnect the alternate pointers.
1477-
_current.alternate = null;
1478-
workInProgress.alternate = null;
1479-
// Since this is conceptually a new fiber, schedule a Placement effect
1480-
workInProgress.flags |= Placement;
1481-
}
1464+
resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);
14821465

14831466
const props = workInProgress.pendingProps;
14841467
const lazyComponent: LazyComponentType<any, any> = elementType;
@@ -1588,16 +1571,7 @@ function mountIncompleteClassComponent(
15881571
nextProps,
15891572
renderLanes,
15901573
) {
1591-
if (_current !== null) {
1592-
// An incomplete component only mounts if it suspended inside a non-
1593-
// concurrent tree, in an inconsistent state. We want to treat it like
1594-
// a new mount, even though an empty version of it already committed.
1595-
// Disconnect the alternate pointers.
1596-
_current.alternate = null;
1597-
workInProgress.alternate = null;
1598-
// Since this is conceptually a new fiber, schedule a Placement effect
1599-
workInProgress.flags |= Placement;
1600-
}
1574+
resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);
16011575

16021576
// Promote the fiber to a class and try rendering again.
16031577
workInProgress.tag = ClassComponent;
@@ -1635,16 +1609,7 @@ function mountIndeterminateComponent(
16351609
Component,
16361610
renderLanes,
16371611
) {
1638-
if (_current !== null) {
1639-
// An indeterminate component only mounts if it suspended inside a non-
1640-
// concurrent tree, in an inconsistent state. We want to treat it like
1641-
// a new mount, even though an empty version of it already committed.
1642-
// Disconnect the alternate pointers.
1643-
_current.alternate = null;
1644-
workInProgress.alternate = null;
1645-
// Since this is conceptually a new fiber, schedule a Placement effect
1646-
workInProgress.flags |= Placement;
1647-
}
1612+
resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);
16481613

16491614
const props = workInProgress.pendingProps;
16501615
let context;
@@ -3376,6 +3341,21 @@ export function checkIfWorkInProgressReceivedUpdate() {
33763341
return didReceiveUpdate;
33773342
}
33783343

3344+
function resetSuspendedCurrentOnMountInLegacyMode(current, workInProgress) {
3345+
if ((workInProgress.mode & ConcurrentMode) === NoMode) {
3346+
if (current !== null) {
3347+
// A lazy component only mounts if it suspended inside a non-
3348+
// concurrent tree, in an inconsistent state. We want to treat it like
3349+
// a new mount, even though an empty version of it already committed.
3350+
// Disconnect the alternate pointers.
3351+
current.alternate = null;
3352+
workInProgress.alternate = null;
3353+
// Since this is conceptually a new fiber, schedule a Placement effect
3354+
workInProgress.flags |= Placement;
3355+
}
3356+
}
3357+
}
3358+
33793359
function bailoutOnAlreadyFinishedWork(
33803360
current: Fiber | null,
33813361
workInProgress: Fiber,

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

+20-40
Original file line numberDiff line numberDiff line change
@@ -1110,16 +1110,8 @@ function updateClassComponent(
11101110
const instance = workInProgress.stateNode;
11111111
let shouldUpdate;
11121112
if (instance === null) {
1113-
if (current !== null) {
1114-
// A class component without an instance only mounts if it suspended
1115-
// inside a non-concurrent tree, in an inconsistent state. We want to
1116-
// treat it like a new mount, even though an empty version of it already
1117-
// committed. Disconnect the alternate pointers.
1118-
current.alternate = null;
1119-
workInProgress.alternate = null;
1120-
// Since this is conceptually a new fiber, schedule a Placement effect
1121-
workInProgress.flags |= Placement;
1122-
}
1113+
resetSuspendedCurrentOnMountInLegacyMode(current, workInProgress);
1114+
11231115
// In the initial pass we might need to construct the instance.
11241116
constructClassInstance(workInProgress, Component, nextProps);
11251117
mountClassInstance(workInProgress, Component, nextProps, renderLanes);
@@ -1469,16 +1461,7 @@ function mountLazyComponent(
14691461
elementType,
14701462
renderLanes,
14711463
) {
1472-
if (_current !== null) {
1473-
// A lazy component only mounts if it suspended inside a non-
1474-
// concurrent tree, in an inconsistent state. We want to treat it like
1475-
// a new mount, even though an empty version of it already committed.
1476-
// Disconnect the alternate pointers.
1477-
_current.alternate = null;
1478-
workInProgress.alternate = null;
1479-
// Since this is conceptually a new fiber, schedule a Placement effect
1480-
workInProgress.flags |= Placement;
1481-
}
1464+
resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);
14821465

14831466
const props = workInProgress.pendingProps;
14841467
const lazyComponent: LazyComponentType<any, any> = elementType;
@@ -1588,16 +1571,7 @@ function mountIncompleteClassComponent(
15881571
nextProps,
15891572
renderLanes,
15901573
) {
1591-
if (_current !== null) {
1592-
// An incomplete component only mounts if it suspended inside a non-
1593-
// concurrent tree, in an inconsistent state. We want to treat it like
1594-
// a new mount, even though an empty version of it already committed.
1595-
// Disconnect the alternate pointers.
1596-
_current.alternate = null;
1597-
workInProgress.alternate = null;
1598-
// Since this is conceptually a new fiber, schedule a Placement effect
1599-
workInProgress.flags |= Placement;
1600-
}
1574+
resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);
16011575

16021576
// Promote the fiber to a class and try rendering again.
16031577
workInProgress.tag = ClassComponent;
@@ -1635,16 +1609,7 @@ function mountIndeterminateComponent(
16351609
Component,
16361610
renderLanes,
16371611
) {
1638-
if (_current !== null) {
1639-
// An indeterminate component only mounts if it suspended inside a non-
1640-
// concurrent tree, in an inconsistent state. We want to treat it like
1641-
// a new mount, even though an empty version of it already committed.
1642-
// Disconnect the alternate pointers.
1643-
_current.alternate = null;
1644-
workInProgress.alternate = null;
1645-
// Since this is conceptually a new fiber, schedule a Placement effect
1646-
workInProgress.flags |= Placement;
1647-
}
1612+
resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);
16481613

16491614
const props = workInProgress.pendingProps;
16501615
let context;
@@ -3376,6 +3341,21 @@ export function checkIfWorkInProgressReceivedUpdate() {
33763341
return didReceiveUpdate;
33773342
}
33783343

3344+
function resetSuspendedCurrentOnMountInLegacyMode(current, workInProgress) {
3345+
if ((workInProgress.mode & ConcurrentMode) === NoMode) {
3346+
if (current !== null) {
3347+
// A lazy component only mounts if it suspended inside a non-
3348+
// concurrent tree, in an inconsistent state. We want to treat it like
3349+
// a new mount, even though an empty version of it already committed.
3350+
// Disconnect the alternate pointers.
3351+
current.alternate = null;
3352+
workInProgress.alternate = null;
3353+
// Since this is conceptually a new fiber, schedule a Placement effect
3354+
workInProgress.flags |= Placement;
3355+
}
3356+
}
3357+
}
3358+
33793359
function bailoutOnAlreadyFinishedWork(
33803360
current: Fiber | null,
33813361
workInProgress: Fiber,

0 commit comments

Comments
 (0)