Skip to content

Commit 8f52597

Browse files
committed
Don't clear other flags when adding Deletion
Same as facebook#20398 but for Deletions. There's no new regression test, but in the effects refactor, existing tests will fail without this.
1 parent d46de90 commit 8f52597

13 files changed

+88
-343
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import type {Fiber} from './ReactInternalTypes';
1313
import type {Lanes} from './ReactFiberLane.new';
1414

1515
import getComponentName from 'shared/getComponentName';
16-
import {Deletion, ChildDeletion, Placement} from './ReactFiberFlags';
16+
import {
17+
Deletion,
18+
ChildDeletion,
19+
Placement,
20+
StaticMask,
21+
} from './ReactFiberFlags';
1722
import {
1823
getIteratorFn,
1924
REACT_ELEMENT_TYPE,
@@ -275,7 +280,7 @@ function ChildReconciler(shouldTrackSideEffects) {
275280
returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
276281
}
277282
childToDelete.nextEffect = null;
278-
childToDelete.flags = Deletion;
283+
childToDelete.flags = (childToDelete.flags & StaticMask) | Deletion;
279284

280285
let deletions = returnFiber.deletions;
281286
if (deletions === null) {

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import type {Fiber} from './ReactInternalTypes';
1313
import type {Lanes} from './ReactFiberLane.old';
1414

1515
import getComponentName from 'shared/getComponentName';
16-
import {Deletion, ChildDeletion, Placement} from './ReactFiberFlags';
16+
import {
17+
Deletion,
18+
ChildDeletion,
19+
Placement,
20+
StaticMask,
21+
} from './ReactFiberFlags';
1722
import {
1823
getIteratorFn,
1924
REACT_ELEMENT_TYPE,
@@ -275,7 +280,7 @@ function ChildReconciler(shouldTrackSideEffects) {
275280
returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
276281
}
277282
childToDelete.nextEffect = null;
278-
childToDelete.flags = Deletion;
283+
childToDelete.flags = (childToDelete.flags & StaticMask) | Deletion;
279284

280285
let deletions = returnFiber.deletions;
281286
if (deletions === null) {

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,8 @@ function updateSuspensePrimaryChildren(
20072007
if (currentFallbackChildFragment !== null) {
20082008
// Delete the fallback child fragment
20092009
currentFallbackChildFragment.nextEffect = null;
2010-
currentFallbackChildFragment.flags = Deletion;
2010+
currentFallbackChildFragment.flags =
2011+
(currentFallbackChildFragment.flags & StaticMask) | Deletion;
20112012
workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChildFragment;
20122013
let deletions = workInProgress.deletions;
20132014
if (deletions === null) {
@@ -2998,7 +2999,7 @@ function remountFiber(
29982999
returnFiber.firstEffect = returnFiber.lastEffect = current;
29993000
}
30003001
current.nextEffect = null;
3001-
current.flags = Deletion;
3002+
current.flags = (current.flags & StaticMask) | Deletion;
30023003

30033004
let deletions = returnFiber.deletions;
30043005
if (deletions === null) {

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,8 @@ function updateSuspensePrimaryChildren(
20072007
if (currentFallbackChildFragment !== null) {
20082008
// Delete the fallback child fragment
20092009
currentFallbackChildFragment.nextEffect = null;
2010-
currentFallbackChildFragment.flags = Deletion;
2010+
currentFallbackChildFragment.flags =
2011+
(currentFallbackChildFragment.flags & StaticMask) | Deletion;
20112012
workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChildFragment;
20122013
let deletions = workInProgress.deletions;
20132014
if (deletions === null) {
@@ -2998,7 +2999,7 @@ function remountFiber(
29982999
returnFiber.firstEffect = returnFiber.lastEffect = current;
29993000
}
30003001
current.nextEffect = null;
3001-
current.flags = Deletion;
3002+
current.flags = (current.flags & StaticMask) | Deletion;
30023003

30033004
let deletions = returnFiber.deletions;
30043005
if (deletions === null) {

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

+6-39
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import type {Lanes} from './ReactFiberLane.old';
1212
import type {UpdateQueue} from './ReactUpdateQueue.old';
1313

1414
import * as React from 'react';
15-
import {Update, Snapshot, MountLayoutDev} from './ReactFiberFlags';
15+
import {Update, Snapshot} from './ReactFiberFlags';
1616
import {
1717
debugRenderPhaseSideEffectsForStrictMode,
1818
disableLegacyContext,
1919
enableDebugTracing,
2020
enableSchedulingProfiler,
2121
warnAboutDeprecatedLifecycles,
22-
enableDoubleInvokingEffects,
2322
} from 'shared/ReactFeatureFlags';
2423
import ReactStrictModeWarnings from './ReactStrictModeWarnings.old';
2524
import {isMounted} from './ReactFiberTreeReflection';
@@ -30,7 +29,7 @@ import invariant from 'shared/invariant';
3029
import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols';
3130

3231
import {resolveDefaultProps} from './ReactFiberLazyComponent.old';
33-
import {DebugTracingMode, NoMode, StrictMode} from './ReactTypeOfMode';
32+
import {DebugTracingMode, StrictMode} from './ReactTypeOfMode';
3433

3534
import {
3635
enqueueUpdate,
@@ -891,15 +890,7 @@ function mountClassInstance(
891890
}
892891

893892
if (typeof instance.componentDidMount === 'function') {
894-
if (
895-
__DEV__ &&
896-
enableDoubleInvokingEffects &&
897-
(workInProgress.mode & StrictMode) !== NoMode
898-
) {
899-
workInProgress.flags |= MountLayoutDev | Update;
900-
} else {
901-
workInProgress.flags |= Update;
902-
}
893+
workInProgress.flags |= Update;
903894
}
904895
}
905896

@@ -969,15 +960,7 @@ function resumeMountClassInstance(
969960
// If an update was already in progress, we should schedule an Update
970961
// effect even though we're bailing out, so that cWU/cDU are called.
971962
if (typeof instance.componentDidMount === 'function') {
972-
if (
973-
__DEV__ &&
974-
enableDoubleInvokingEffects &&
975-
(workInProgress.mode & StrictMode) !== NoMode
976-
) {
977-
workInProgress.flags |= MountLayoutDev | Update;
978-
} else {
979-
workInProgress.flags |= Update;
980-
}
963+
workInProgress.flags |= Update;
981964
}
982965
return false;
983966
}
@@ -1020,29 +1003,13 @@ function resumeMountClassInstance(
10201003
}
10211004
}
10221005
if (typeof instance.componentDidMount === 'function') {
1023-
if (
1024-
__DEV__ &&
1025-
enableDoubleInvokingEffects &&
1026-
(workInProgress.mode & StrictMode) !== NoMode
1027-
) {
1028-
workInProgress.flags |= MountLayoutDev | Update;
1029-
} else {
1030-
workInProgress.flags |= Update;
1031-
}
1006+
workInProgress.flags |= Update;
10321007
}
10331008
} else {
10341009
// If an update was already in progress, we should schedule an Update
10351010
// effect even though we're bailing out, so that cWU/cDU are called.
10361011
if (typeof instance.componentDidMount === 'function') {
1037-
if (
1038-
__DEV__ &&
1039-
enableDoubleInvokingEffects &&
1040-
(workInProgress.mode & StrictMode) !== NoMode
1041-
) {
1042-
workInProgress.flags |= MountLayoutDev | Update;
1043-
} else {
1044-
workInProgress.flags |= Update;
1045-
}
1012+
workInProgress.flags |= Update;
10461013
}
10471014

10481015
// If shouldComponentUpdate returned false, we should still update the

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

-115
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
enableFundamentalAPI,
3636
enableSuspenseCallback,
3737
enableScopeAPI,
38-
enableDoubleInvokingEffects,
3938
} from 'shared/ReactFeatureFlags';
4039
import {
4140
FunctionComponent,
@@ -1799,116 +1798,6 @@ function commitResetTextContent(current: Fiber) {
17991798
resetTextContent(current.stateNode);
18001799
}
18011800

1802-
function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
1803-
if (__DEV__ && enableDoubleInvokingEffects) {
1804-
switch (fiber.tag) {
1805-
case FunctionComponent:
1806-
case ForwardRef:
1807-
case SimpleMemoComponent: {
1808-
invokeGuardedCallback(
1809-
null,
1810-
commitHookEffectListMount,
1811-
null,
1812-
HookLayout | HookHasEffect,
1813-
fiber,
1814-
);
1815-
if (hasCaughtError()) {
1816-
const mountError = clearCaughtError();
1817-
captureCommitPhaseError(fiber, mountError);
1818-
}
1819-
break;
1820-
}
1821-
case ClassComponent: {
1822-
const instance = fiber.stateNode;
1823-
invokeGuardedCallback(null, instance.componentDidMount, instance);
1824-
if (hasCaughtError()) {
1825-
const mountError = clearCaughtError();
1826-
captureCommitPhaseError(fiber, mountError);
1827-
}
1828-
break;
1829-
}
1830-
}
1831-
}
1832-
}
1833-
1834-
function invokePassiveEffectMountInDEV(fiber: Fiber): void {
1835-
if (__DEV__ && enableDoubleInvokingEffects) {
1836-
switch (fiber.tag) {
1837-
case FunctionComponent:
1838-
case ForwardRef:
1839-
case SimpleMemoComponent: {
1840-
invokeGuardedCallback(
1841-
null,
1842-
commitHookEffectListMount,
1843-
null,
1844-
HookPassive | HookHasEffect,
1845-
fiber,
1846-
);
1847-
if (hasCaughtError()) {
1848-
const mountError = clearCaughtError();
1849-
captureCommitPhaseError(fiber, mountError);
1850-
}
1851-
break;
1852-
}
1853-
}
1854-
}
1855-
}
1856-
1857-
function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
1858-
if (__DEV__ && enableDoubleInvokingEffects) {
1859-
switch (fiber.tag) {
1860-
case FunctionComponent:
1861-
case ForwardRef:
1862-
case SimpleMemoComponent: {
1863-
invokeGuardedCallback(
1864-
null,
1865-
commitHookEffectListUnmount,
1866-
null,
1867-
HookLayout | HookHasEffect,
1868-
fiber,
1869-
fiber.return,
1870-
);
1871-
if (hasCaughtError()) {
1872-
const unmountError = clearCaughtError();
1873-
captureCommitPhaseError(fiber, unmountError);
1874-
}
1875-
break;
1876-
}
1877-
case ClassComponent: {
1878-
const instance = fiber.stateNode;
1879-
if (typeof instance.componentWillUnmount === 'function') {
1880-
safelyCallComponentWillUnmount(fiber, instance);
1881-
}
1882-
break;
1883-
}
1884-
}
1885-
}
1886-
}
1887-
1888-
function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
1889-
if (__DEV__ && enableDoubleInvokingEffects) {
1890-
switch (fiber.tag) {
1891-
case FunctionComponent:
1892-
case ForwardRef:
1893-
case SimpleMemoComponent: {
1894-
invokeGuardedCallback(
1895-
null,
1896-
commitHookEffectListUnmount,
1897-
null,
1898-
HookPassive | HookHasEffect,
1899-
fiber,
1900-
fiber.return,
1901-
);
1902-
if (hasCaughtError()) {
1903-
const unmountError = clearCaughtError();
1904-
captureCommitPhaseError(fiber, unmountError);
1905-
}
1906-
break;
1907-
}
1908-
}
1909-
}
1910-
}
1911-
19121801
export {
19131802
commitBeforeMutationLifeCycles,
19141803
commitResetTextContent,
@@ -1918,8 +1807,4 @@ export {
19181807
commitLifeCycles,
19191808
commitAttachRef,
19201809
commitDetachRef,
1921-
invokeLayoutEffectMountInDEV,
1922-
invokeLayoutEffectUnmountInDEV,
1923-
invokePassiveEffectMountInDEV,
1924-
invokePassiveEffectUnmountInDEV,
19251810
};

0 commit comments

Comments
 (0)