Skip to content

Commit 6fa33e6

Browse files
authored
fix(runtime-core): should not warn out-of-render slot fn usage when mounting another app in setup (#10125)
close #10124
1 parent 81d307a commit 6fa33e6

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/runtime-core/__tests__/componentSlots.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
createApp,
23
getCurrentInstance,
34
h,
45
nextTick,
@@ -240,4 +241,32 @@ describe('component: slots', () => {
240241
await nextTick()
241242
expect(spy).toHaveBeenCalledTimes(2)
242243
})
244+
245+
test('should not warn when mounting another app in setup', () => {
246+
const Comp = {
247+
setup(_: any, { slots }: any) {
248+
return () => slots.default?.()
249+
},
250+
}
251+
252+
const mountComp = () => {
253+
createApp({
254+
setup() {
255+
return () => h(Comp, () => 'msg')
256+
},
257+
}).mount(nodeOps.createElement('div'))
258+
}
259+
260+
const App = {
261+
setup() {
262+
mountComp()
263+
return () => null
264+
},
265+
}
266+
267+
createApp(App).mount(nodeOps.createElement('div'))
268+
expect(
269+
'Slot "default" invoked outside of the render function',
270+
).not.toHaveBeenWarned()
271+
})
243272
})

packages/runtime-core/src/componentSlots.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ const normalizeSlot = (
9797
return rawSlot as Slot
9898
}
9999
const normalized = withCtx((...args: any[]) => {
100-
if (__DEV__ && currentInstance) {
100+
if (
101+
__DEV__ &&
102+
currentInstance &&
103+
(!ctx || ctx.root === currentInstance.root)
104+
) {
101105
warn(
102106
`Slot "${key}" invoked outside of the render function: ` +
103107
`this will not track dependencies used in the slot. ` +

0 commit comments

Comments
 (0)