Thanks to visit codestin.com
Credit goes to github.com

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

Cleanup is not removing event listeners #97

@FingalP

Description

@FingalP

Note: for support questions, please use the Universal Slack Channcel or https://gitter.im/angular/universal

  • I'm submitting a ...
  • bug report
  • feature request
  • Which parts of preboot are affected by this issue?
  • server side
  • client side
  • inline
  • build process
  • docs
  • tests
  • Do you want to request a feature or report a bug?

report a bug

  • What is the current behavior?

Cleanup is not removing event listeners.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem by creating a github repo.

Open a prerendered page and use the Chrome inspector to see the event listeners on your root component.

  • What is the expected behavior?

Cleanup should remove all of the event listeners.

  • What is the motivation / use case for changing the behavior?

This has lead to issues which fail silently, are hard to debug and it's not clear that they are related to preboot. For example, a button of type submit inside a form which was prerendered only worked if I click on the text of the button, but not if I click on the rest of the button. I'm not sure exactly why that happened, but removing the event listeners fixed it.

  • Please tell us about your environment:
  • Browser: Chromium 68
  • Language: TypeScript 2.9.2 with target es5
  • OS: Linux
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

I fixed it by using this in my project:
document.addEventListener('PrebootComplete', () => {
prebootData.listeners.forEach(listener => {
listener.node.removeEventListener(listener.eventName, listener.handler, true)
})
})
It seems that the line linked below just needs to have an additional argument to removeEventListener, true, as they have useCapture=true.

listener.node.removeEventListener(listener.eventName, listener.handler);

The event listeners are added here:
serverRoot.addEventListener(eventName, handler, true);

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