Skip to content

Commit

Permalink
fix(core/instance/render): inherit instance listeners to rendered vnode
Browse files Browse the repository at this point in the history
  • Loading branch information
samxchen committed May 24, 2023
1 parent 49b6bd4 commit f7add52
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/core/instance/render.ts
Expand Up @@ -128,6 +128,28 @@ export function renderMixin(Vue: typeof Component) {
setCurrentInstance(vm)
currentRenderingInstance = vm
vnode = render.call(vm._renderProxy, vm.$createElement)
// merge vnode hook listeners, example: vnode.data.on.click.fns = [fn1, fn2, fn3], vm.$vnode.data.on.click.fns = [fn4, fn5, fn6], then vnode.data.on.click.fns = [fn1, fn2, fn3, fn4, fn5, fn6]
if (vnode?.data?.on && vm?.$vnode?.data?.on) {
Object.keys(vm.$vnode.data.on).forEach((key) => {
if (vnode.data.on[key]) {
let fnsOnVnode = vnode.data.on[key];
if (typeof fnsOnVnode === 'function') {
fnsOnVnode = [fnsOnVnode];
}
let fnsOnVm = vm.$vnode?.data?.on?.[key];
if (typeof fnsOnVm === 'function') {
fnsOnVm = [fnsOnVm];
}
vnode.data.on[key] = [
...fnsOnVnode,
...(fnsOnVm || []),
]
if (vm.$vnode?.data?.on?.[key]) {
delete vm.$vnode.data.on[key];
}
}
})
}
} catch (e: any) {
handleError(e, vm, `render`)
// return error render result,
Expand Down

0 comments on commit f7add52

Please sign in to comment.