Skip to content

Commit

Permalink
refactor: handle dynamic children for fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed May 10, 2020
1 parent b725b63 commit 19482a2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
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
// close block
blockStack.pop()
currentBlock = blockStack[blockStack.length - 1] || null
Expand Down

0 comments on commit 19482a2

Please sign in to comment.