-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Description
Version
2.3.3
Reproduction link
https://codepen.io/MadLittleMods/pen/YQPjXZ/
Steps to reproduce
- Create a Vue component with a
@blur
event listener - Focus the element with the
@blur
listener - Destroy the Vue component (
vm.$destroy()
,vm.$off()
,vm.$el.remove()
,vm = null
) - Click away to blur the element and see the
@blur
method get called
What is expected?
The @blur
event listener is not called.
In the minimal example, I expect the vm and listeners to get garbage collected after the setTimeout
call with just a vm.$destroy()
.
I expect the explicit vm.$off()
to remove the listeners.
Doing vm.$el.remove()
fires @blur
but does stop further calls after that (you can't focus it again to blur).
I expect vm = null;
to kick things more into garbage collection mode but doesn't seem to affect the result.
What is the correct way to clean up listeners on a Vue component after destroying?
What is actually happening?
The @blur
event listener gets called.
I ran into this while writing some Jasmine tests for a Vue component. I am focusing an input, vm.$destroy()
in the Jasmine afterEach
hook, then in another unrelated test, something else is focused causing a blur and a NPE is thrown.
Related Issues