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') {