fix settings panel leak

This commit is contained in:
Zack Rauen 2018-08-22 23:30:07 -04:00
parent 3e39d7ebb8
commit 63cc9fa1cc
2 changed files with 28 additions and 1 deletions

View File

@ -1259,6 +1259,23 @@ Utils.monkeyPatch = (what, methodName, options) => {
return cancel;
};
Utils.onRemoved = function(node, callback) {
const observer = new MutationObserver((mutations) => {
for (let m = 0; m < mutations.length; m++) {
const mutation = mutations[m];
const nodes = Array.from(mutation.removedNodes);
const directMatch = nodes.indexOf(node) > -1;
const parentMatch = nodes.some(parent => parent.contains(node));
if (directMatch || parentMatch) {
observer.disconnect();
callback();
}
}
});
observer.observe(document.body, {subtree: true, childList: true});
}
/* BetterDiscordApp VoiceMode JavaScript
@ -2447,6 +2464,7 @@ class V2C_CssEditorDetached extends BDV2.reactComponent {
this.saveCss();
this.updateCss();
});
}
componentWillUnmount() {
@ -3141,6 +3159,9 @@ class V2_SettingsPanel_Sidebar {
return;
}
BDV2.reactDom.render(this.component, root);
Utils.onRemoved(root, () => {
BDV2.reactDom.unmountComponentAtNode(root);
});
}
}
@ -3154,6 +3175,12 @@ class V2_SettingsPanel {
self.sidebar = new V2_SettingsPanel_Sidebar(self.sideBarOnClick);
}
componentDidMount() {
Utils.onRemoved(this.root, () => {
BDV2.reactDom.unmountComponentAtNode(this.root);
});
}
get root() {
let _root = $("#bd-settingspane-container");
if (!_root.length) {

2
js/main.min.js vendored

File diff suppressed because one or more lines are too long