Skip to content

Commit

Permalink
Add try/catch to places used to be covered by commitDeletionEffects
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Sep 4, 2024
1 parent d0c1936 commit 08b8d14
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
28 changes: 28 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitHostEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import {
unhideTextInstance,
commitHydratedContainer,
commitHydratedSuspenseInstance,
removeChildFromContainer,
removeChild,
} from './ReactFiberConfig';
import {captureCommitPhaseError} from './ReactFiberWorkLoop';

Expand Down Expand Up @@ -334,6 +336,32 @@ export function commitHostPlacement(finishedWork: Fiber) {
}
}

export function commitHostRemoveChildFromContainer(
deletedFiber: Fiber,
nearestMountedAncestor: Fiber,
parentContainer: Container,
hostInstance: Instance | TextInstance,
) {
try {
removeChildFromContainer(parentContainer, hostInstance);
} catch (error) {
captureCommitPhaseError(deletedFiber, nearestMountedAncestor, error);
}
}

export function commitHostRemoveChild(
deletedFiber: Fiber,
nearestMountedAncestor: Fiber,
parentInstance: Instance,
hostInstance: Instance | TextInstance,
) {
try {
removeChild(parentInstance, hostInstance);
} catch (error) {
captureCommitPhaseError(deletedFiber, nearestMountedAncestor, error);
}
}

export function commitHostRootContainerChildren(
root: FiberRoot,
finishedWork: Fiber,
Expand Down
26 changes: 19 additions & 7 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ import {
supportsHydration,
supportsResources,
supportsSingletons,
removeChild,
removeChildFromContainer,
clearSuspenseBoundary,
clearSuspenseBoundaryFromContainer,
replaceContainerChildren,
Expand Down Expand Up @@ -212,6 +210,8 @@ import {
commitHostPortalContainerChildren,
commitHostHydratedContainer,
commitHostHydratedSuspense,
commitHostRemoveChildFromContainer,
commitHostRemoveChild,
} from './ReactFiberCommitHostEffects';

// Used during the commit phase to track the state of the Offscreen component stack.
Expand Down Expand Up @@ -1249,12 +1249,16 @@ function commitDeletionEffectsOnFiber(
// Now that all the child effects have unmounted, we can remove the
// node from the tree.
if (hostParentIsContainer) {
removeChildFromContainer(
commitHostRemoveChildFromContainer(
deletedFiber,
nearestMountedAncestor,
((hostParent: any): Container),
(deletedFiber.stateNode: Instance | TextInstance),
);
} else {
removeChild(
commitHostRemoveChild(
deletedFiber,
nearestMountedAncestor,
((hostParent: any): Instance),
(deletedFiber.stateNode: Instance | TextInstance),
);
Expand All @@ -1273,9 +1277,17 @@ function commitDeletionEffectsOnFiber(
if (enableSuspenseCallback) {
const hydrationCallbacks = finishedRoot.hydrationCallbacks;
if (hydrationCallbacks !== null) {
const onDeleted = hydrationCallbacks.onDeleted;
if (onDeleted) {
onDeleted((deletedFiber.stateNode: SuspenseInstance));
try {
const onDeleted = hydrationCallbacks.onDeleted;
if (onDeleted) {
onDeleted((deletedFiber.stateNode: SuspenseInstance));
}
} catch (error) {
captureCommitPhaseError(
deletedFiber,
nearestMountedAncestor,
error,
);
}
}
}
Expand Down

0 comments on commit 08b8d14

Please sign in to comment.