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): handle dynamic children for fragment #1154

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 30 additions & 0 deletions packages/runtime-core/__tests__/vnode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,36 @@ describe('vnode', () => {
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
})

test('with keyed or unkeyed fragment', () => {
const hoist = createVNode('div')
let vnode1
const vnode = (openBlock(),
createBlock('div', null, [
(vnode1 = (openBlock(true),
createBlock(Fragment, null, [
hoist,
/*vnode2*/ createVNode(() => {}, null, 'text')
])))
]))
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
expect(vnode1.dynamicChildren).toStrictEqual(null)
})

test('with stable fragment', () => {
const hoist = createVNode('div')
let vnode1, vnode2
const vnode = (openBlock(),
createBlock('div', null, [
(vnode1 = (openBlock(),
createBlock(Fragment, null, [
hoist,
(vnode2 = createVNode(() => {}, null, 'text'))
])))
]))
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
expect(vnode1.dynamicChildren).toStrictEqual([vnode2])
})

// #1039
// <component :is="foo">{{ bar }}</component>
// - content is compiled as slot
Expand Down
6 changes: 1 addition & 5 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,11 +918,7 @@ function baseCreateRenderer(
optimized
)
} else {
if (
patchFlag > 0 &&
patchFlag & PatchFlags.STABLE_FRAGMENT &&
dynamicChildren
) {
if (dynamicChildren) {
// a stable fragment (template root or <template v-for>) doesn't need to
// patch children order, but it may contain dynamicChildren.
patchBlockChildren(
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
isFunction,
isString,
isObject,
EMPTY_ARR,
extend,
normalizeClass,
normalizeStyle,
Expand Down Expand Up @@ -215,7 +214,7 @@ export function createBlock(
true /* isBlock: prevent a block from tracking itself */
)
// save current block children on the block vnode
vnode.dynamicChildren = currentBlock || EMPTY_ARR
vnode.dynamicChildren = currentBlock
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current block is Array for stable fragment .
The current block is null (openBlock(true)) for unkeyed or keyed fragment.
So only check dynamicChildren if it is null when patch or unmount.

// close block
blockStack.pop()
currentBlock = blockStack[blockStack.length - 1] || null
Expand Down