Skip to content

Commit

Permalink
Optimization: avoid looping to find dom element when
Browse files Browse the repository at this point in the history
componentWillUnmount and componentWillDisappear are not defined
  • Loading branch information
Havunen committed Apr 26, 2022
1 parent b9e689a commit 1170cea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/inferno/src/DOM/unmounting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ export function unmount(vNode, animations: AnimationQueues) {
let childAnimations = animations;
ref = vNode.ref;
if (!isNullOrUndef(ref)) {
const domEl = findDOMfromVNode(vNode, true) as Element;
let domEl : Element | null = null;

if (isFunction(ref.onComponentWillUnmount)) {
domEl = findDOMFromVNode(vNode, true);
ref.onComponentWillUnmount(domEl, vNode.props || EMPTY_OBJ);
}
if (isFunction(ref.onComponentWillDisappear)) {
childAnimations = new AnimationQueues();
addDisappearAnimationHook(animations, ref, domEl, flags, vNode.props);
domEl = domEl || findDOMFromVNode(vNode, true);
addDisappearAnimationHook(animations, ref, domEl as Element, flags, vNode.props);
}
}
unmount(children, childAnimations);
Expand Down

0 comments on commit 1170cea

Please sign in to comment.