Skip to content

Commit bcc1b31

Browse files
committed
Move reportUncaughtErrorInDev to captureCommitPhaseError
reportUncaughtErrorInDev is always followed by captureCommitPhaseError, so we can move it into that function.
1 parent c99c5f1 commit bcc1b31

File tree

4 files changed

+6
-36
lines changed

4 files changed

+6
-36
lines changed

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ let nextEffect: Fiber | null = null;
180180
let inProgressLanes: Lanes | null = null;
181181
let inProgressRoot: FiberRoot | null = null;
182182

183-
function reportUncaughtErrorInDEV(error) {
183+
export function reportUncaughtErrorInDEV(error: mixed) {
184184
// Wrapping each small part of the commit phase into a guarded
185185
// callback is a bit too slow (https://github.com/facebook/react/pull/21666).
186186
// But we rely on it to surface errors to DEV tools like overlays
@@ -221,7 +221,6 @@ function safelyCallCommitHookLayoutEffectListMount(
221221
try {
222222
commitHookEffectListMount(HookLayout, current);
223223
} catch (error) {
224-
reportUncaughtErrorInDEV(error);
225224
captureCommitPhaseError(current, nearestMountedAncestor, error);
226225
}
227226
}
@@ -235,7 +234,6 @@ function safelyCallComponentWillUnmount(
235234
try {
236235
callComponentWillUnmountWithTimer(current, instance);
237236
} catch (error) {
238-
reportUncaughtErrorInDEV(error);
239237
captureCommitPhaseError(current, nearestMountedAncestor, error);
240238
}
241239
}
@@ -249,7 +247,6 @@ function safelyCallComponentDidMount(
249247
try {
250248
instance.componentDidMount();
251249
} catch (error) {
252-
reportUncaughtErrorInDEV(error);
253250
captureCommitPhaseError(current, nearestMountedAncestor, error);
254251
}
255252
}
@@ -259,7 +256,6 @@ function safelyAttachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
259256
try {
260257
commitAttachRef(current);
261258
} catch (error) {
262-
reportUncaughtErrorInDEV(error);
263259
captureCommitPhaseError(current, nearestMountedAncestor, error);
264260
}
265261
}
@@ -285,7 +281,6 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
285281
retVal = ref(null);
286282
}
287283
} catch (error) {
288-
reportUncaughtErrorInDEV(error);
289284
captureCommitPhaseError(current, nearestMountedAncestor, error);
290285
}
291286
if (__DEV__) {
@@ -311,7 +306,6 @@ function safelyCallDestroy(
311306
try {
312307
destroy();
313308
} catch (error) {
314-
reportUncaughtErrorInDEV(error);
315309
captureCommitPhaseError(current, nearestMountedAncestor, error);
316310
}
317311
}
@@ -373,7 +367,6 @@ function commitBeforeMutationEffects_complete() {
373367
try {
374368
commitBeforeMutationEffectsOnFiber(fiber);
375369
} catch (error) {
376-
reportUncaughtErrorInDEV(error);
377370
captureCommitPhaseError(fiber, fiber.return, error);
378371
}
379372
resetCurrentDebugFiberInDEV();
@@ -1926,7 +1919,6 @@ function commitMutationEffects_begin(root: FiberRoot, lanes: Lanes) {
19261919
try {
19271920
commitDeletion(root, childToDelete, fiber);
19281921
} catch (error) {
1929-
reportUncaughtErrorInDEV(error);
19301922
captureCommitPhaseError(childToDelete, fiber, error);
19311923
}
19321924
}
@@ -1949,7 +1941,6 @@ function commitMutationEffects_complete(root: FiberRoot, lanes: Lanes) {
19491941
try {
19501942
commitMutationEffectsOnFiber(fiber, root, lanes);
19511943
} catch (error) {
1952-
reportUncaughtErrorInDEV(error);
19531944
captureCommitPhaseError(fiber, fiber.return, error);
19541945
}
19551946
resetCurrentDebugFiberInDEV();
@@ -2340,7 +2331,6 @@ function commitLayoutMountEffects_complete(
23402331
try {
23412332
commitLayoutEffectOnFiber(root, current, fiber, committedLanes);
23422333
} catch (error) {
2343-
reportUncaughtErrorInDEV(error);
23442334
captureCommitPhaseError(fiber, fiber.return, error);
23452335
}
23462336
resetCurrentDebugFiberInDEV();
@@ -2481,7 +2471,6 @@ function reappearLayoutEffects_complete(subtreeRoot: Fiber) {
24812471
try {
24822472
reappearLayoutEffectsOnFiber(fiber);
24832473
} catch (error) {
2484-
reportUncaughtErrorInDEV(error);
24852474
captureCommitPhaseError(fiber, fiber.return, error);
24862475
}
24872476
resetCurrentDebugFiberInDEV();
@@ -2543,7 +2532,6 @@ function commitPassiveMountEffects_complete(
25432532
try {
25442533
commitPassiveMountOnFiber(root, fiber, committedLanes);
25452534
} catch (error) {
2546-
reportUncaughtErrorInDEV(error);
25472535
captureCommitPhaseError(fiber, fiber.return, error);
25482536
}
25492537
resetCurrentDebugFiberInDEV();
@@ -2945,7 +2933,6 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
29452933
try {
29462934
commitHookEffectListMount(HookLayout | HookHasEffect, fiber);
29472935
} catch (error) {
2948-
reportUncaughtErrorInDEV(error);
29492936
captureCommitPhaseError(fiber, fiber.return, error);
29502937
}
29512938
break;
@@ -2955,7 +2942,6 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
29552942
try {
29562943
instance.componentDidMount();
29572944
} catch (error) {
2958-
reportUncaughtErrorInDEV(error);
29592945
captureCommitPhaseError(fiber, fiber.return, error);
29602946
}
29612947
break;
@@ -2975,7 +2961,6 @@ function invokePassiveEffectMountInDEV(fiber: Fiber): void {
29752961
try {
29762962
commitHookEffectListMount(HookPassive | HookHasEffect, fiber);
29772963
} catch (error) {
2978-
reportUncaughtErrorInDEV(error);
29792964
captureCommitPhaseError(fiber, fiber.return, error);
29802965
}
29812966
break;
@@ -2999,7 +2984,6 @@ function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
29992984
fiber.return,
30002985
);
30012986
} catch (error) {
3002-
reportUncaughtErrorInDEV(error);
30032987
captureCommitPhaseError(fiber, fiber.return, error);
30042988
}
30052989
break;
@@ -3030,7 +3014,6 @@ function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
30303014
fiber.return,
30313015
);
30323016
} catch (error) {
3033-
reportUncaughtErrorInDEV(error);
30343017
captureCommitPhaseError(fiber, fiber.return, error);
30353018
}
30363019
}

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ let nextEffect: Fiber | null = null;
180180
let inProgressLanes: Lanes | null = null;
181181
let inProgressRoot: FiberRoot | null = null;
182182

183-
function reportUncaughtErrorInDEV(error) {
183+
export function reportUncaughtErrorInDEV(error: mixed) {
184184
// Wrapping each small part of the commit phase into a guarded
185185
// callback is a bit too slow (https://github.com/facebook/react/pull/21666).
186186
// But we rely on it to surface errors to DEV tools like overlays
@@ -221,7 +221,6 @@ function safelyCallCommitHookLayoutEffectListMount(
221221
try {
222222
commitHookEffectListMount(HookLayout, current);
223223
} catch (error) {
224-
reportUncaughtErrorInDEV(error);
225224
captureCommitPhaseError(current, nearestMountedAncestor, error);
226225
}
227226
}
@@ -235,7 +234,6 @@ function safelyCallComponentWillUnmount(
235234
try {
236235
callComponentWillUnmountWithTimer(current, instance);
237236
} catch (error) {
238-
reportUncaughtErrorInDEV(error);
239237
captureCommitPhaseError(current, nearestMountedAncestor, error);
240238
}
241239
}
@@ -249,7 +247,6 @@ function safelyCallComponentDidMount(
249247
try {
250248
instance.componentDidMount();
251249
} catch (error) {
252-
reportUncaughtErrorInDEV(error);
253250
captureCommitPhaseError(current, nearestMountedAncestor, error);
254251
}
255252
}
@@ -259,7 +256,6 @@ function safelyAttachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
259256
try {
260257
commitAttachRef(current);
261258
} catch (error) {
262-
reportUncaughtErrorInDEV(error);
263259
captureCommitPhaseError(current, nearestMountedAncestor, error);
264260
}
265261
}
@@ -285,7 +281,6 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
285281
retVal = ref(null);
286282
}
287283
} catch (error) {
288-
reportUncaughtErrorInDEV(error);
289284
captureCommitPhaseError(current, nearestMountedAncestor, error);
290285
}
291286
if (__DEV__) {
@@ -311,7 +306,6 @@ function safelyCallDestroy(
311306
try {
312307
destroy();
313308
} catch (error) {
314-
reportUncaughtErrorInDEV(error);
315309
captureCommitPhaseError(current, nearestMountedAncestor, error);
316310
}
317311
}
@@ -373,7 +367,6 @@ function commitBeforeMutationEffects_complete() {
373367
try {
374368
commitBeforeMutationEffectsOnFiber(fiber);
375369
} catch (error) {
376-
reportUncaughtErrorInDEV(error);
377370
captureCommitPhaseError(fiber, fiber.return, error);
378371
}
379372
resetCurrentDebugFiberInDEV();
@@ -1926,7 +1919,6 @@ function commitMutationEffects_begin(root: FiberRoot, lanes: Lanes) {
19261919
try {
19271920
commitDeletion(root, childToDelete, fiber);
19281921
} catch (error) {
1929-
reportUncaughtErrorInDEV(error);
19301922
captureCommitPhaseError(childToDelete, fiber, error);
19311923
}
19321924
}
@@ -1949,7 +1941,6 @@ function commitMutationEffects_complete(root: FiberRoot, lanes: Lanes) {
19491941
try {
19501942
commitMutationEffectsOnFiber(fiber, root, lanes);
19511943
} catch (error) {
1952-
reportUncaughtErrorInDEV(error);
19531944
captureCommitPhaseError(fiber, fiber.return, error);
19541945
}
19551946
resetCurrentDebugFiberInDEV();
@@ -2340,7 +2331,6 @@ function commitLayoutMountEffects_complete(
23402331
try {
23412332
commitLayoutEffectOnFiber(root, current, fiber, committedLanes);
23422333
} catch (error) {
2343-
reportUncaughtErrorInDEV(error);
23442334
captureCommitPhaseError(fiber, fiber.return, error);
23452335
}
23462336
resetCurrentDebugFiberInDEV();
@@ -2481,7 +2471,6 @@ function reappearLayoutEffects_complete(subtreeRoot: Fiber) {
24812471
try {
24822472
reappearLayoutEffectsOnFiber(fiber);
24832473
} catch (error) {
2484-
reportUncaughtErrorInDEV(error);
24852474
captureCommitPhaseError(fiber, fiber.return, error);
24862475
}
24872476
resetCurrentDebugFiberInDEV();
@@ -2543,7 +2532,6 @@ function commitPassiveMountEffects_complete(
25432532
try {
25442533
commitPassiveMountOnFiber(root, fiber, committedLanes);
25452534
} catch (error) {
2546-
reportUncaughtErrorInDEV(error);
25472535
captureCommitPhaseError(fiber, fiber.return, error);
25482536
}
25492537
resetCurrentDebugFiberInDEV();
@@ -2945,7 +2933,6 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
29452933
try {
29462934
commitHookEffectListMount(HookLayout | HookHasEffect, fiber);
29472935
} catch (error) {
2948-
reportUncaughtErrorInDEV(error);
29492936
captureCommitPhaseError(fiber, fiber.return, error);
29502937
}
29512938
break;
@@ -2955,7 +2942,6 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
29552942
try {
29562943
instance.componentDidMount();
29572944
} catch (error) {
2958-
reportUncaughtErrorInDEV(error);
29592945
captureCommitPhaseError(fiber, fiber.return, error);
29602946
}
29612947
break;
@@ -2975,7 +2961,6 @@ function invokePassiveEffectMountInDEV(fiber: Fiber): void {
29752961
try {
29762962
commitHookEffectListMount(HookPassive | HookHasEffect, fiber);
29772963
} catch (error) {
2978-
reportUncaughtErrorInDEV(error);
29792964
captureCommitPhaseError(fiber, fiber.return, error);
29802965
}
29812966
break;
@@ -2999,7 +2984,6 @@ function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
29992984
fiber.return,
30002985
);
30012986
} catch (error) {
3002-
reportUncaughtErrorInDEV(error);
30032987
captureCommitPhaseError(fiber, fiber.return, error);
30042988
}
30052989
break;
@@ -3030,7 +3014,6 @@ function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
30303014
fiber.return,
30313015
);
30323016
} catch (error) {
3033-
reportUncaughtErrorInDEV(error);
30343017
captureCommitPhaseError(fiber, fiber.return, error);
30353018
}
30363019
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ import {
180180
invokePassiveEffectMountInDEV,
181181
invokeLayoutEffectUnmountInDEV,
182182
invokePassiveEffectUnmountInDEV,
183+
reportUncaughtErrorInDEV,
183184
} from './ReactFiberCommitWork.new';
184185
import {enqueueUpdate} from './ReactUpdateQueue.new';
185186
import {resetContextDependencies} from './ReactFiberNewContext.new';
@@ -2567,6 +2568,7 @@ export function captureCommitPhaseError(
25672568
error: mixed,
25682569
) {
25692570
if (__DEV__) {
2571+
reportUncaughtErrorInDEV(error);
25702572
setIsRunningInsertionEffect(false);
25712573
}
25722574
if (sourceFiber.tag === HostRoot) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ import {
180180
invokePassiveEffectMountInDEV,
181181
invokeLayoutEffectUnmountInDEV,
182182
invokePassiveEffectUnmountInDEV,
183+
reportUncaughtErrorInDEV,
183184
} from './ReactFiberCommitWork.old';
184185
import {enqueueUpdate} from './ReactUpdateQueue.old';
185186
import {resetContextDependencies} from './ReactFiberNewContext.old';
@@ -2567,6 +2568,7 @@ export function captureCommitPhaseError(
25672568
error: mixed,
25682569
) {
25692570
if (__DEV__) {
2571+
reportUncaughtErrorInDEV(error);
25702572
setIsRunningInsertionEffect(false);
25712573
}
25722574
if (sourceFiber.tag === HostRoot) {

0 commit comments

Comments
 (0)