Skip to content

Commit

Permalink
fix: clean up custom events when patched component no longer have events
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and hefeng committed Jan 25, 2019
1 parent b1afe40 commit 130137e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/core/instance/lifecycle.js
Expand Up @@ -257,11 +257,10 @@ export function updateChildComponent (
}

// update listeners
if (listeners) {
const oldListeners = vm.$options._parentListeners
vm.$options._parentListeners = listeners
updateComponentListeners(vm, listeners, oldListeners)
}
listeners = listeners || emptyObject
const oldListeners = vm.$options._parentListeners
vm.$options._parentListeners = listeners
updateComponentListeners(vm, listeners, oldListeners)

// resolve slots + force update if has children
if (hasChildren) {
Expand Down
26 changes: 26 additions & 0 deletions test/unit/modules/vdom/patch/edge-cases.spec.js
Expand Up @@ -301,4 +301,30 @@ describe('vdom patch: edge cases', () => {
expect(vm.$el.children[0].style.color).toBe('green')
}).then(done)
})

// #7294
it('should cleanup component inline events on patch when no events are present', done => {
const log = jasmine.createSpy()
const vm = new Vue({
data: { ok: true },
template: `
<div>
<foo v-if="ok" @custom="log"/>
<foo v-else/>
</div>
`,
components: {
foo: {
render () {}
}
},
methods: { log }
}).$mount()

vm.ok = false
waitForUpdate(() => {
vm.$children[0].$emit('custom')
expect(log).not.toHaveBeenCalled()
}).then(done)
})
})

0 comments on commit 130137e

Please sign in to comment.