Skip to content

Commit

Permalink
Simplify unmount logic
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Apr 20, 2021
1 parent 4cdcc88 commit 1f8d6ad
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,6 @@ export function unmount(vnode, parentVNode, skipRemove) {
if (!r.current || r.current === vnode._dom) applyRef(r, null, parentVNode);
}

let dom;
if (!skipRemove && typeof vnode.type != 'function') {
skipRemove = (dom = vnode._dom) != null;
}

// Must be set to `undefined` to properly clean up `_nextDom`
// for which `null` is a valid value. See comment in `create-element.js`
vnode._dom = vnode._nextDom = undefined;

if ((r = vnode._component) != null) {
if (r.componentWillUnmount) {
try {
Expand All @@ -503,11 +494,17 @@ export function unmount(vnode, parentVNode, skipRemove) {

if ((r = vnode._children)) {
for (let i = 0; i < r.length; i++) {
if (r[i]) unmount(r[i], parentVNode, skipRemove);
if (r[i]) {
unmount(r[i], parentVNode, typeof vnode.type != 'function');
}
}
}

if (dom != null) removeNode(dom);
if (!skipRemove && vnode._dom != null) removeNode(vnode._dom);

// Must be set to `undefined` to properly clean up `_nextDom`
// for which `null` is a valid value. See comment in `create-element.js`
vnode._dom = vnode._nextDom = undefined;
}

/** The `.render()` method for a PFC backing instance. */
Expand Down

0 comments on commit 1f8d6ad

Please sign in to comment.