From eeb2c0f6900798f5dfe6bfa45291a73724a9dd30 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Wed, 26 Nov 2025 11:29:58 +0000 Subject: [PATCH] Fix failure to request persistent storage perms (#31299) * Move call to `tryPersistStorage` to `OnLoggedIn` handler I think this needs to happen whether or not we are in the middle of a login flow. Fixes: https://github.com/element-hq/element-web/issues/31298 * Inline `MatrixChat.onLoggedIn` It's now a one-liner, and its semantics are very confusing. * Factor out `MatrixChat.onLoggedIn` Now that we've got rid of the confusing `onLoggedIn` method, we can factor out a method which *actually* handles `OnLoggedIn` actions. --- src/components/structures/MatrixChat.tsx | 64 +++++++++++------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index b0b45e4add..41c4117164 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -395,8 +395,7 @@ export default class MatrixChat extends React.PureComponent { } /** - * Perform actions that are specific to a user that has just logged in (compare {@link onLoggedIn}, which, despite - * its name, is called when an already-logged-in client is restored at session startup). + * Perform actions that are specific to a user that has just logged in. * * Called when: * @@ -404,7 +403,7 @@ export default class MatrixChat extends React.PureComponent { * - The {@link Login} or {@link Register} components notify us that we successfully completed a non-OIDC login or * registration. * - * In both cases, {@link Action.OnLoggedIn} will already have been emitted, but the call to {@link onLoggedIn} will + * In both cases, {@link Action.OnLoggedIn} will already have been emitted, but the call to {@link onShowPostLoginScreen} will * have been suppressed (by either {@link tokenLogin} being set, or the view being set to {@link Views.LOGIN} or * {@link Views.REGISTER}). * @@ -418,7 +417,7 @@ export default class MatrixChat extends React.PureComponent { const cli = MatrixClientPeg.safeGet(); const cryptoEnabled = Boolean(cli.getCrypto()); if (!cryptoEnabled) { - this.onLoggedIn(); + this.onShowPostLoginScreen(); } const promisesList: Promise[] = [this.firstSyncPromise.promise]; @@ -451,7 +450,7 @@ export default class MatrixChat extends React.PureComponent { const cryptoExtension = ModuleRunner.instance.extensions.cryptoSetup; if (cryptoExtension.SHOW_ENCRYPTION_SETUP_UI == false) { - this.onLoggedIn(); + this.onShowPostLoginScreen(); } else { this.setStateForNewView({ view: Views.COMPLETE_SECURITY }); } @@ -463,7 +462,7 @@ export default class MatrixChat extends React.PureComponent { ); this.setStateForNewView({ view: Views.E2E_SETUP }); } else { - this.onLoggedIn(); + this.onShowPostLoginScreen(); } this.setState({ pendingInitialSync: false }); } @@ -868,18 +867,7 @@ export default class MatrixChat extends React.PureComponent { Modal.createDialog(DialPadModal, {}, "mx_Dialog_dialPadWrapper"); break; case Action.OnLoggedIn: - this.stores.client = MatrixClientPeg.safeGet(); - if ( - // Skip this handling for token login as that always calls onLoggedIn itself - !this.tokenLogin && - !Lifecycle.isSoftLogout() && - this.state.view !== Views.LOGIN && - this.state.view !== Views.REGISTER && - this.state.view !== Views.COMPLETE_SECURITY && - this.state.view !== Views.E2E_SETUP - ) { - this.onLoggedIn(); - } + this.onLoggedIn(); break; case Action.ClientNotViable: this.onSoftLogout(); @@ -1392,28 +1380,12 @@ export default class MatrixChat extends React.PureComponent { } /** - * Called when a new logged in session has started. + * Show the first screen after the application is successfully loaded in a logged-in state. * * Called: * * - on {@link Action.OnLoggedIn}, but only when we don't expect a separate call to {@link postLoginSetup}. * - from {@link postLoginSetup}, when we don't have crypto setup tasks to perform after the login. - * - * It's never actually called if we have crypto setup tasks to perform after login (which we normally do, unless - * crypto is disabled.) XXX: is this a bug or a feature? - */ - private async onLoggedIn(): Promise { - StorageManager.tryPersistStorage(); - - await this.onShowPostLoginScreen(); - } - - /** - * Show the first screen after the application is successfully loaded in a logged-in state. - * - * Called: - * - * - by {@link onLoggedIn} * - by {@link onCompleteSecurityE2eSetupFinished} * * In other words, whenever we think we have completed the login and E2E setup tasks. @@ -1527,6 +1499,28 @@ export default class MatrixChat extends React.PureComponent { }); } + /** + * Handle an {@link Action.OnLoggedIn} action (i.e, we now have a client with working credentials). + */ + private onLoggedIn(): void { + this.stores.client = MatrixClientPeg.safeGet(); + StorageManager.tryPersistStorage(); + + // If we're in the middle of a login/registration, we wait for it to complete before transitioning to the logged + // in view the login flow will call `postLoginSetup` when it's done, which will arrange for `onShowPostLoginScreen` + // to be called. + if ( + !this.tokenLogin && + !Lifecycle.isSoftLogout() && + this.state.view !== Views.LOGIN && + this.state.view !== Views.REGISTER && + this.state.view !== Views.COMPLETE_SECURITY && + this.state.view !== Views.E2E_SETUP + ) { + this.onShowPostLoginScreen(); + } + } + /** * Called when the session is logged out */