mirror of https://github.com/vuejs/core.git
fix(runtime-core): should not warn out-of-render slot fn usage when mounting another app in setup (#10125)
close #10124
This commit is contained in:
parent
81d307a1e9
commit
6fa33e67ec
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
createApp,
|
||||
getCurrentInstance,
|
||||
h,
|
||||
nextTick,
|
||||
|
@ -240,4 +241,32 @@ describe('component: slots', () => {
|
|||
await nextTick()
|
||||
expect(spy).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
test('should not warn when mounting another app in setup', () => {
|
||||
const Comp = {
|
||||
setup(_: any, { slots }: any) {
|
||||
return () => slots.default?.()
|
||||
},
|
||||
}
|
||||
|
||||
const mountComp = () => {
|
||||
createApp({
|
||||
setup() {
|
||||
return () => h(Comp, () => 'msg')
|
||||
},
|
||||
}).mount(nodeOps.createElement('div'))
|
||||
}
|
||||
|
||||
const App = {
|
||||
setup() {
|
||||
mountComp()
|
||||
return () => null
|
||||
},
|
||||
}
|
||||
|
||||
createApp(App).mount(nodeOps.createElement('div'))
|
||||
expect(
|
||||
'Slot "default" invoked outside of the render function',
|
||||
).not.toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -97,7 +97,11 @@ const normalizeSlot = (
|
|||
return rawSlot as Slot
|
||||
}
|
||||
const normalized = withCtx((...args: any[]) => {
|
||||
if (__DEV__ && currentInstance) {
|
||||
if (
|
||||
__DEV__ &&
|
||||
currentInstance &&
|
||||
(!ctx || ctx.root === currentInstance.root)
|
||||
) {
|
||||
warn(
|
||||
`Slot "${key}" invoked outside of the render function: ` +
|
||||
`this will not track dependencies used in the slot. ` +
|
||||
|
|
Loading…
Reference in New Issue