From: inottn Date: Thu, 18 Jan 2024 03:45:11 +0000 (+0800) Subject: fix(runtime-core): should not warn out-of-render slot fn usage when mounting another... X-Git-Tag: v3.4.15~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fa33e67ec42af140a86fbdb86939032c3a1f345;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-core): should not warn out-of-render slot fn usage when mounting another app in setup (#10125) close #10124 --- diff --git a/packages/runtime-core/__tests__/componentSlots.spec.ts b/packages/runtime-core/__tests__/componentSlots.spec.ts index dde505b48e..09b3793214 100644 --- a/packages/runtime-core/__tests__/componentSlots.spec.ts +++ b/packages/runtime-core/__tests__/componentSlots.spec.ts @@ -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() + }) }) diff --git a/packages/runtime-core/src/componentSlots.ts b/packages/runtime-core/src/componentSlots.ts index 3214f8cb45..61e1ecc072 100644 --- a/packages/runtime-core/src/componentSlots.ts +++ b/packages/runtime-core/src/componentSlots.ts @@ -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. ` +