fix(runtime-core): ensure custom events are not emitted anymore after unmount. (#5679)
close #5674
This commit is contained in:
parent
8e29ef6019
commit
71c9536625
@ -6,7 +6,8 @@ import {
|
|||||||
defineComponent,
|
defineComponent,
|
||||||
h,
|
h,
|
||||||
nodeOps,
|
nodeOps,
|
||||||
toHandlers
|
toHandlers,
|
||||||
|
nextTick
|
||||||
} from '@vue/runtime-test'
|
} from '@vue/runtime-test'
|
||||||
import { isEmitListener } from '../src/componentEmits'
|
import { isEmitListener } from '../src/componentEmits'
|
||||||
|
|
||||||
@ -374,4 +375,29 @@ describe('component: emit', () => {
|
|||||||
// PascalCase option
|
// PascalCase option
|
||||||
expect(isEmitListener(options, 'onFooBaz')).toBe(true)
|
expect(isEmitListener(options, 'onFooBaz')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('does not emit after unmount', async () => {
|
||||||
|
const fn = jest.fn()
|
||||||
|
const Foo = defineComponent({
|
||||||
|
emits: ['closing'],
|
||||||
|
async beforeUnmount() {
|
||||||
|
await this.$nextTick()
|
||||||
|
this.$emit('closing', true)
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
return h('div')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const Comp = () =>
|
||||||
|
h(Foo, {
|
||||||
|
onClosing: fn
|
||||||
|
})
|
||||||
|
|
||||||
|
const el = nodeOps.createElement('div')
|
||||||
|
render(h(Comp), el)
|
||||||
|
await nextTick()
|
||||||
|
render(null, el)
|
||||||
|
await nextTick()
|
||||||
|
expect(fn).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -73,6 +73,7 @@ export function emit(
|
|||||||
event: string,
|
event: string,
|
||||||
...rawArgs: any[]
|
...rawArgs: any[]
|
||||||
) {
|
) {
|
||||||
|
if (instance.isUnmounted) return
|
||||||
const props = instance.vnode.props || EMPTY_OBJ
|
const props = instance.vnode.props || EMPTY_OBJ
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
|
Loading…
Reference in New Issue
Block a user