Skip to content

Commit a994a53

Browse files
author
Brian Vaughn
committed
Move skip-unmounting boundaries behavior behind a feature flag
1 parent c74790f commit a994a53

15 files changed

+34
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,7 @@ describe('ReactErrorBoundaries', () => {
24742474
);
24752475
});
24762476

2477+
// @gate skipUnmountedBoundaries
24772478
it('catches errors thrown in componentWillUnmount', () => {
24782479
class LocalErrorBoundary extends React.Component {
24792480
state = {error: null};

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
enableDebugTracing,
3131
enableSchedulingProfiler,
3232
enableScopeAPI,
33+
skipUnmountedBoundaries,
3334
} from 'shared/ReactFeatureFlags';
3435
import ReactSharedInternals from 'shared/ReactSharedInternals';
3536
import invariant from 'shared/invariant';
@@ -2950,7 +2951,13 @@ export function captureCommitPhaseError(
29502951
return;
29512952
}
29522953

2953-
let fiber = nearestMountedAncestor;
2954+
let fiber = null;
2955+
if (skipUnmountedBoundaries) {
2956+
fiber = nearestMountedAncestor;
2957+
} else {
2958+
fiber = sourceFiber.return;
2959+
}
2960+
29542961
while (fiber !== null) {
29552962
if (fiber.tag === HostRoot) {
29562963
captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
enableDebugTracing,
3131
enableSchedulingProfiler,
3232
enableScopeAPI,
33+
skipUnmountedBoundaries,
3334
} from 'shared/ReactFeatureFlags';
3435
import ReactSharedInternals from 'shared/ReactSharedInternals';
3536
import invariant from 'shared/invariant';
@@ -2836,7 +2837,13 @@ export function captureCommitPhaseError(
28362837
return;
28372838
}
28382839

2839-
let fiber = nearestMountedAncestor;
2840+
let fiber = null;
2841+
if (skipUnmountedBoundaries) {
2842+
fiber = nearestMountedAncestor;
2843+
} else {
2844+
fiber = sourceFiber.return;
2845+
}
2846+
28402847
while (fiber !== null) {
28412848
if (fiber.tag === HostRoot) {
28422849
captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,7 @@ describe('ReactHooksWithNoopRenderer', () => {
27982798
]);
27992799
});
28002800

2801+
// @gate skipUnmountedBoundaries
28012802
it('catches errors thrown in useLayoutEffect', () => {
28022803
class ErrorBoundary extends React.Component {
28032804
state = {error: null};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ describe('ReactIncrementalErrorHandling', () => {
961961
expect(Scheduler).toFlushAndYield(['Foo']);
962962
});
963963

964+
// @gate skipUnmountedBoundaries
964965
it('should not attempt to recover an unmounting error boundary', () => {
965966
class Parent extends React.Component {
966967
componentWillUnmount() {

packages/shared/ReactFeatureFlags.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ export const enableComponentStackLocations = true;
9292

9393
export const enableNewReconciler = false;
9494

95+
// Errors that are thrown while unmounting (or after in the case of passive effects)
96+
// should bypass any error boundaries that are also unmounting (or have unmounted)
97+
// and be handled by the nearest still-mounted boundary.
98+
// If there are no still-mounted boundaries, the errors should be rethrown.
99+
export const skipUnmountedBoundaries = false;
100+
95101
// --------------------------
96102
// Future APIs to be deprecated
97103
// --------------------------

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const warnAboutSpreadingKeyToJSX = false;
4343
export const enableComponentStackLocations = false;
4444
export const enableLegacyFBSupport = false;
4545
export const enableFilterEmptyStringAttributesDOM = false;
46+
export const skipUnmountedBoundaries = false;
4647

4748
export const enableNewReconciler = false;
4849
export const deferRenderPhaseUpdateToNextBatch = true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const warnAboutSpreadingKeyToJSX = false;
4242
export const enableComponentStackLocations = false;
4343
export const enableLegacyFBSupport = false;
4444
export const enableFilterEmptyStringAttributesDOM = false;
45+
export const skipUnmountedBoundaries = false;
4546

4647
export const enableNewReconciler = false;
4748
export const deferRenderPhaseUpdateToNextBatch = true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const warnAboutSpreadingKeyToJSX = false;
4242
export const enableComponentStackLocations = true;
4343
export const enableLegacyFBSupport = false;
4444
export const enableFilterEmptyStringAttributesDOM = false;
45+
export const skipUnmountedBoundaries = false;
4546

4647
export const enableNewReconciler = false;
4748
export const deferRenderPhaseUpdateToNextBatch = true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const warnAboutSpreadingKeyToJSX = false;
4242
export const enableComponentStackLocations = false;
4343
export const enableLegacyFBSupport = false;
4444
export const enableFilterEmptyStringAttributesDOM = false;
45+
export const skipUnmountedBoundaries = false;
4546

4647
export const enableNewReconciler = false;
4748
export const deferRenderPhaseUpdateToNextBatch = true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const warnAboutSpreadingKeyToJSX = false;
4242
export const enableComponentStackLocations = true;
4343
export const enableLegacyFBSupport = false;
4444
export const enableFilterEmptyStringAttributesDOM = false;
45+
export const skipUnmountedBoundaries = false;
4546

4647
export const enableNewReconciler = false;
4748
export const deferRenderPhaseUpdateToNextBatch = true;

packages/shared/forks/ReactFeatureFlags.testing.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const warnAboutSpreadingKeyToJSX = false;
4242
export const enableComponentStackLocations = true;
4343
export const enableLegacyFBSupport = false;
4444
export const enableFilterEmptyStringAttributesDOM = false;
45+
export const skipUnmountedBoundaries = false;
4546

4647
export const enableNewReconciler = false;
4748
export const deferRenderPhaseUpdateToNextBatch = true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const warnAboutSpreadingKeyToJSX = false;
4242
export const enableComponentStackLocations = true;
4343
export const enableLegacyFBSupport = !__EXPERIMENTAL__;
4444
export const enableFilterEmptyStringAttributesDOM = false;
45+
export const skipUnmountedBoundaries = __EXPERIMENTAL__;
4546

4647
export const enableNewReconciler = false;
4748
export const deferRenderPhaseUpdateToNextBatch = true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const disableInputAttributeSyncing = __VARIANT__;
1818
export const enableFilterEmptyStringAttributesDOM = __VARIANT__;
1919
export const enableLegacyFBSupport = __VARIANT__;
2020
export const decoupleUpdatePriorityFromScheduler = __VARIANT__;
21+
export const skipUnmountedBoundaries = __VARIANT__;
2122

2223
// Enable this flag to help with concurrent mode debugging.
2324
// It logs information to the console about React scheduling, rendering, and commit phases.

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const {
2626
deferRenderPhaseUpdateToNextBatch,
2727
decoupleUpdatePriorityFromScheduler,
2828
enableDebugTracing,
29+
skipUnmountedBoundaries,
2930
} = dynamicFeatureFlags;
3031

3132
// On WWW, __EXPERIMENTAL__ is used for a new modern build.

0 commit comments

Comments
 (0)