Move reportUncaughtErrorInDev to captureCommitPhaseError
reportUncaughtErrorInDev is always followed by captureCommitPhaseError, so we can move it into that function.
Andrew Clark committed
Apr 8, 2022 at 00:05 UTC
bcc1b3121e3052f88a643eaefe93f300a4bfa7b2
4 files changed
+6
-36
packages/react-reconciler/src/ReactFiberCommitWork.new.js
+1
-18
@@ -180,7 +180,7 @@ let nextEffect: Fiber | null = null;
180
let inProgressLanes: Lanes | null = null;
181
let inProgressRoot: FiberRoot | null = null;
182
183
-function reportUncaughtErrorInDEV(error) {
183
+export function reportUncaughtErrorInDEV(error: mixed) {
184
// Wrapping each small part of the commit phase into a guarded
185
// callback is a bit too slow (https://github.com/facebook/react/pull/21666).
186
// But we rely on it to surface errors to DEV tools like overlays
@@ -221,7 +221,6 @@ function safelyCallCommitHookLayoutEffectListMount(
221
try {
222
commitHookEffectListMount(HookLayout, current);
223
} catch (error) {
224
- reportUncaughtErrorInDEV(error);
224
captureCommitPhaseError(current, nearestMountedAncestor, error);
225
}
226
}
@@ -235,7 +234,6 @@ function safelyCallComponentWillUnmount(
234
try {
235
callComponentWillUnmountWithTimer(current, instance);
236
} catch (error) {
238
- reportUncaughtErrorInDEV(error);
237
captureCommitPhaseError(current, nearestMountedAncestor, error);
238
}
239
}
@@ -249,7 +247,6 @@ function safelyCallComponentDidMount(
247
try {
248
instance.componentDidMount();
249
} catch (error) {
252
- reportUncaughtErrorInDEV(error);
250
captureCommitPhaseError(current, nearestMountedAncestor, error);
251
}
252
}
@@ -259,7 +256,6 @@ function safelyAttachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
256
try {
257
commitAttachRef(current);
258
} catch (error) {
262
- reportUncaughtErrorInDEV(error);
259
captureCommitPhaseError(current, nearestMountedAncestor, error);
260
}
261
}
@@ -285,7 +281,6 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
281
retVal = ref(null);
282
}
283
} catch (error) {
288
- reportUncaughtErrorInDEV(error);
284
captureCommitPhaseError(current, nearestMountedAncestor, error);
285
}
286
if (__DEV__) {
@@ -311,7 +306,6 @@ function safelyCallDestroy(
306
try {
307
destroy();
308
} catch (error) {
314
- reportUncaughtErrorInDEV(error);
309
captureCommitPhaseError(current, nearestMountedAncestor, error);
310
}
311
}
@@ -373,7 +367,6 @@ function commitBeforeMutationEffects_complete() {
367
try {
368
commitBeforeMutationEffectsOnFiber(fiber);
369
} catch (error) {
376
- reportUncaughtErrorInDEV(error);
370
captureCommitPhaseError(fiber, fiber.return, error);
371
}
372
resetCurrentDebugFiberInDEV();
@@ -1926,7 +1919,6 @@ function commitMutationEffects_begin(root: FiberRoot, lanes: Lanes) {
1919
try {
1920
commitDeletion(root, childToDelete, fiber);
1921
} catch (error) {
1929
- reportUncaughtErrorInDEV(error);
1922
captureCommitPhaseError(childToDelete, fiber, error);
1923
}
1924
}
@@ -1949,7 +1941,6 @@ function commitMutationEffects_complete(root: FiberRoot, lanes: Lanes) {
1941
try {
1942
commitMutationEffectsOnFiber(fiber, root, lanes);
1943
} catch (error) {
1952
- reportUncaughtErrorInDEV(error);
1944
captureCommitPhaseError(fiber, fiber.return, error);
1945
}
1946
resetCurrentDebugFiberInDEV();
@@ -2340,7 +2331,6 @@ function commitLayoutMountEffects_complete(
2331
try {
2332
commitLayoutEffectOnFiber(root, current, fiber, committedLanes);
2333
} catch (error) {
2343
- reportUncaughtErrorInDEV(error);
2334
captureCommitPhaseError(fiber, fiber.return, error);
2335
}
2336
resetCurrentDebugFiberInDEV();
@@ -2481,7 +2471,6 @@ function reappearLayoutEffects_complete(subtreeRoot: Fiber) {
2471
try {
2472
reappearLayoutEffectsOnFiber(fiber);
2473
} catch (error) {
2484
- reportUncaughtErrorInDEV(error);
2474
captureCommitPhaseError(fiber, fiber.return, error);
2475
}
2476
resetCurrentDebugFiberInDEV();
@@ -2543,7 +2532,6 @@ function commitPassiveMountEffects_complete(
2532
try {
2533
commitPassiveMountOnFiber(root, fiber, committedLanes);
2534
} catch (error) {
2546
- reportUncaughtErrorInDEV(error);
2535
captureCommitPhaseError(fiber, fiber.return, error);
2536
}
2537
resetCurrentDebugFiberInDEV();
@@ -2945,7 +2933,6 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
2933
try {
2934
commitHookEffectListMount(HookLayout | HookHasEffect, fiber);
2935
} catch (error) {
2948
- reportUncaughtErrorInDEV(error);
2936
captureCommitPhaseError(fiber, fiber.return, error);
2937
}
2938
break;
@@ -2955,7 +2942,6 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
2942
try {
2943
instance.componentDidMount();
2944
} catch (error) {
2958
- reportUncaughtErrorInDEV(error);
2945
captureCommitPhaseError(fiber, fiber.return, error);
2946
}
2947
break;
@@ -2975,7 +2961,6 @@ function invokePassiveEffectMountInDEV(fiber: Fiber): void {
2961
try {
2962
commitHookEffectListMount(HookPassive | HookHasEffect, fiber);
2963
} catch (error) {
2978
- reportUncaughtErrorInDEV(error);
2964
captureCommitPhaseError(fiber, fiber.return, error);
2965
}
2966
break;
@@ -2999,7 +2984,6 @@ function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
2984
fiber.return,
2985
);
2986
} catch (error) {
3002
- reportUncaughtErrorInDEV(error);
2987
captureCommitPhaseError(fiber, fiber.return, error);
2988
}
2989
break;
@@ -3030,7 +3014,6 @@ function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
3014
fiber.return,
3015
);
3016
} catch (error) {
3033
- reportUncaughtErrorInDEV(error);
3017
captureCommitPhaseError(fiber, fiber.return, error);
3018
}
3019
}
packages/react-reconciler/src/ReactFiberCommitWork.old.js
+1
-18
@@ -180,7 +180,7 @@ let nextEffect: Fiber | null = null;
180
let inProgressLanes: Lanes | null = null;
181
let inProgressRoot: FiberRoot | null = null;
182
183
-function reportUncaughtErrorInDEV(error) {
183
+export function reportUncaughtErrorInDEV(error: mixed) {
184
// Wrapping each small part of the commit phase into a guarded
185
// callback is a bit too slow (https://github.com/facebook/react/pull/21666).
186
// But we rely on it to surface errors to DEV tools like overlays
@@ -221,7 +221,6 @@ function safelyCallCommitHookLayoutEffectListMount(
221
try {
222
commitHookEffectListMount(HookLayout, current);
223
} catch (error) {
224
- reportUncaughtErrorInDEV(error);
224
captureCommitPhaseError(current, nearestMountedAncestor, error);
225
}
226
}
@@ -235,7 +234,6 @@ function safelyCallComponentWillUnmount(
234
try {
235
callComponentWillUnmountWithTimer(current, instance);
236
} catch (error) {
238
- reportUncaughtErrorInDEV(error);
237
captureCommitPhaseError(current, nearestMountedAncestor, error);
238
}
239
}
@@ -249,7 +247,6 @@ function safelyCallComponentDidMount(
247
try {
248
instance.componentDidMount();
249
} catch (error) {
252
- reportUncaughtErrorInDEV(error);
250
captureCommitPhaseError(current, nearestMountedAncestor, error);
251
}
252
}
@@ -259,7 +256,6 @@ function safelyAttachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
256
try {
257
commitAttachRef(current);
258
} catch (error) {
262
- reportUncaughtErrorInDEV(error);
259
captureCommitPhaseError(current, nearestMountedAncestor, error);
260
}
261
}
@@ -285,7 +281,6 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
281
retVal = ref(null);
282
}
283
} catch (error) {
288
- reportUncaughtErrorInDEV(error);
284
captureCommitPhaseError(current, nearestMountedAncestor, error);
285
}
286
if (__DEV__) {
@@ -311,7 +306,6 @@ function safelyCallDestroy(
306
try {
307
destroy();
308
} catch (error) {
314
- reportUncaughtErrorInDEV(error);
309
captureCommitPhaseError(current, nearestMountedAncestor, error);
310
}
311
}
@@ -373,7 +367,6 @@ function commitBeforeMutationEffects_complete() {
367
try {
368
commitBeforeMutationEffectsOnFiber(fiber);
369
} catch (error) {
376
- reportUncaughtErrorInDEV(error);
370
captureCommitPhaseError(fiber, fiber.return, error);
371
}
372
resetCurrentDebugFiberInDEV();
@@ -1926,7 +1919,6 @@ function commitMutationEffects_begin(root: FiberRoot, lanes: Lanes) {
1919
try {
1920
commitDeletion(root, childToDelete, fiber);
1921
} catch (error) {
1929
- reportUncaughtErrorInDEV(error);
1922
captureCommitPhaseError(childToDelete, fiber, error);
1923
}
1924
}
@@ -1949,7 +1941,6 @@ function commitMutationEffects_complete(root: FiberRoot, lanes: Lanes) {
1941
try {
1942
commitMutationEffectsOnFiber(fiber, root, lanes);
1943
} catch (error) {
1952
- reportUncaughtErrorInDEV(error);
1944
captureCommitPhaseError(fiber, fiber.return, error);
1945
}
1946
resetCurrentDebugFiberInDEV();
@@ -2340,7 +2331,6 @@ function commitLayoutMountEffects_complete(
2331
try {
2332
commitLayoutEffectOnFiber(root, current, fiber, committedLanes);
2333
} catch (error) {
2343
- reportUncaughtErrorInDEV(error);
2334
captureCommitPhaseError(fiber, fiber.return, error);
2335
}
2336
resetCurrentDebugFiberInDEV();
@@ -2481,7 +2471,6 @@ function reappearLayoutEffects_complete(subtreeRoot: Fiber) {
2471
try {
2472
reappearLayoutEffectsOnFiber(fiber);
2473
} catch (error) {
2484
- reportUncaughtErrorInDEV(error);
2474
captureCommitPhaseError(fiber, fiber.return, error);
2475
}
2476
resetCurrentDebugFiberInDEV();
@@ -2543,7 +2532,6 @@ function commitPassiveMountEffects_complete(
2532
try {
2533
commitPassiveMountOnFiber(root, fiber, committedLanes);
2534
} catch (error) {
2546
- reportUncaughtErrorInDEV(error);
2535
captureCommitPhaseError(fiber, fiber.return, error);
2536
}
2537
resetCurrentDebugFiberInDEV();
@@ -2945,7 +2933,6 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
2933
try {
2934
commitHookEffectListMount(HookLayout | HookHasEffect, fiber);
2935
} catch (error) {
2948
- reportUncaughtErrorInDEV(error);
2936
captureCommitPhaseError(fiber, fiber.return, error);
2937
}
2938
break;
@@ -2955,7 +2942,6 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
2942
try {
2943
instance.componentDidMount();
2944
} catch (error) {
2958
- reportUncaughtErrorInDEV(error);
2945
captureCommitPhaseError(fiber, fiber.return, error);
2946
}
2947
break;
@@ -2975,7 +2961,6 @@ function invokePassiveEffectMountInDEV(fiber: Fiber): void {
2961
try {
2962
commitHookEffectListMount(HookPassive | HookHasEffect, fiber);
2963
} catch (error) {
2978
- reportUncaughtErrorInDEV(error);
2964
captureCommitPhaseError(fiber, fiber.return, error);
2965
}
2966
break;
@@ -2999,7 +2984,6 @@ function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
2984
fiber.return,
2985
);
2986
} catch (error) {
3002
- reportUncaughtErrorInDEV(error);
2987
captureCommitPhaseError(fiber, fiber.return, error);
2988
}
2989
break;
@@ -3030,7 +3014,6 @@ function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
3014
fiber.return,
3015
);
3016
} catch (error) {
3033
- reportUncaughtErrorInDEV(error);
3017
captureCommitPhaseError(fiber, fiber.return, error);
3018
}
3019
}
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+2
@@ -180,6 +180,7 @@ import {
180
invokePassiveEffectMountInDEV,
181
invokeLayoutEffectUnmountInDEV,
182
invokePassiveEffectUnmountInDEV,
183
+ reportUncaughtErrorInDEV,
184
} from './ReactFiberCommitWork.new';
185
import {enqueueUpdate} from './ReactUpdateQueue.new';
186
import {resetContextDependencies} from './ReactFiberNewContext.new';
@@ -2567,6 +2568,7 @@ export function captureCommitPhaseError(
2568
error: mixed,
2569
) {
2570
if (__DEV__) {
2571
+ reportUncaughtErrorInDEV(error);
2572
setIsRunningInsertionEffect(false);
2573
}
2574
if (sourceFiber.tag === HostRoot) {
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+2
@@ -180,6 +180,7 @@ import {
180
invokePassiveEffectMountInDEV,
181
invokeLayoutEffectUnmountInDEV,
182
invokePassiveEffectUnmountInDEV,
183
+ reportUncaughtErrorInDEV,
184
} from './ReactFiberCommitWork.old';
185
import {enqueueUpdate} from './ReactUpdateQueue.old';
186
import {resetContextDependencies} from './ReactFiberNewContext.old';
@@ -2567,6 +2568,7 @@ export function captureCommitPhaseError(
2568
error: mixed,
2569
) {
2570
if (__DEV__) {
2571
+ reportUncaughtErrorInDEV(error);
2572
setIsRunningInsertionEffect(false);
2573
}
2574
if (sourceFiber.tag === HostRoot) {