Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): ensure custom events are not emitted anymore after unmount. (fix #5674) #5679

Merged
merged 1 commit into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/runtime-core/__tests__/componentEmits.spec.ts
Expand Up @@ -6,7 +6,8 @@ import {
defineComponent,
h,
nodeOps,
toHandlers
toHandlers,
nextTick
} from '@vue/runtime-test'
import { isEmitListener } from '../src/componentEmits'

Expand Down Expand Up @@ -374,4 +375,29 @@ describe('component: emit', () => {
// PascalCase option
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()
})
})
1 change: 1 addition & 0 deletions packages/runtime-core/src/componentEmits.ts
Expand Up @@ -73,6 +73,7 @@ export function emit(
event: string,
...rawArgs: any[]
) {
if (instance.isUnmounted) return
const props = instance.vnode.props || EMPTY_OBJ

if (__DEV__) {
Expand Down