Skip to content

Commit d8b0838

Browse files
committed
fix: clean up custom events when patched component no longer have events
fix #7294
1 parent 956756b commit d8b0838

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/core/instance/lifecycle.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,10 @@ export function updateChildComponent (
257257
}
258258

259259
// update listeners
260-
if (listeners) {
261-
const oldListeners = vm.$options._parentListeners
262-
vm.$options._parentListeners = listeners
263-
updateComponentListeners(vm, listeners, oldListeners)
264-
}
260+
listeners = listeners || emptyObject
261+
const oldListeners = vm.$options._parentListeners
262+
vm.$options._parentListeners = listeners
263+
updateComponentListeners(vm, listeners, oldListeners)
265264

266265
// resolve slots + force update if has children
267266
if (hasChildren) {

test/unit/modules/vdom/patch/edge-cases.spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,30 @@ describe('vdom patch: edge cases', () => {
301301
expect(vm.$el.children[0].style.color).toBe('green')
302302
}).then(done)
303303
})
304+
305+
// #7294
306+
it('should cleanup component inline events on patch when no events are present', done => {
307+
const log = jasmine.createSpy()
308+
const vm = new Vue({
309+
data: { ok: true },
310+
template: `
311+
<div>
312+
<foo v-if="ok" @custom="log"/>
313+
<foo v-else/>
314+
</div>
315+
`,
316+
components: {
317+
foo: {
318+
render () {}
319+
}
320+
},
321+
methods: { log }
322+
}).$mount()
323+
324+
vm.ok = false
325+
waitForUpdate(() => {
326+
vm.$children[0].$emit('custom')
327+
expect(log).not.toHaveBeenCalled()
328+
}).then(done)
329+
})
304330
})

0 commit comments

Comments
 (0)