fix(runtime-core): correctly track dynamic nodes in renderSlot (#1911)

This commit is contained in:
HcySunYang 2020-08-20 21:37:26 +08:00 committed by GitHub
parent 91c4735416
commit 7ffb79c563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -10,7 +10,7 @@ import {
import { PatchFlags, SlotFlags } from '@vue/shared' import { PatchFlags, SlotFlags } from '@vue/shared'
import { warn } from '../warning' import { warn } from '../warning'
export let isRenderingTemplateSlot = false export let shouldTrackInSlotRendering = 0
/** /**
* Compiler runtime helper for rendering `<slot/>` * Compiler runtime helper for rendering `<slot/>`
@ -39,7 +39,7 @@ export function renderSlot(
// invocation interfering with template-based block tracking, but in // invocation interfering with template-based block tracking, but in
// `renderSlot` we can be sure that it's template-based so we can force // `renderSlot` we can be sure that it's template-based so we can force
// enable it. // enable it.
isRenderingTemplateSlot = true shouldTrackInSlotRendering++
const rendered = (openBlock(), const rendered = (openBlock(),
createBlock( createBlock(
Fragment, Fragment,
@ -49,6 +49,6 @@ export function renderSlot(
? PatchFlags.STABLE_FRAGMENT ? PatchFlags.STABLE_FRAGMENT
: PatchFlags.BAIL : PatchFlags.BAIL
)) ))
isRenderingTemplateSlot = false shouldTrackInSlotRendering--
return rendered return rendered
} }

View File

@ -36,7 +36,7 @@ import { currentRenderingInstance } from './componentRenderUtils'
import { RendererNode, RendererElement } from './renderer' import { RendererNode, RendererElement } from './renderer'
import { NULL_DYNAMIC_COMPONENT } from './helpers/resolveAssets' import { NULL_DYNAMIC_COMPONENT } from './helpers/resolveAssets'
import { hmrDirtyComponents } from './hmr' import { hmrDirtyComponents } from './hmr'
import { isRenderingTemplateSlot } from './helpers/renderSlot' import { shouldTrackInSlotRendering } from './helpers/renderSlot'
export const Fragment = (Symbol(__DEV__ ? 'Fragment' : undefined) as any) as { export const Fragment = (Symbol(__DEV__ ? 'Fragment' : undefined) as any) as {
__isFragment: true __isFragment: true
@ -403,7 +403,7 @@ function _createVNode(
normalizeChildren(vnode, children) normalizeChildren(vnode, children)
if ( if (
(shouldTrack > 0 || isRenderingTemplateSlot) && (shouldTrack > 0 || shouldTrackInSlotRendering > 0) &&
// avoid a block node from tracking itself // avoid a block node from tracking itself
!isBlockNode && !isBlockNode &&
// has current parent block // has current parent block