fix(runtime-core): should not track dynamic children when the user calls a compiled slot inside template expression (#3554)

fix #3548, partial fix for #3569
This commit is contained in:
HcySunYang
2021-05-26 01:33:41 +08:00
committed by GitHub
parent 1526f94edf
commit 201060717d
7 changed files with 175 additions and 34 deletions

View File

@@ -40,7 +40,6 @@ import {
import { RendererNode, RendererElement } from './renderer'
import { NULL_DYNAMIC_COMPONENT } from './helpers/resolveAssets'
import { hmrDirtyComponents } from './hmr'
import { setCompiledSlotRendering } from './helpers/renderSlot'
import { convertLegacyComponent } from './compat/component'
import { convertLegacyVModelProps } from './compat/componentVModel'
import { defineLegacyVNodeProperties } from './compat/renderFn'
@@ -218,7 +217,7 @@ export function closeBlock() {
// Only tracks when this value is > 0
// We are not using a simple boolean because this value may need to be
// incremented/decremented by nested usage of v-once (see below)
let shouldTrack = 1
let isBlockTreeEnabled = 1
/**
* Block tracking sometimes needs to be disabled, for example during the
@@ -237,7 +236,7 @@ let shouldTrack = 1
* @private
*/
export function setBlockTracking(value: number) {
shouldTrack += value
isBlockTreeEnabled += value
}
/**
@@ -263,12 +262,13 @@ export function createBlock(
true /* isBlock: prevent a block from tracking itself */
)
// save current block children on the block vnode
vnode.dynamicChildren = currentBlock || (EMPTY_ARR as any)
vnode.dynamicChildren =
isBlockTreeEnabled > 0 ? currentBlock || (EMPTY_ARR as any) : null
// close block
closeBlock()
// a block is always going to be patched, so track it as a child of its
// parent block
if (shouldTrack > 0 && currentBlock) {
if (isBlockTreeEnabled > 0 && currentBlock) {
currentBlock.push(vnode)
}
return vnode
@@ -458,7 +458,7 @@ function _createVNode(
}
if (
shouldTrack > 0 &&
isBlockTreeEnabled > 0 &&
// avoid a block node from tracking itself
!isBlockNode &&
// has current parent block
@@ -635,9 +635,9 @@ export function normalizeChildren(vnode: VNode, children: unknown) {
const slot = (children as any).default
if (slot) {
// _c marker is added by withCtx() indicating this is a compiled slot
slot._c && setCompiledSlotRendering(1)
slot._c && (slot._d = false)
normalizeChildren(vnode, slot())
slot._c && setCompiledSlotRendering(-1)
slot._c && (slot._d = true)
}
return
} else {