MatrixChat: only start session load once (#30642)
* MatrixChat: only start session load once When running in development mode, `MatrixChat.componentDidMount` is run twice, meaning it checks the session lock twice. Sometimes, this means it shows the "Element is running in another window" page. The real problem is of course that we're running all this application logic inside the `MatrixChat` component, but as a quick workaround, we can just remember that we've started the session load code, and bail out on the second pass. * Address review comments
This commit is contained in:
committed by
GitHub
parent
cf692e751b
commit
701019052c
@@ -238,6 +238,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
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<IProps, IState> {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user