Skip to content

Commit 08b8d14

Browse files
committed
Add try/catch to places used to be covered by commitDeletionEffects
1 parent d0c1936 commit 08b8d14

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

packages/react-reconciler/src/ReactFiberCommitHostEffects.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import {
4545
unhideTextInstance,
4646
commitHydratedContainer,
4747
commitHydratedSuspenseInstance,
48+
removeChildFromContainer,
49+
removeChild,
4850
} from './ReactFiberConfig';
4951
import {captureCommitPhaseError} from './ReactFiberWorkLoop';
5052

@@ -334,6 +336,32 @@ export function commitHostPlacement(finishedWork: Fiber) {
334336
}
335337
}
336338

339+
export function commitHostRemoveChildFromContainer(
340+
deletedFiber: Fiber,
341+
nearestMountedAncestor: Fiber,
342+
parentContainer: Container,
343+
hostInstance: Instance | TextInstance,
344+
) {
345+
try {
346+
removeChildFromContainer(parentContainer, hostInstance);
347+
} catch (error) {
348+
captureCommitPhaseError(deletedFiber, nearestMountedAncestor, error);
349+
}
350+
}
351+
352+
export function commitHostRemoveChild(
353+
deletedFiber: Fiber,
354+
nearestMountedAncestor: Fiber,
355+
parentInstance: Instance,
356+
hostInstance: Instance | TextInstance,
357+
) {
358+
try {
359+
removeChild(parentInstance, hostInstance);
360+
} catch (error) {
361+
captureCommitPhaseError(deletedFiber, nearestMountedAncestor, error);
362+
}
363+
}
364+
337365
export function commitHostRootContainerChildren(
338366
root: FiberRoot,
339367
finishedWork: Fiber,

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ import {
114114
supportsHydration,
115115
supportsResources,
116116
supportsSingletons,
117-
removeChild,
118-
removeChildFromContainer,
119117
clearSuspenseBoundary,
120118
clearSuspenseBoundaryFromContainer,
121119
replaceContainerChildren,
@@ -212,6 +210,8 @@ import {
212210
commitHostPortalContainerChildren,
213211
commitHostHydratedContainer,
214212
commitHostHydratedSuspense,
213+
commitHostRemoveChildFromContainer,
214+
commitHostRemoveChild,
215215
} from './ReactFiberCommitHostEffects';
216216

217217
// Used during the commit phase to track the state of the Offscreen component stack.
@@ -1249,12 +1249,16 @@ function commitDeletionEffectsOnFiber(
12491249
// Now that all the child effects have unmounted, we can remove the
12501250
// node from the tree.
12511251
if (hostParentIsContainer) {
1252-
removeChildFromContainer(
1252+
commitHostRemoveChildFromContainer(
1253+
deletedFiber,
1254+
nearestMountedAncestor,
12531255
((hostParent: any): Container),
12541256
(deletedFiber.stateNode: Instance | TextInstance),
12551257
);
12561258
} else {
1257-
removeChild(
1259+
commitHostRemoveChild(
1260+
deletedFiber,
1261+
nearestMountedAncestor,
12581262
((hostParent: any): Instance),
12591263
(deletedFiber.stateNode: Instance | TextInstance),
12601264
);
@@ -1273,9 +1277,17 @@ function commitDeletionEffectsOnFiber(
12731277
if (enableSuspenseCallback) {
12741278
const hydrationCallbacks = finishedRoot.hydrationCallbacks;
12751279
if (hydrationCallbacks !== null) {
1276-
const onDeleted = hydrationCallbacks.onDeleted;
1277-
if (onDeleted) {
1278-
onDeleted((deletedFiber.stateNode: SuspenseInstance));
1280+
try {
1281+
const onDeleted = hydrationCallbacks.onDeleted;
1282+
if (onDeleted) {
1283+
onDeleted((deletedFiber.stateNode: SuspenseInstance));
1284+
}
1285+
} catch (error) {
1286+
captureCommitPhaseError(
1287+
deletedFiber,
1288+
nearestMountedAncestor,
1289+
error,
1290+
);
12791291
}
12801292
}
12811293
}

0 commit comments

Comments
 (0)