From 9354f61c2155c57578481a823a74c32dbc7993c3 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Thu, 2 Feb 2023 10:24:09 -0500 Subject: [PATCH 1/2] Fix a crash when removing persistent widgets When a persistent widget is removed, multiple calls to updateShowWidgetInPip happen in succession as each of the widget stores emit updates. But by depending on this.state.persistentWidgetId at the time of the call rather than passing an update function to setState, this had the effect that the removal of the widget could be reverted in the component's state, and so it could end up passing the ID of a removed widget to WidgetPip. --- src/components/structures/PipContainer.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/components/structures/PipContainer.tsx b/src/components/structures/PipContainer.tsx index 416458e6ff6..1638d75039a 100644 --- a/src/components/structures/PipContainer.tsx +++ b/src/components/structures/PipContainer.tsx @@ -192,10 +192,7 @@ class PipContainerInner extends React.Component { }; private onWidgetPersistence = (): void => { - this.updateShowWidgetInPip( - ActiveWidgetStore.instance.getPersistentWidgetId(), - ActiveWidgetStore.instance.getPersistentRoomId(), - ); + this.updateShowWidgetInPip(); }; private onWidgetDockChanges = (): void => { @@ -234,11 +231,10 @@ class PipContainerInner extends React.Component { } }; - // Accepts a persistentWidgetId to be able to skip awaiting the setState for persistentWidgetId - public updateShowWidgetInPip( - persistentWidgetId = this.state.persistentWidgetId, - persistentRoomId = this.state.persistentRoomId, - ): void { + private updateShowWidgetInPip(): void { + const persistentWidgetId = ActiveWidgetStore.instance.getPersistentWidgetId(); + const persistentRoomId = ActiveWidgetStore.instance.getPersistentRoomId(); + let fromAnotherRoom = false; let notDocked = false; // Sanity check the room - the widget may have been destroyed between render cycles, and From 12c70c67ac29530c0ddd08be62b3e1da48374f06 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 7 Feb 2023 10:51:58 +0000 Subject: [PATCH 2/2] Re-public updateShowWidgetInPip so we don't change the interface --- src/components/structures/PipContainer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/PipContainer.tsx b/src/components/structures/PipContainer.tsx index 1638d75039a..113ae702c9c 100644 --- a/src/components/structures/PipContainer.tsx +++ b/src/components/structures/PipContainer.tsx @@ -231,7 +231,7 @@ class PipContainerInner extends React.Component { } }; - private updateShowWidgetInPip(): void { + public updateShowWidgetInPip(): void { const persistentWidgetId = ActiveWidgetStore.instance.getPersistentWidgetId(); const persistentRoomId = ActiveWidgetStore.instance.getPersistentRoomId();