
activating - deactivating the menu's keeps registrering the click event listener on MDCMenuSurface.
Possible fix:
menu-surface component
component.js
MDCMenuSurface.prototype.initialSyncWithDOM
this.deregisterBodyClickListener = function () {
//BEFORE: document.body.removeEventListener('click', _this.handleBodyClick);
//AFTER: add the , { capture: true } to the removeEventListener
//to match the document.body.addEventListener('click', _this.handleBodyClick, { capture: true });
document.body.removeEventListener('click', _this.handleBodyClick, { capture: true });
};
FYI - I will post this suggestion on the material-components/material-components-web too
This looks like a bug in the menu surface class itself: https://github.com/material-components/material-components-web-components/blob/master/packages/menu/mwc-menu-surface-base.ts#L341
thanks for looking into this - my current "hack" is to do this (in lit-element updated):
this.temp_menu = new MDCMenu(div);
let origHandler = this.temp_menu.menuSurface_.handleBodyClick;
this.temp_menu.menuSurface_.deregisterBodyClickListener = () => {
document.body.removeEventListener('click', origHandler, { capture: true });
};
it's ugly - but seems to work.
@dfreedm - just out of curiosity - may I ask why these types of memory leak issues are considered "Severity: Low"? As I see it there are a couple of them in the "framework" and when using any of the components (menu and tab bar seems rather widespread) in a SPA the events are adding up and up and up.... when building a solid SPA where users might work for hours - it seems to slow down and refiring etc....?
I see it's been fixed in MDC, when is the next release with this fix expected? It's not just a memory leak, by the way, it messes up the logic when you subscribe to the 'closed' event of the menu surface--each undelegated handler emits an event resulting in an avalanche of events increasing the more times you open the menu.
@zandaqo You can use the @canary version of MWC to get the latest version, which will have the MDC fix included, until the next release.
The version 0.20.0 fixes this for me, but only when MDCMenuSurface#quick is set to true for some reason.