diff --git a/packages/runtime-core/__tests__/directives.spec.ts b/packages/runtime-core/__tests__/directives.spec.ts index bfd6e439..3bca7c4e 100644 --- a/packages/runtime-core/__tests__/directives.spec.ts +++ b/packages/runtime-core/__tests__/directives.spec.ts @@ -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() + }) }) diff --git a/packages/runtime-core/src/componentRenderUtils.ts b/packages/runtime-core/src/componentRenderUtils.ts index 4a4b363f..39f53603 100644 --- a/packages/runtime-core/src/componentRenderUtils.ts +++ b/packages/runtime-core/src/componentRenderUtils.ts @@ -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) {