Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): should not warn when mounting another app in setup #10125

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/runtime-core/__tests__/componentSlots.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
createApp,
getCurrentInstance,
h,
nextTick,
Expand Down Expand Up @@ -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()
})
})
6 changes: 5 additions & 1 deletion packages/runtime-core/src/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. ` +
Expand Down