Skip to content

Commit

Permalink
unmount prior root when remounted root
Browse files Browse the repository at this point in the history
  • Loading branch information
night committed Oct 4, 2021
1 parent 10fb8e3 commit 97c4694
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/modules/emote_menu/EmoteMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class SafeEmoteMenuButton extends React.Component {
}
}

let mountedNode;

export default class EmoteMenuModule {
constructor() {
domObserver.on(CHAT_SETTINGS_BUTTON_CONTAINER_SELECTOR, (node, isConnected) => {
Expand Down Expand Up @@ -78,6 +80,10 @@ export default class EmoteMenuModule {
buttonContainer.setAttribute('data-a-target', 'legacy-bttv-emote-picker-button-container');
rightContainer.insertBefore(buttonContainer, rightContainer.lastChild);

if (mountedNode != null) {
ReactDOM.unmountComponentAtNode(mountedNode);
}

ReactDOM.render(
<SafeEmoteMenuButton
onError={() => this.show(false)}
Expand All @@ -88,6 +94,7 @@ export default class EmoteMenuModule {
/>,
buttonContainer
);
mountedNode = buttonContainer;
}

this.show(true);
Expand Down
6 changes: 6 additions & 0 deletions src/modules/settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function setHandleOpen(newHandleOpen) {
handleOpen = newHandleOpen;
}

let mountedNode;

export default class SettingsModule {
constructor() {
this.renderSettings();
Expand All @@ -22,7 +24,11 @@ export default class SettingsModule {
const panel = document.createElement('div');
panel.setAttribute('id', 'bttvSettingsPanel');
$('body').append(panel);
if (mountedNode != null) {
ReactDOM.unmountComponentAtNode(mountedNode);
}
ReactDOM.render(<Modal setHandleOpen={setHandleOpen} />, panel);
mountedNode = panel;
}

renderSettingsMenuOption() {
Expand Down

0 comments on commit 97c4694

Please sign in to comment.