Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing param to safelyCallDestroy() #19638

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,11 @@ function commitBeforeMutationLifeCycles(
);
}

function commitHookEffectListUnmount(tag: HookEffectTag, finishedWork: Fiber) {
function commitHookEffectListUnmount(
tag: HookEffectTag,
finishedWork: Fiber,
nearestMountedAncestor: Fiber | null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding this as a new param (rather than making this function call finishedWork.return) because commitHookEffectListUnmount and commitHookEffectListUnmount2 will eventually be merged– and then passive effects will be involved as well.

) {
const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);
const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
if (lastEffect !== null) {
Expand All @@ -335,7 +339,7 @@ function commitHookEffectListUnmount(tag: HookEffectTag, finishedWork: Fiber) {
const destroy = effect.destroy;
effect.destroy = undefined;
if (destroy !== undefined) {
safelyCallDestroy(finishedWork, destroy);
safelyCallDestroy(finishedWork, nearestMountedAncestor, destroy);
}
}
effect = effect.next;
Expand Down Expand Up @@ -1598,12 +1602,17 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
commitHookEffectListUnmount(
HookLayout | HookHasEffect,
finishedWork,
finishedWork.return,
Copy link
Contributor Author

@bvaughn bvaughn Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to pass finishedWork.return here because none of these calls get made within the context of an unmounted/unmounting tree.

);
} finally {
recordLayoutEffectDuration(finishedWork);
}
} else {
commitHookEffectListUnmount(HookLayout | HookHasEffect, finishedWork);
commitHookEffectListUnmount(
HookLayout | HookHasEffect,
finishedWork,
finishedWork.return,
);
}
return;
}
Expand Down Expand Up @@ -1658,12 +1667,20 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
) {
try {
startLayoutEffectTimer();
commitHookEffectListUnmount(HookLayout | HookHasEffect, finishedWork);
commitHookEffectListUnmount(
HookLayout | HookHasEffect,
finishedWork,
finishedWork.return,
);
} finally {
recordLayoutEffectDuration(finishedWork);
}
} else {
commitHookEffectListUnmount(HookLayout | HookHasEffect, finishedWork);
commitHookEffectListUnmount(
HookLayout | HookHasEffect,
finishedWork,
finishedWork.return,
);
}
return;
}
Expand Down