]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix scopeId inheritance for component inside slots
authorEvan You <yyx990803@gmail.com>
Sat, 27 Jun 2020 02:28:55 +0000 (22:28 -0400)
committerEvan You <yyx990803@gmail.com>
Sat, 27 Jun 2020 02:28:55 +0000 (22:28 -0400)
packages/runtime-core/__tests__/helpers/scopeId.spec.ts
packages/runtime-core/src/componentRenderUtils.ts

index b14d3acbc44ffb94bef773ad42e4c433b972d0e3..c943ef9705469203eef65ad32acebbf7ffc400d8 100644 (file)
@@ -45,13 +45,18 @@ describe('scopeId runtime support', () => {
         return h('div', this.$slots.default())
       })
     }
+    const withChil2Id = withScopeId('child2')
+    const Child2 = {
+      __scopeId: 'child2',
+      render: withChil2Id(() => h('span'))
+    }
     const App = {
       __scopeId: 'parent',
       render: withParentId(() => {
         return h(
           Child,
           withParentId(() => {
-            return h('div')
+            return [h('div'), h(Child2)]
           })
         )
       })
@@ -62,7 +67,14 @@ describe('scopeId runtime support', () => {
     // - scopeId from parent
     // - slotted scopeId (with `-s` postfix) from child (the tree owner)
     expect(serializeInner(root)).toBe(
-      `<div parent child><div parent child-s></div></div>`
+      `<div parent child>` +
+        `<div parent child-s></div>` +
+        // component inside slot should have:
+        // - scopeId from template context
+        // - slotted scopeId from slot owner
+        // - its own scopeId
+        `<span parent child-s child2></span>` +
+        `</div>`
     )
   })
 })
index 510f8b9af63a789e015d7dfd64e4de6a1b0c125d..05813b9c93e50b174d7a72902c53a8f374124218 100644 (file)
@@ -42,6 +42,7 @@ export function renderComponentRoot(
 ): VNode {
   const {
     type: Component,
+    parent,
     vnode,
     proxy,
     withProxy,
@@ -148,9 +149,15 @@ export function renderComponentRoot(
     }
 
     // inherit scopeId
-    if (vnode.scopeId) {
-      root = cloneVNode(root, { [vnode.scopeId]: '' })
+    const scopeId = vnode.scopeId
+    if (scopeId) {
+      root = cloneVNode(root, { [scopeId]: '' })
     }
+    const treeOwnerId = parent && parent.type.__scopeId
+    if (treeOwnerId && treeOwnerId !== scopeId) {
+      root = cloneVNode(root, { [treeOwnerId + '-s']: '' })
+    }
+
     // inherit directives
     if (vnode.dirs) {
       if (__DEV__ && !isElementRoot(root)) {