-
Notifications
You must be signed in to change notification settings - Fork 48
Cleanup is not removing event listeners #97
Description
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.
preboot/src/lib/api/event.replayer.ts
Line 178 in 60a3ea8
| listener.node.removeEventListener(listener.eventName, listener.handler); |
The event listeners are added here:
preboot/src/lib/api/event.recorder.ts
Line 178 in 60a3ea8
| serverRoot.addEventListener(eventName, handler, true); |