Skip to content

Commit

Permalink
fix(runtime-core): fix directive merging on component root
Browse files Browse the repository at this point in the history
fix #2298
  • Loading branch information
yyx990803 committed Oct 8, 2020
1 parent f06518a commit 4d1ebb5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/runtime-core/__tests__/directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4d1ebb5

Please sign in to comment.