]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): should not warn out-of-render slot fn usage when mounting another...
authorinottn <inottn@outlook.com>
Thu, 18 Jan 2024 03:45:11 +0000 (11:45 +0800)
committerGitHub <noreply@github.com>
Thu, 18 Jan 2024 03:45:11 +0000 (11:45 +0800)
close #10124

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

index dde505b48e116414a83c448529bc031c1e6609de..09b37932147be3232e1ee242d5f44d007c1fe9f0 100644 (file)
@@ -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()
+  })
 })
index 3214f8cb455738822346e6d144a9cf773c85c6f2..61e1ecc072c1f07597ad7a91b9dfe18ca571994b 100644 (file)
@@ -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. ` +