fix(runtime-core): enable block tracking when normalizing plain element with slot children (#1987)
fix #1980
This commit is contained in:
@@ -11,6 +11,8 @@ import { PatchFlags, SlotFlags } from '@vue/shared'
|
||||
import { warn } from '../warning'
|
||||
|
||||
export let isRenderingCompiledSlot = 0
|
||||
export const setCompiledSlotRendering = (n: number) =>
|
||||
(isRenderingCompiledSlot += n)
|
||||
|
||||
/**
|
||||
* Compiler runtime helper for rendering `<slot/>`
|
||||
|
||||
@@ -16,7 +16,7 @@ export function withCtx(
|
||||
ctx: ComponentInternalInstance | null = currentRenderingInstance
|
||||
) {
|
||||
if (!ctx) return fn
|
||||
return function renderFnWithContext() {
|
||||
const renderFnWithContext = (...args: any[]) => {
|
||||
// If a user calls a compiled slot inside a template expression (#1745), it
|
||||
// can mess up block tracking, so by default we need to push a null block to
|
||||
// avoid that. This isn't necessary if rendering a compiled `<slot>`.
|
||||
@@ -25,11 +25,13 @@ export function withCtx(
|
||||
}
|
||||
const owner = currentRenderingInstance
|
||||
setCurrentRenderingInstance(ctx)
|
||||
const res = fn.apply(null, arguments as any)
|
||||
const res = fn(...args)
|
||||
setCurrentRenderingInstance(owner)
|
||||
if (!isRenderingCompiledSlot) {
|
||||
closeBlock()
|
||||
}
|
||||
return res
|
||||
}
|
||||
renderFnWithContext._c = true
|
||||
return renderFnWithContext
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user