From cf23417e6e43e65f9ed0b60f685c219dd59b5c32 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 21 Oct 2020 16:06:22 +0100 Subject: [PATCH] Fix WidgetStore wrongly hanging onto old Widget definitions during removal Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/stores/WidgetEchoStore.js | 2 +- src/stores/WidgetStore.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stores/WidgetEchoStore.js b/src/stores/WidgetEchoStore.js index 7dd093d45e..3aef1beb3e 100644 --- a/src/stores/WidgetEchoStore.js +++ b/src/stores/WidgetEchoStore.js @@ -55,7 +55,7 @@ class WidgetEchoStore extends EventEmitter { const widgetId = w.getStateKey(); // If there's no echo, or the echo still has a widget present, show the *old* widget // we don't include widgets that have changed for the same reason we don't include new ones, - // ie. we'd need to fake matrix events to do so and therte's currently no need. + // ie. we'd need to fake matrix events to do so and there's currently no need. if (!roomEchoState[widgetId] || Object.keys(roomEchoState[widgetId]).length !== 0) { echoedWidgets.push(w); } diff --git a/src/stores/WidgetStore.ts b/src/stores/WidgetStore.ts index 1caea659ca..a8040f57de 100644 --- a/src/stores/WidgetStore.ts +++ b/src/stores/WidgetStore.ts @@ -122,6 +122,15 @@ export default class WidgetStore extends AsyncStoreWithClient { if (!room) return; const roomInfo = this.roomMap.get(room.roomId); roomInfo.widgets = []; + + // first clean out old widgets from the map which originate from this room + // otherwise we are out of sync with the rest of the app with stale widget events during removal + Array.from(this.widgetMap.values()).forEach(app => { + if (app.roomId === room.roomId) { + this.widgetMap.delete(app.id); + } + }); + this.generateApps(room).forEach(app => { this.widgetMap.set(app.id, app); roomInfo.widgets.push(app);