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

fix(runtime-core): non-stable Fragment always need to diff its children #2445

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,46 @@ describe('renderer: optimized mode', () => {
render(null, root)
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)
})
})
7 changes: 6 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,12 @@ function baseCreateRenderer(
false,
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)
}

Expand Down