nextTick,
defineComponent,
withCtx,
- renderSlot
+ renderSlot,
+ onBeforeUnmount
} from '@vue/runtime-test'
import { PatchFlags, SlotFlags } from '@vue/shared'
expect(inner(root)).toBe('<div><p>1</p></div>')
})
+
+ // #2169
+ // block
+ // - dynamic child (1)
+ // - component (2)
+ // When unmounting (1), we know we are in optimized mode so no need to further
+ // traverse unmount its children
+ test('should not perform unnecessary unmount traversals', () => {
+ const spy = jest.fn()
+ const Child = {
+ setup() {
+ onBeforeUnmount(spy)
+ return () => 'child'
+ }
+ }
+ const Parent = () => (
+ openBlock(),
+ createBlock('div', null, [
+ createVNode('div', { style: {} }, [createVNode(Child)], 4 /* STYLE */)
+ ])
+ )
+ render(h(Parent), root)
+ render(null, root)
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
})
vnode: VNode,
parentComponent: ComponentInternalInstance | null,
parentSuspense: SuspenseBoundary | null,
- doRemove?: boolean
+ doRemove?: boolean,
+ optimized?: boolean
) => void
type RemoveFn = (vnode: VNode) => void
parentComponent: ComponentInternalInstance | null,
parentSuspense: SuspenseBoundary | null,
doRemove?: boolean,
+ optimized?: boolean,
start?: number
) => void
}
if (oldLength > newLength) {
// remove old
- unmountChildren(c1, parentComponent, parentSuspense, true, commonLength)
+ unmountChildren(
+ c1,
+ parentComponent,
+ parentSuspense,
+ true,
+ false,
+ commonLength
+ )
} else {
// mount new
mountChildren(
vnode,
parentComponent,
parentSuspense,
- doRemove = false
+ doRemove = false,
+ optimized = false
) => {
const {
type,
(patchFlag > 0 && patchFlag & PatchFlags.STABLE_FRAGMENT))
) {
// fast path for block nodes: only need to unmount dynamic children.
- unmountChildren(dynamicChildren, parentComponent, parentSuspense)
- } else if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
+ unmountChildren(
+ dynamicChildren,
+ parentComponent,
+ parentSuspense,
+ false,
+ true
+ )
+ } else if (!optimized && shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
unmountChildren(children as VNode[], parentComponent, parentSuspense)
}
parentComponent,
parentSuspense,
doRemove = false,
+ optimized = false,
start = 0
) => {
for (let i = start; i < children.length; i++) {
- unmount(children[i], parentComponent, parentSuspense, doRemove)
+ unmount(children[i], parentComponent, parentSuspense, doRemove, optimized)
}
}