From b04d2de31344dc9c643c6ff7edd3d9298d1483af Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 28 Jan 2022 08:52:46 -0700 Subject: [PATCH] Fix left panel widgets causing app-wide crash (#7659) --- src/components/views/elements/AppTile.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/views/elements/AppTile.tsx b/src/components/views/elements/AppTile.tsx index 0db5a275b3..9327b0b50e 100644 --- a/src/components/views/elements/AppTile.tsx +++ b/src/components/views/elements/AppTile.tsx @@ -243,7 +243,11 @@ export default class AppTile extends React.Component { } this.watchUserReady(); - WidgetLayoutStore.instance.on(WidgetLayoutStore.emissionForRoom(this.props.room), this.onWidgetLayoutChange); + if (this.props.room) { + const emitEvent = WidgetLayoutStore.emissionForRoom(this.props.room); + WidgetLayoutStore.instance.on(emitEvent, this.onWidgetLayoutChange); + } + this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate); this.allowedWidgetsWatchRef = SettingsStore.watchSetting("allowedWidgets", null, this.onAllowedWidgetsChange); // Widget action listeners @@ -254,7 +258,11 @@ export default class AppTile extends React.Component { // Widget action listeners if (this.dispatcherRef) dis.unregister(this.dispatcherRef); - WidgetLayoutStore.instance.off(WidgetLayoutStore.emissionForRoom(this.props.room), this.onWidgetLayoutChange); + if (this.props.room) { + const emitEvent = WidgetLayoutStore.emissionForRoom(this.props.room); + WidgetLayoutStore.instance.off(emitEvent, this.onWidgetLayoutChange); + } + this.roomStoreToken?.remove(); SettingsStore.unwatchSetting(this.allowedWidgetsWatchRef); OwnProfileStore.instance.removeListener(UPDATE_EVENT, this.onUserReady);