Skip to content

Commit

Permalink
Wrap CommitHostEffects in runWithFiberInDEV at the same place as try/…
Browse files Browse the repository at this point in the history
…catch
  • Loading branch information
sebmarkbage committed Sep 4, 2024
1 parent 6285367 commit 5e8b486
Showing 1 changed file with 142 additions and 21 deletions.
163 changes: 142 additions & 21 deletions packages/react-reconciler/src/ReactFiberCommitHostEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,25 @@ import {
} from './ReactFiberConfig';
import {captureCommitPhaseError} from './ReactFiberWorkLoop';

import {runWithFiberInDEV} from './ReactCurrentFiber';

export function commitHostMount(finishedWork: Fiber) {
const type = finishedWork.type;
const props = finishedWork.memoizedProps;
const instance: Instance = finishedWork.stateNode;
try {
commitMount(instance, type, props, finishedWork);
if (__DEV__) {
runWithFiberInDEV(
finishedWork,
commitMount,
instance,
type,
props,
finishedWork,
);
} else {
commitMount(instance, type, props, finishedWork);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand All @@ -67,13 +80,25 @@ export function commitHostUpdate(
oldProps: any,
) {
try {
commitUpdate(
finishedWork.stateNode,
finishedWork.type,
oldProps,
newProps,
finishedWork,
);
if (__DEV__) {
runWithFiberInDEV(
finishedWork,
commitUpdate,
finishedWork.stateNode,
finishedWork.type,
oldProps,
newProps,
finishedWork,
);
} else {
commitUpdate(
finishedWork.stateNode,
finishedWork.type,
oldProps,
newProps,
finishedWork,
);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand All @@ -86,7 +111,17 @@ export function commitHostTextUpdate(
) {
const textInstance: TextInstance = finishedWork.stateNode;
try {
commitTextUpdate(textInstance, oldText, newText);
if (__DEV__) {
runWithFiberInDEV(
finishedWork,
commitTextUpdate,
textInstance,
oldText,
newText,
);
} else {
commitTextUpdate(textInstance, oldText, newText);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand All @@ -95,7 +130,11 @@ export function commitHostTextUpdate(
export function commitHostResetTextContent(finishedWork: Fiber) {
const instance: Instance = finishedWork.stateNode;
try {
resetTextContent(instance);
if (__DEV__) {
runWithFiberInDEV(finishedWork, resetTextContent, instance);
} else {
resetTextContent(instance);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand All @@ -105,9 +144,22 @@ export function commitShowHideHostInstance(node: Fiber, isHidden: boolean) {
try {
const instance = node.stateNode;
if (isHidden) {
hideInstance(instance);
if (__DEV__) {
runWithFiberInDEV(node, hideInstance, instance);
} else {
hideInstance(instance);
}
} else {
unhideInstance(node.stateNode, node.memoizedProps);
if (__DEV__) {
runWithFiberInDEV(
node,
unhideInstance,
node.stateNode,
node.memoizedProps,
);
} else {
unhideInstance(node.stateNode, node.memoizedProps);
}
}
} catch (error) {
captureCommitPhaseError(node, node.return, error);
Expand All @@ -118,9 +170,22 @@ export function commitShowHideHostTextInstance(node: Fiber, isHidden: boolean) {
try {
const instance = node.stateNode;
if (isHidden) {
hideTextInstance(instance);
if (__DEV__) {
runWithFiberInDEV(node, hideTextInstance, instance);
} else {
hideTextInstance(instance);
}
} else {
unhideTextInstance(instance, node.memoizedProps);
if (__DEV__) {
runWithFiberInDEV(
node,
unhideTextInstance,
instance,
node.memoizedProps,
);
} else {
unhideTextInstance(instance, node.memoizedProps);
}
}
} catch (error) {
captureCommitPhaseError(node, node.return, error);
Expand Down Expand Up @@ -330,7 +395,11 @@ function commitPlacement(finishedWork: Fiber): void {

export function commitHostPlacement(finishedWork: Fiber) {
try {
commitPlacement(finishedWork);
if (__DEV__) {
runWithFiberInDEV(finishedWork, commitPlacement, finishedWork);
} else {
commitPlacement(finishedWork);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand All @@ -343,7 +412,16 @@ export function commitHostRemoveChildFromContainer(
hostInstance: Instance | TextInstance,
) {
try {
removeChildFromContainer(parentContainer, hostInstance);
if (__DEV__) {
runWithFiberInDEV(
deletedFiber,
removeChildFromContainer,
parentContainer,
hostInstance,
);
} else {
removeChildFromContainer(parentContainer, hostInstance);
}
} catch (error) {
captureCommitPhaseError(deletedFiber, nearestMountedAncestor, error);
}
Expand All @@ -356,7 +434,16 @@ export function commitHostRemoveChild(
hostInstance: Instance | TextInstance,
) {
try {
removeChild(parentInstance, hostInstance);
if (__DEV__) {
runWithFiberInDEV(
deletedFiber,
removeChild,
parentInstance,
hostInstance,
);
} else {
removeChild(parentInstance, hostInstance);
}
} catch (error) {
captureCommitPhaseError(deletedFiber, nearestMountedAncestor, error);
}
Expand All @@ -369,7 +456,16 @@ export function commitHostRootContainerChildren(
const containerInfo = root.containerInfo;
const pendingChildren = root.pendingChildren;
try {
replaceContainerChildren(containerInfo, pendingChildren);
if (__DEV__) {
runWithFiberInDEV(
finishedWork,
replaceContainerChildren,
containerInfo,
pendingChildren,
);
} else {
replaceContainerChildren(containerInfo, pendingChildren);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand All @@ -386,7 +482,16 @@ export function commitHostPortalContainerChildren(
) {
const containerInfo = portal.containerInfo;
try {
replaceContainerChildren(containerInfo, pendingChildren);
if (__DEV__) {
runWithFiberInDEV(
finishedWork,
replaceContainerChildren,
containerInfo,
pendingChildren,
);
} else {
replaceContainerChildren(containerInfo, pendingChildren);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand All @@ -397,7 +502,15 @@ export function commitHostHydratedContainer(
finishedWork: Fiber,
) {
try {
commitHydratedContainer(root.containerInfo);
if (__DEV__) {
runWithFiberInDEV(
finishedWork,
commitHydratedContainer,
root.containerInfo,
);
} else {
commitHydratedContainer(root.containerInfo);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand All @@ -408,7 +521,15 @@ export function commitHostHydratedSuspense(
finishedWork: Fiber,
) {
try {
commitHydratedSuspenseInstance(suspenseInstance);
if (__DEV__) {
runWithFiberInDEV(
finishedWork,
commitHydratedSuspenseInstance,
suspenseInstance,
);
} else {
commitHydratedSuspenseInstance(suspenseInstance);
}
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
Expand Down

0 comments on commit 5e8b486

Please sign in to comment.