Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Calling EventTarget.removeEventListener twice causes errors #283

Closed

Description

@sjelin

Consider the following code snippet:

var elem = document.body;
var listener = function (event) {};
elem.addEventListener('click', listener, false);
elem.removeEventListener('click', listener, false);
elem.removeEventListener('click', listener, false);

According to the DOM spec, the second removeEventListener should do nothing. However, with zone.js loaded it produces the following error message:

    Error: Task does not support cancellation, or is already canceled.
        at ZoneDelegate.cancelTask (/usr/local/google/home/sjelin/zone.js/test/browser_entry_point.ts:382:24)
        at Zone.cancelTask (/usr/local/google/home/sjelin/zone.js/test/browser_entry_point.ts:292:45)
        at zoneAwareRemoveEventListener (/usr/local/google/home/sjelin/zone.js/test/browser_entry_point.ts:970:25)
        at HTMLBodyElement.removeEventListener (eval at createNamedFn (/usr/local/google/home/sjelin/zone.js/test/browser_entry_point.ts:1051:18), <anonymous>:3:46)
        at Object.<anonymous> (/usr/local/google/home/sjelin/zone.js/test/browser_entry_point.ts:2354:19)

Basically, the problem is that the patched removeEventListener will cancel the task, but never removes it from the list of registered tasks. So when the second removeEventListener happens it tries to cancel the task again, leading to the problem. I suggest we start removing it from the list of registered tasks, unless there is a reason it has to stay there.

Activity

  1. mhevery commented on Mar 18, 2016

    @mhevery
    Contributor

    Sounds good to me.

  2. arsenys commented on Mar 18, 2016

    @arsenys

    I have the exactly the same problem. I have an Angular2 app with Semantic-UI. After upgrading zone.js from 0.5.x to 0.6.x almost every Semantic-UI component, such as modal window or dropdown throws the SafeSubscriber errors, whether its Task does not support cancellation, or is already canceled. or undefined is not an object (evaluating 'task.zone') errors from SafeSubscriber.

  3. added a commit that references this issue on Mar 18, 2016
    1350b02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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