diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 39c0147da0..62831716c3 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -238,6 +238,8 @@ export default class MatrixChat extends React.PureComponent { private readonly stores: SdkContextClass; private loadSessionAbortController = new AbortController(); + private sessionLoadStarted = false; + public constructor(props: IProps) { super(props); this.stores = SdkContextClass.instance; @@ -470,15 +472,20 @@ export default class MatrixChat extends React.PureComponent { this.fontWatcher.start(); initSentry(SdkConfig.get("sentry")); - - if (!checkSessionLockFree()) { - // another instance holds the lock; confirm its theft before proceeding - setTimeout(() => this.setState({ view: Views.CONFIRM_LOCK_THEFT }), 0); - } else { - this.startInitSession(); - } - window.addEventListener("resize", this.onWindowResized); + + // Once we start loading the MatrixClient, we can't stop, even if MatrixChat gets unmounted (as it does + // in React's Strict Mode). So, start loading the session now, but only if this MatrixChat was not previously + // mounted. + if (!this.sessionLoadStarted) { + this.sessionLoadStarted = true; + if (!checkSessionLockFree()) { + // another instance holds the lock; confirm its theft before proceeding + setTimeout(() => this.setState({ view: Views.CONFIRM_LOCK_THEFT }), 0); + } else { + this.startInitSession(); + } + } } public componentDidUpdate(prevProps: IProps, prevState: IState): void {