diff --git a/src/FromWidgetPostMessageApi.js b/src/FromWidgetPostMessageApi.js index 4dd3ea6e6d..61c51d4a20 100644 --- a/src/FromWidgetPostMessageApi.js +++ b/src/FromWidgetPostMessageApi.js @@ -116,10 +116,8 @@ export default class FromWidgetPostMessageApi { const origin = u.protocol + '//' + u.host; if (this.widgetMessagingEndpoints && this.widgetMessagingEndpoints.length > 0) { const length = this.widgetMessagingEndpoints.length; - this.widgetMessagingEndpoints = this.widgetMessagingEndpoints. - filter(function(endpoint) { - return (endpoint.widgetId != widgetId || endpoint.endpointUrl != origin); - }); + this.widgetMessagingEndpoints = this.widgetMessagingEndpoints + .filter((endpoint) => endpoint.widgetId !== widgetId || endpoint.endpointUrl !== origin); return (length > this.widgetMessagingEndpoints.length); } return false; diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 708eb39bd3..959cee7ace 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -339,9 +339,7 @@ export default class AppTile extends React.Component { // Destroy the old widget messaging before starting it back up again. Some widgets // have startup routines that run when they are loaded, so we just need to reinitialize // the messaging for them. - if (ActiveWidgetStore.getWidgetMessaging(this.props.id)) { - ActiveWidgetStore.delWidgetMessaging(this.props.id); - } + ActiveWidgetStore.delWidgetMessaging(this.props.id); this._setupWidgetMessaging(); ActiveWidgetStore.setRoomId(this.props.id, this.props.room.roomId); diff --git a/src/stores/ActiveWidgetStore.js b/src/stores/ActiveWidgetStore.js index 1211195203..2d80a763d0 100644 --- a/src/stores/ActiveWidgetStore.js +++ b/src/stores/ActiveWidgetStore.js @@ -116,6 +116,8 @@ class ActiveWidgetStore extends EventEmitter { } setWidgetMessaging(widgetId, wm) { + // Stop any existing widget messaging first + this.delWidgetMessaging(widgetId); this._widgetMessagingByWidgetId[widgetId] = wm; this.emit('update'); }