From 9d247321f549962db976281edbb6c06bf5336581 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 30 Jul 2020 18:52:47 +0100 Subject: [PATCH 1/2] Fix crash on logging in again after soft logout Fixes https://github.com/vector-im/riot-web/issues/14834 --- src/stores/AsyncStoreWithClient.ts | 5 ----- src/stores/BreadcrumbsStore.ts | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/stores/AsyncStoreWithClient.ts b/src/stores/AsyncStoreWithClient.ts index 5b9f95f991..69aa5367c6 100644 --- a/src/stores/AsyncStoreWithClient.ts +++ b/src/stores/AsyncStoreWithClient.ts @@ -35,11 +35,6 @@ export abstract class AsyncStoreWithClient extends AsyncStore< await this.onAction(payload); if (payload.action === 'MatrixActions.sync') { - // Filter out anything that isn't the first PREPARED sync. - if (!(payload.prevState === 'PREPARED' && payload.state !== 'PREPARED')) { - return; - } - this.matrixClient = payload.matrixClient; await this.onReady(); } else if (payload.action === 'on_client_not_viable' || payload.action === 'on_logged_out') { diff --git a/src/stores/BreadcrumbsStore.ts b/src/stores/BreadcrumbsStore.ts index 34affbe746..ea29cb9dfc 100644 --- a/src/stores/BreadcrumbsStore.ts +++ b/src/stores/BreadcrumbsStore.ts @@ -55,7 +55,7 @@ export class BreadcrumbsStore extends AsyncStoreWithClient { } private get meetsRoomRequirement(): boolean { - return this.matrixClient.getVisibleRooms().length >= 20; + return this.matrixClient && this.matrixClient.getVisibleRooms().length >= 20; } protected async onAction(payload: ActionPayload) { From aaf0c7d269c2afbb120347dc0425e882f2f1a32b Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 30 Jul 2020 19:46:27 +0100 Subject: [PATCH 2/2] Put back code with comment hopefully explaining why it's necessary --- src/stores/AsyncStoreWithClient.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/stores/AsyncStoreWithClient.ts b/src/stores/AsyncStoreWithClient.ts index 69aa5367c6..f305bcb913 100644 --- a/src/stores/AsyncStoreWithClient.ts +++ b/src/stores/AsyncStoreWithClient.ts @@ -35,6 +35,13 @@ export abstract class AsyncStoreWithClient extends AsyncStore< await this.onAction(payload); if (payload.action === 'MatrixActions.sync') { + // Only set the client on the transition into the PREPARED state. + // Everything after this is unnecessary (we only need to know once we have a client) + // and we intentionally don't set the client before this point to avoid stores + // updating for every event emitted during the cached sync. + if (!(payload.prevState === 'PREPARED' && payload.state !== 'PREPARED')) { + return; + } this.matrixClient = payload.matrixClient; await this.onReady(); } else if (payload.action === 'on_client_not_viable' || payload.action === 'on_logged_out') {