Skip to content

Commit

Permalink
Removed skip-error-boundaries modifications from old fork (#19961)
Browse files Browse the repository at this point in the history
Technically this change is unnecessary, since the feature is controlled by a flag, but since we decided not to ship this in v17– I'm going to remove it for now entirely.
  • Loading branch information
Brian Vaughn authored Oct 5, 2020
1 parent 461cd84 commit 44d39c4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 101 deletions.
95 changes: 22 additions & 73 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ const callComponentWillUnmountWithTimer = function(current, instance) {
};

// Capture errors so they don't interrupt unmounting.
function safelyCallComponentWillUnmount(
current: Fiber,
instance: any,
nearestMountedAncestor: Fiber | null,
) {
function safelyCallComponentWillUnmount(current: Fiber, instance: any) {
if (__DEV__) {
invokeGuardedCallback(
null,
Expand All @@ -168,32 +164,32 @@ function safelyCallComponentWillUnmount(
);
if (hasCaughtError()) {
const unmountError = clearCaughtError();
captureCommitPhaseError(current, nearestMountedAncestor, unmountError);
captureCommitPhaseError(current, unmountError);
}
} else {
try {
callComponentWillUnmountWithTimer(current, instance);
} catch (unmountError) {
captureCommitPhaseError(current, nearestMountedAncestor, unmountError);
captureCommitPhaseError(current, unmountError);
}
}
}

function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
function safelyDetachRef(current: Fiber) {
const ref = current.ref;
if (ref !== null) {
if (typeof ref === 'function') {
if (__DEV__) {
invokeGuardedCallback(null, ref, null, null);
if (hasCaughtError()) {
const refError = clearCaughtError();
captureCommitPhaseError(current, nearestMountedAncestor, refError);
captureCommitPhaseError(current, refError);
}
} else {
try {
ref(null);
} catch (refError) {
captureCommitPhaseError(current, nearestMountedAncestor, refError);
captureCommitPhaseError(current, refError);
}
}
} else {
Expand All @@ -202,22 +198,18 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
}
}

function safelyCallDestroy(
current: Fiber,
nearestMountedAncestor: Fiber | null,
destroy: () => void,
) {
function safelyCallDestroy(current: Fiber, destroy: () => void) {
if (__DEV__) {
invokeGuardedCallback(null, destroy, null);
if (hasCaughtError()) {
const error = clearCaughtError();
captureCommitPhaseError(current, nearestMountedAncestor, error);
captureCommitPhaseError(current, error);
}
} else {
try {
destroy();
} catch (error) {
captureCommitPhaseError(current, nearestMountedAncestor, error);
captureCommitPhaseError(current, error);
}
}
}
Expand Down Expand Up @@ -874,7 +866,6 @@ function commitDetachRef(current: Fiber) {
function commitUnmount(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber | null,
renderPriorityLevel: ReactPriorityLevel,
): void {
onCommitUnmount(current);
Expand Down Expand Up @@ -904,10 +895,10 @@ function commitUnmount(
current.mode & ProfileMode
) {
startLayoutEffectTimer();
safelyCallDestroy(current, nearestMountedAncestor, destroy);
safelyCallDestroy(current, destroy);
recordLayoutEffectDuration(current);
} else {
safelyCallDestroy(current, nearestMountedAncestor, destroy);
safelyCallDestroy(current, destroy);
}
}
}
Expand All @@ -918,32 +909,23 @@ function commitUnmount(
return;
}
case ClassComponent: {
safelyDetachRef(current, nearestMountedAncestor);
safelyDetachRef(current);
const instance = current.stateNode;
if (typeof instance.componentWillUnmount === 'function') {
safelyCallComponentWillUnmount(
current,
instance,
nearestMountedAncestor,
);
safelyCallComponentWillUnmount(current, instance);
}
return;
}
case HostComponent: {
safelyDetachRef(current, nearestMountedAncestor);
safelyDetachRef(current);
return;
}
case HostPortal: {
// TODO: this is recursive.
// We are also not using this parent because
// the portal will get pushed immediately.
if (supportsMutation) {
unmountHostComponents(
finishedRoot,
current,
nearestMountedAncestor,
renderPriorityLevel,
);
unmountHostComponents(finishedRoot, current, renderPriorityLevel);
} else if (supportsPersistence) {
emptyPortalContainer(current);
}
Expand Down Expand Up @@ -973,7 +955,7 @@ function commitUnmount(
}
case ScopeComponent: {
if (enableScopeAPI) {
safelyDetachRef(current, nearestMountedAncestor);
safelyDetachRef(current);
}
return;
}
Expand All @@ -983,7 +965,6 @@ function commitUnmount(
function commitNestedUnmounts(
finishedRoot: FiberRoot,
root: Fiber,
nearestMountedAncestor: Fiber | null,
renderPriorityLevel: ReactPriorityLevel,
): void {
// While we're inside a removed host node we don't want to call
Expand All @@ -993,12 +974,7 @@ function commitNestedUnmounts(
// we do an inner loop while we're still inside the host node.
let node: Fiber = root;
while (true) {
commitUnmount(
finishedRoot,
node,
nearestMountedAncestor,
renderPriorityLevel,
);
commitUnmount(finishedRoot, node, renderPriorityLevel);
// Visit children because they may contain more composite or host nodes.
// Skip portals because commitUnmount() currently visits them recursively.
if (
Expand Down Expand Up @@ -1289,7 +1265,6 @@ function insertOrAppendPlacementNode(
function unmountHostComponents(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber | null,
renderPriorityLevel: ReactPriorityLevel,
): void {
// We only have the top Fiber that was deleted but we need to recurse down its
Expand Down Expand Up @@ -1339,12 +1314,7 @@ function unmountHostComponents(
}

if (node.tag === HostComponent || node.tag === HostText) {
commitNestedUnmounts(
finishedRoot,
node,
nearestMountedAncestor,
renderPriorityLevel,
);
commitNestedUnmounts(finishedRoot, node, renderPriorityLevel);
// After all the children have unmounted, it is now safe to remove the
// node from the tree.
if (currentParentIsContainer) {
Expand All @@ -1361,12 +1331,7 @@ function unmountHostComponents(
// Don't visit children because we already visited them.
} else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
const fundamentalNode = node.stateNode.instance;
commitNestedUnmounts(
finishedRoot,
node,
nearestMountedAncestor,
renderPriorityLevel,
);
commitNestedUnmounts(finishedRoot, node, renderPriorityLevel);
// After all the children have unmounted, it is now safe to remove the
// node from the tree.
if (currentParentIsContainer) {
Expand Down Expand Up @@ -1418,12 +1383,7 @@ function unmountHostComponents(
continue;
}
} else {
commitUnmount(
finishedRoot,
node,
nearestMountedAncestor,
renderPriorityLevel,
);
commitUnmount(finishedRoot, node, renderPriorityLevel);
// Visit children because we may find more host components below.
if (node.child !== null) {
node.child.return = node;
Expand Down Expand Up @@ -1453,26 +1413,15 @@ function unmountHostComponents(
function commitDeletion(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber | null,
renderPriorityLevel: ReactPriorityLevel,
): void {
if (supportsMutation) {
// Recursively delete all host nodes from the parent.
// Detach refs and call componentWillUnmount() on the whole subtree.
unmountHostComponents(
finishedRoot,
current,
nearestMountedAncestor,
renderPriorityLevel,
);
unmountHostComponents(finishedRoot, current, renderPriorityLevel);
} else {
// Detach refs and call componentWillUnmount() on the whole subtree.
commitNestedUnmounts(
finishedRoot,
current,
nearestMountedAncestor,
renderPriorityLevel,
);
commitNestedUnmounts(finishedRoot, current, renderPriorityLevel);
}
const alternate = current.alternate;
detachFiberMutation(current);
Expand Down
41 changes: 13 additions & 28 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
enableDebugTracing,
enableSchedulingProfiler,
enableScopeAPI,
skipUnmountedBoundaries,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import invariant from 'shared/invariant';
Expand Down Expand Up @@ -2019,15 +2018,15 @@ function commitRootImpl(root, renderPriorityLevel) {
if (hasCaughtError()) {
invariant(nextEffect !== null, 'Should be working on an effect.');
const error = clearCaughtError();
captureCommitPhaseError(nextEffect, nextEffect.return, error);
captureCommitPhaseError(nextEffect, error);
nextEffect = nextEffect.nextEffect;
}
} else {
try {
commitBeforeMutationEffects();
} catch (error) {
invariant(nextEffect !== null, 'Should be working on an effect.');
captureCommitPhaseError(nextEffect, nextEffect.return, error);
captureCommitPhaseError(nextEffect, error);
nextEffect = nextEffect.nextEffect;
}
}
Expand Down Expand Up @@ -2056,15 +2055,15 @@ function commitRootImpl(root, renderPriorityLevel) {
if (hasCaughtError()) {
invariant(nextEffect !== null, 'Should be working on an effect.');
const error = clearCaughtError();
captureCommitPhaseError(nextEffect, nextEffect.return, error);
captureCommitPhaseError(nextEffect, error);
nextEffect = nextEffect.nextEffect;
}
} else {
try {
commitMutationEffects(root, renderPriorityLevel);
} catch (error) {
invariant(nextEffect !== null, 'Should be working on an effect.');
captureCommitPhaseError(nextEffect, nextEffect.return, error);
captureCommitPhaseError(nextEffect, error);
nextEffect = nextEffect.nextEffect;
}
}
Expand All @@ -2091,15 +2090,15 @@ function commitRootImpl(root, renderPriorityLevel) {
if (hasCaughtError()) {
invariant(nextEffect !== null, 'Should be working on an effect.');
const error = clearCaughtError();
captureCommitPhaseError(nextEffect, nextEffect.return, error);
captureCommitPhaseError(nextEffect, error);
nextEffect = nextEffect.nextEffect;
}
} else {
try {
commitLayoutEffects(root, lanes);
} catch (error) {
invariant(nextEffect !== null, 'Should be working on an effect.');
captureCommitPhaseError(nextEffect, nextEffect.return, error);
captureCommitPhaseError(nextEffect, error);
nextEffect = nextEffect.nextEffect;
}
}
Expand Down Expand Up @@ -2373,12 +2372,7 @@ function commitMutationEffects(
break;
}
case Deletion: {
commitDeletion(
root,
nextEffect,
nextEffect.return,
renderPriorityLevel,
);
commitDeletion(root, nextEffect, renderPriorityLevel);
break;
}
}
Expand Down Expand Up @@ -2589,7 +2583,7 @@ function flushPassiveEffectsImpl() {
if (hasCaughtError()) {
invariant(fiber !== null, 'Should be working on an effect.');
const error = clearCaughtError();
captureCommitPhaseError(fiber, fiber.return, error);
captureCommitPhaseError(fiber, error);
}
resetCurrentDebugFiberInDEV();
} else {
Expand All @@ -2610,7 +2604,7 @@ function flushPassiveEffectsImpl() {
}
} catch (error) {
invariant(fiber !== null, 'Should be working on an effect.');
captureCommitPhaseError(fiber, fiber.return, error);
captureCommitPhaseError(fiber, error);
}
}
}
Expand All @@ -2637,7 +2631,7 @@ function flushPassiveEffectsImpl() {
if (hasCaughtError()) {
invariant(fiber !== null, 'Should be working on an effect.');
const error = clearCaughtError();
captureCommitPhaseError(fiber, fiber.return, error);
captureCommitPhaseError(fiber, error);
}
resetCurrentDebugFiberInDEV();
} else {
Expand All @@ -2659,7 +2653,7 @@ function flushPassiveEffectsImpl() {
}
} catch (error) {
invariant(fiber !== null, 'Should be working on an effect.');
captureCommitPhaseError(fiber, fiber.return, error);
captureCommitPhaseError(fiber, error);
}
}
}
Expand Down Expand Up @@ -2758,24 +2752,15 @@ function captureCommitPhaseErrorOnRoot(
}
}

export function captureCommitPhaseError(
sourceFiber: Fiber,
nearestMountedAncestor: Fiber | null,
error: mixed,
) {
export function captureCommitPhaseError(sourceFiber: Fiber, error: mixed) {
if (sourceFiber.tag === HostRoot) {
// Error was thrown at the root. There is no parent, so the root
// itself should capture it.
captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
return;
}

let fiber = null;
if (skipUnmountedBoundaries) {
fiber = nearestMountedAncestor;
} else {
fiber = sourceFiber.return;
}
let fiber = sourceFiber.return;

while (fiber !== null) {
if (fiber.tag === HostRoot) {
Expand Down

0 comments on commit 44d39c4

Please sign in to comment.