Skip to content

Commit a82ef6d

Browse files
authored
Add back skipUnmountedBoundaries flag only for www (#23383)
There are a few internal tests that still need to be updated, so I'm adding this flag back for www only. The desired behavior rolled out to 10% public, so we're confident there are no issues. The open source behavior remains (skipUnmountedBoundaries = true).
1 parent f468816 commit a82ef6d

15 files changed

+48
-4
lines changed

packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('ReactErrorBoundaries', () => {
4242
PropTypes = require('prop-types');
4343
ReactFeatureFlags = require('shared/ReactFeatureFlags');
4444
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
45+
ReactFeatureFlags.skipUnmountedBoundaries = true;
4546
ReactDOM = require('react-dom');
4647
React = require('react');
4748
act = require('jest-react').act;

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
enableSchedulingProfiler,
3636
disableSchedulerTimeoutInWorkLoop,
3737
enableStrictEffects,
38+
skipUnmountedBoundaries,
3839
enableUpdaterTracking,
3940
enableCache,
4041
enableTransitionTracing,
@@ -2537,7 +2538,13 @@ export function captureCommitPhaseError(
25372538
return;
25382539
}
25392540

2540-
let fiber = nearestMountedAncestor;
2541+
let fiber = null;
2542+
if (skipUnmountedBoundaries) {
2543+
fiber = nearestMountedAncestor;
2544+
} else {
2545+
fiber = sourceFiber.return;
2546+
}
2547+
25412548
while (fiber !== null) {
25422549
if (fiber.tag === HostRoot) {
25432550
captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
@@ -2570,9 +2577,14 @@ export function captureCommitPhaseError(
25702577
}
25712578

25722579
if (__DEV__) {
2580+
// TODO: Until we re-land skipUnmountedBoundaries (see #20147), this warning
2581+
// will fire for errors that are thrown by destroy functions inside deleted
2582+
// trees. What it should instead do is propagate the error to the parent of
2583+
// the deleted tree. In the meantime, do not add this warning to the
2584+
// allowlist; this is only for our internal use.
25732585
console.error(
25742586
'Internal React error: Attempted to capture a commit phase error ' +
2575-
'inside a detached tree. This indicates a bug in React. Potential ' +
2587+
'inside a detached tree. This indicates a bug in React. Likely ' +
25762588
'causes include deleting the same fiber more than once, committing an ' +
25772589
'already-finished tree, or an inconsistent return pointer.\n\n' +
25782590
'Error message:\n\n%s',

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
enableSchedulingProfiler,
3636
disableSchedulerTimeoutInWorkLoop,
3737
enableStrictEffects,
38+
skipUnmountedBoundaries,
3839
enableUpdaterTracking,
3940
enableCache,
4041
enableTransitionTracing,
@@ -2537,7 +2538,13 @@ export function captureCommitPhaseError(
25372538
return;
25382539
}
25392540

2540-
let fiber = nearestMountedAncestor;
2541+
let fiber = null;
2542+
if (skipUnmountedBoundaries) {
2543+
fiber = nearestMountedAncestor;
2544+
} else {
2545+
fiber = sourceFiber.return;
2546+
}
2547+
25412548
while (fiber !== null) {
25422549
if (fiber.tag === HostRoot) {
25432550
captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
@@ -2570,9 +2577,14 @@ export function captureCommitPhaseError(
25702577
}
25712578

25722579
if (__DEV__) {
2580+
// TODO: Until we re-land skipUnmountedBoundaries (see #20147), this warning
2581+
// will fire for errors that are thrown by destroy functions inside deleted
2582+
// trees. What it should instead do is propagate the error to the parent of
2583+
// the deleted tree. In the meantime, do not add this warning to the
2584+
// allowlist; this is only for our internal use.
25732585
console.error(
25742586
'Internal React error: Attempted to capture a commit phase error ' +
2575-
'inside a detached tree. This indicates a bug in React. Potential ' +
2587+
'inside a detached tree. This indicates a bug in React. Likely ' +
25762588
'causes include deleting the same fiber more than once, committing an ' +
25772589
'already-finished tree, or an inconsistent return pointer.\n\n' +
25782590
'Error message:\n\n%s',

packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js

+5
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,7 @@ describe('ReactHooksWithNoopRenderer', () => {
23512351
};
23522352
});
23532353

2354+
// @gate skipUnmountedBoundaries
23542355
it('should use the nearest still-mounted boundary if there are no unmounted boundaries', () => {
23552356
act(() => {
23562357
ReactNoop.render(
@@ -2376,6 +2377,7 @@ describe('ReactHooksWithNoopRenderer', () => {
23762377
]);
23772378
});
23782379

2380+
// @gate skipUnmountedBoundaries
23792381
it('should skip unmounted boundaries and use the nearest still-mounted boundary', () => {
23802382
function Conditional({showChildren}) {
23812383
if (showChildren) {
@@ -2418,6 +2420,7 @@ describe('ReactHooksWithNoopRenderer', () => {
24182420
]);
24192421
});
24202422

2423+
// @gate skipUnmountedBoundaries
24212424
it('should call getDerivedStateFromError in the nearest still-mounted boundary', () => {
24222425
function Conditional({showChildren}) {
24232426
if (showChildren) {
@@ -2461,6 +2464,7 @@ describe('ReactHooksWithNoopRenderer', () => {
24612464
]);
24622465
});
24632466

2467+
// @gate skipUnmountedBoundaries
24642468
it('should rethrow error if there are no still-mounted boundaries', () => {
24652469
function Conditional({showChildren}) {
24662470
if (showChildren) {
@@ -3186,6 +3190,7 @@ describe('ReactHooksWithNoopRenderer', () => {
31863190
]);
31873191
});
31883192

3193+
// @gate skipUnmountedBoundaries
31893194
it('catches errors thrown in useLayoutEffect', () => {
31903195
class ErrorBoundary extends React.Component {
31913196
state = {error: null};

packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js

+1
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ describe('ReactIncrementalErrorHandling', () => {
10171017
expect(Scheduler).toFlushAndYield(['Foo']);
10181018
});
10191019

1020+
// @gate skipUnmountedBoundaries
10201021
it('should not attempt to recover an unmounting error boundary', () => {
10211022
class Parent extends React.Component {
10221023
componentWillUnmount() {

packages/shared/ReactFeatureFlags.js

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const enablePersistentOffscreenHostContainer = false;
2828
// like migrating internal callers or performance testing.
2929
// -----------------------------------------------------------------------------
3030

31+
// This rolled out to 10% public in www, so we should be able to land, but some
32+
// internal tests need to be updated. The open source behavior is correct.
33+
export const skipUnmountedBoundaries = true;
34+
3135
// Destroy layout effects for components that are hidden because something
3236
// suspended in an update and recreate them when they are shown again (after the
3337
// suspended boundary has resolved). Note that this should be an uncommon use

packages/shared/forks/ReactFeatureFlags.native-fb.js

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const enableComponentStackLocations = false;
5656
export const enableLegacyFBSupport = false;
5757
export const enableFilterEmptyStringAttributesDOM = false;
5858
export const disableNativeComponentFrames = false;
59+
export const skipUnmountedBoundaries = false;
5960
export const deletedTreeCleanUpLevel = 3;
6061
export const enableSuspenseLayoutEffectSemantics = false;
6162
export const enableGetInspectorDataForInstanceInProduction = true;

packages/shared/forks/ReactFeatureFlags.native-oss.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableComponentStackLocations = false;
4747
export const enableLegacyFBSupport = false;
4848
export const enableFilterEmptyStringAttributesDOM = false;
4949
export const disableNativeComponentFrames = false;
50+
export const skipUnmountedBoundaries = false;
5051
export const deletedTreeCleanUpLevel = 3;
5152
export const enableSuspenseLayoutEffectSemantics = false;
5253
export const enableGetInspectorDataForInstanceInProduction = false;

packages/shared/forks/ReactFeatureFlags.test-renderer.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableComponentStackLocations = true;
4747
export const enableLegacyFBSupport = false;
4848
export const enableFilterEmptyStringAttributesDOM = false;
4949
export const disableNativeComponentFrames = false;
50+
export const skipUnmountedBoundaries = false;
5051
export const deletedTreeCleanUpLevel = 3;
5152
export const enableSuspenseLayoutEffectSemantics = false;
5253
export const enableGetInspectorDataForInstanceInProduction = false;

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const enableComponentStackLocations = false;
4343
export const enableLegacyFBSupport = false;
4444
export const enableFilterEmptyStringAttributesDOM = false;
4545
export const disableNativeComponentFrames = false;
46+
export const skipUnmountedBoundaries = false;
4647
export const deletedTreeCleanUpLevel = 3;
4748
export const enableSuspenseLayoutEffectSemantics = false;
4849
export const enableGetInspectorDataForInstanceInProduction = false;

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableComponentStackLocations = true;
4747
export const enableLegacyFBSupport = false;
4848
export const enableFilterEmptyStringAttributesDOM = false;
4949
export const disableNativeComponentFrames = false;
50+
export const skipUnmountedBoundaries = false;
5051
export const deletedTreeCleanUpLevel = 3;
5152
export const enableSuspenseLayoutEffectSemantics = false;
5253
export const enableGetInspectorDataForInstanceInProduction = false;

packages/shared/forks/ReactFeatureFlags.testing.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableComponentStackLocations = true;
4747
export const enableLegacyFBSupport = false;
4848
export const enableFilterEmptyStringAttributesDOM = false;
4949
export const disableNativeComponentFrames = false;
50+
export const skipUnmountedBoundaries = false;
5051
export const deletedTreeCleanUpLevel = 3;
5152
export const enableSuspenseLayoutEffectSemantics = false;
5253
export const enableGetInspectorDataForInstanceInProduction = false;

packages/shared/forks/ReactFeatureFlags.testing.www.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableComponentStackLocations = true;
4747
export const enableLegacyFBSupport = !__EXPERIMENTAL__;
4848
export const enableFilterEmptyStringAttributesDOM = false;
4949
export const disableNativeComponentFrames = false;
50+
export const skipUnmountedBoundaries = true;
5051
export const deletedTreeCleanUpLevel = 3;
5152
export const enableSuspenseLayoutEffectSemantics = false;
5253
export const enableGetInspectorDataForInstanceInProduction = false;

packages/shared/forks/ReactFeatureFlags.www-dynamic.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const warnAboutSpreadingKeyToJSX = __VARIANT__;
1717
export const disableInputAttributeSyncing = __VARIANT__;
1818
export const enableFilterEmptyStringAttributesDOM = __VARIANT__;
1919
export const enableLegacyFBSupport = __VARIANT__;
20+
export const skipUnmountedBoundaries = __VARIANT__;
2021
export const enableUseRefAccessWarning = __VARIANT__;
2122
export const deletedTreeCleanUpLevel = __VARIANT__ ? 3 : 1;
2223
export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;

packages/shared/forks/ReactFeatureFlags.www.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const {
2424
enableLegacyFBSupport,
2525
deferRenderPhaseUpdateToNextBatch,
2626
enableDebugTracing,
27+
skipUnmountedBoundaries,
2728
createRootStrictEffectsByDefault,
2829
enableUseRefAccessWarning,
2930
disableNativeComponentFrames,

0 commit comments

Comments
 (0)