Skip to content

Event listeners still in-tact after destroying (blur) #5829

@MadLittleMods

Description

@MadLittleMods

Version

2.3.3

Reproduction link

https://codepen.io/MadLittleMods/pen/YQPjXZ/

Steps to reproduce

  1. Create a Vue component with a @blur event listener
  2. Focus the element with the @blur listener
  3. Destroy the Vue component (vm.$destroy(), vm.$off(), vm.$el.remove(), vm = null)
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions