chore: fix vdom slots currentInstance

This commit is contained in:
Evan You 2024-12-08 16:41:53 +08:00
parent e8067f1cd9
commit 6c4018652b
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
1 changed files with 12 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import { type ComponentInternalInstance, getCurrentInstance } from './component' import { type ComponentInternalInstance, currentInstance } from './component'
import { import {
type VNode, type VNode,
type VNodeChild, type VNodeChild,
@ -94,15 +94,17 @@ const normalizeSlot = (
return rawSlot as Slot return rawSlot as Slot
} }
const normalized = withCtx((...args: any[]) => { const normalized = withCtx((...args: any[]) => {
if (__DEV__) { if (
const currentInstance = getCurrentInstance() __DEV__ &&
if (currentInstance && (!ctx || ctx.root === currentInstance.root)) { currentInstance &&
warn( !currentInstance.vapor &&
`Slot "${key}" invoked outside of the render function: ` + (!ctx || ctx.root === (currentInstance as ComponentInternalInstance).root)
`this will not track dependencies used in the slot. ` + ) {
`Invoke the slot function inside the render function instead.`, warn(
) `Slot "${key}" invoked outside of the render function: ` +
} `this will not track dependencies used in the slot. ` +
`Invoke the slot function inside the render function instead.`,
)
} }
return normalizeSlotValue(rawSlot(...args)) return normalizeSlotValue(rawSlot(...args))
}, ctx) as Slot }, ctx) as Slot