fix(runtime-core): non-stable Fragment should always unmount its children (#2445)
fix #2444
This commit is contained in:
parent
0227b4a697
commit
fff62e2ee8
@ -475,4 +475,46 @@ describe('renderer: optimized mode', () => {
|
|||||||
render(null, root)
|
render(null, root)
|
||||||
expect(spy).toHaveBeenCalledTimes(1)
|
expect(spy).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #2444
|
||||||
|
// `KEYED_FRAGMENT` and `UNKEYED_FRAGMENT` always need to diff its children
|
||||||
|
test('non-stable Fragment always need to diff its children', () => {
|
||||||
|
const spyA = jest.fn()
|
||||||
|
const spyB = jest.fn()
|
||||||
|
const ChildA = {
|
||||||
|
setup() {
|
||||||
|
onBeforeUnmount(spyA)
|
||||||
|
return () => 'child'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const ChildB = {
|
||||||
|
setup() {
|
||||||
|
onBeforeUnmount(spyB)
|
||||||
|
return () => 'child'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const Parent = () => (
|
||||||
|
openBlock(),
|
||||||
|
createBlock('div', null, [
|
||||||
|
(openBlock(true),
|
||||||
|
createBlock(
|
||||||
|
Fragment,
|
||||||
|
null,
|
||||||
|
[createVNode(ChildA, { key: 0 })],
|
||||||
|
128 /* KEYED_FRAGMENT */
|
||||||
|
)),
|
||||||
|
(openBlock(true),
|
||||||
|
createBlock(
|
||||||
|
Fragment,
|
||||||
|
null,
|
||||||
|
[createVNode(ChildB)],
|
||||||
|
256 /* UNKEYED_FRAGMENT */
|
||||||
|
))
|
||||||
|
])
|
||||||
|
)
|
||||||
|
render(h(Parent), root)
|
||||||
|
render(null, root)
|
||||||
|
expect(spyA).toHaveBeenCalledTimes(1)
|
||||||
|
expect(spyB).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -2038,7 +2038,12 @@ function baseCreateRenderer(
|
|||||||
false,
|
false,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
} else if (!optimized && shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
} else if (
|
||||||
|
(type === Fragment &&
|
||||||
|
(patchFlag & PatchFlags.KEYED_FRAGMENT ||
|
||||||
|
patchFlag & PatchFlags.UNKEYED_FRAGMENT)) ||
|
||||||
|
(!optimized && shapeFlag & ShapeFlags.ARRAY_CHILDREN)
|
||||||
|
) {
|
||||||
unmountChildren(children as VNode[], parentComponent, parentSuspense)
|
unmountChildren(children as VNode[], parentComponent, parentSuspense)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user