fix(runtime-core): fix dynamic node tracking in dynamic component that resolves to plain elements
fix #1039
This commit is contained in:
parent
fa216a0c3a
commit
dcf2458fa8
@ -337,6 +337,27 @@ describe('vnode', () => {
|
|||||||
]))
|
]))
|
||||||
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #1039
|
||||||
|
// <component :is="foo">{{ bar }}</component>
|
||||||
|
// - content is compiled as slot
|
||||||
|
// - dynamic component reoslves to plain element, but as a block
|
||||||
|
// - block creation disables its own tracking, accidentally causing the
|
||||||
|
// slot content (called during the block node creation) to be missed
|
||||||
|
test('element block should track normalized slot children', () => {
|
||||||
|
const hoist = createVNode('div')
|
||||||
|
let vnode1
|
||||||
|
const vnode = (openBlock(),
|
||||||
|
createBlock('div', null, {
|
||||||
|
default: () => {
|
||||||
|
return [
|
||||||
|
hoist,
|
||||||
|
(vnode1 = createVNode('div', null, 'text', PatchFlags.TEXT))
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
expect(vnode.dynamicChildren).toStrictEqual([vnode1])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('transformVNodeArgs', () => {
|
describe('transformVNodeArgs', () => {
|
||||||
|
@ -177,10 +177,14 @@ export function createBlock(
|
|||||||
patchFlag?: number,
|
patchFlag?: number,
|
||||||
dynamicProps?: string[]
|
dynamicProps?: string[]
|
||||||
): VNode {
|
): VNode {
|
||||||
// avoid a block with patchFlag tracking itself
|
const vnode = createVNode(
|
||||||
shouldTrack--
|
type,
|
||||||
const vnode = createVNode(type, props, children, patchFlag, dynamicProps)
|
props,
|
||||||
shouldTrack++
|
children,
|
||||||
|
patchFlag,
|
||||||
|
dynamicProps,
|
||||||
|
true /* isBlock: prevent a block from tracking itself */
|
||||||
|
)
|
||||||
// save current block children on the block vnode
|
// save current block children on the block vnode
|
||||||
vnode.dynamicChildren = currentBlock || EMPTY_ARR
|
vnode.dynamicChildren = currentBlock || EMPTY_ARR
|
||||||
// close block
|
// close block
|
||||||
@ -244,7 +248,8 @@ function _createVNode(
|
|||||||
props: (Data & VNodeProps) | null = null,
|
props: (Data & VNodeProps) | null = null,
|
||||||
children: unknown = null,
|
children: unknown = null,
|
||||||
patchFlag: number = 0,
|
patchFlag: number = 0,
|
||||||
dynamicProps: string[] | null = null
|
dynamicProps: string[] | null = null,
|
||||||
|
isBlockNode = false
|
||||||
): VNode {
|
): VNode {
|
||||||
if (!type) {
|
if (!type) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
@ -337,6 +342,7 @@ function _createVNode(
|
|||||||
// the next vnode so that it can be properly unmounted later.
|
// the next vnode so that it can be properly unmounted later.
|
||||||
if (
|
if (
|
||||||
shouldTrack > 0 &&
|
shouldTrack > 0 &&
|
||||||
|
!isBlockNode &&
|
||||||
currentBlock &&
|
currentBlock &&
|
||||||
// the EVENTS flag is only for hydration and if it is the only flag, the
|
// the EVENTS flag is only for hydration and if it is the only flag, the
|
||||||
// vnode should not be considered dynamic due to handler caching.
|
// vnode should not be considered dynamic due to handler caching.
|
||||||
|
Loading…
Reference in New Issue
Block a user