]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix directive merging on component root
authorEvan You <yyx990803@gmail.com>
Thu, 8 Oct 2020 02:02:32 +0000 (22:02 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 8 Oct 2020 02:02:32 +0000 (22:02 -0400)
fix #2298

packages/runtime-core/__tests__/directives.spec.ts
packages/runtime-core/src/componentRenderUtils.ts

index bfd6e439a46a22daeeebd53843264b27f9413ca9..3bca7c4e8d6c8e17ac21d2d1e98a16c175ccb54a 100644 (file)
@@ -340,4 +340,31 @@ describe('directives', () => {
     expect(beforeUnmount).toHaveBeenCalledTimes(1)
     expect(unmounted).toHaveBeenCalledTimes(1)
   })
+
+  // #2298
+  it('directive merging on component root', () => {
+    const d1 = {
+      mounted: jest.fn()
+    }
+    const d2 = {
+      mounted: jest.fn()
+    }
+    const Comp = {
+      render() {
+        return withDirectives(h('div'), [[d2]])
+      }
+    }
+
+    const App = {
+      name: 'App',
+      render() {
+        return h('div', [withDirectives(h(Comp), [[d1]])])
+      }
+    }
+
+    const root = nodeOps.createElement('div')
+    render(h(App), root)
+    expect(d1.mounted).toHaveBeenCalled()
+    expect(d2.mounted).toHaveBeenCalled()
+  })
 })
index 4a4b363f7b80e20c898943117c7525a2058f5b50..39f53603c5697526e0659ce00e2420a20e42bf2b 100644 (file)
@@ -186,7 +186,7 @@ export function renderComponentRoot(
             `The directives will not function as intended.`
         )
       }
-      root.dirs = vnode.dirs
+      root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs
     }
     // inherit transition data
     if (vnode.transition) {