Skip to content

Commit 04cf53e

Browse files
authored
Fix bug which caused app not to load correctly when force_verification is enabled (#31265)
* MatrixChat: add a load of logging for view transitions This stuff was essentially impossible to follow and debug. I think a load of logging will help. * Add more comments on `state.view` * Add a new state between LOADING/SOFT_LOGOUT and LOGGED_IN ... so that we can transition into COMPLETE_SECURITY without going via LOGGED_IN. * Remove redundant check for `force_verification` This check was previously necessary to keep the tests working, because: * onLoggedIn would call `onShowPostLoginScreen`, * which (without the check) would call `showScreenAfterLogin` * which would queue up an action `Action.ViewHomePage` * Then we would receive an already-queued `ClientStarted` action, which would transition us (correctly) to the `COMPLETE_SECURITY` view * Then we would receive the `ViewHomePage` action, taking us back to `LOGGED_IN`. I don't think the check was necessary in practice, because in practice there would be enough delay between the OnLoggedIn and ClientStarted actions that the race didn't happen. The *problem* with the check was that it meant that, whenever `force_verification` was enabled, we would get stuck in the LOADING state. The check is now unnecessary, because `onLoggedIn` no longer calls `onShowPostLoginScreen`. * `onShowPostLoginScreen` need no longer be `async` * Regression test for #31203
1 parent 57fd3c4 commit 04cf53e

4 files changed

Lines changed: 172 additions & 71 deletions

File tree

playwright/e2e/login/login.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2025 Element Creations Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import { expect, test } from "../../element-web-test";
9+
import { logIntoElement } from "../crypto/utils.ts";
10+
11+
test.describe(`With force_verification: true`, () => {
12+
test.use({
13+
config: {
14+
force_verification: true,
15+
},
16+
});
17+
18+
test("Can reload after login", async ({ page, credentials }) => {
19+
// The page should reload fine when going to the base client URL
20+
// Regression test for https://github.com/element-hq/element-web/issues/31203
21+
await logIntoElement(page, credentials);
22+
23+
// We should auto-upload the E2EE keys, and show a welcome page
24+
await expect(page.getByRole("heading", { name: `Welcome ${credentials.displayName}` })).toBeVisible();
25+
26+
await page.goto("/");
27+
28+
await expect(page.getByRole("heading", { name: `Welcome ${credentials.displayName}` })).toBeVisible();
29+
});
30+
});

src/PosthogTrackers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const notLoggedInMap: Record<Exclude<Views, Views.LOGGED_IN>, ScreenName> = {
2727
[Views.FORGOT_PASSWORD]: "ForgotPassword",
2828
[Views.COMPLETE_SECURITY]: "CompleteSecurity",
2929
[Views.E2E_SETUP]: "E2ESetup",
30+
[Views.PENDING_CLIENT_START]: "Loading",
3031
[Views.SOFT_LOGOUT]: "SoftLogout",
3132
[Views.LOCK_STOLEN]: "SessionLockStolen",
3233
};

src/Views.ts

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,62 @@ Please see LICENSE files in the repository root for full details.
2020
* │ LOADING │─────────────────────────────►│ CONFIRM_LOCK_ │
2121
* │ │◄─────────────────────────────│ THEFT │
2222
* └─────────────────┘ Lock theft confirmed └─────────────────┘
23-
* Session recovered │ │ │
24-
* ┌──────────────┘ │ └────────────────┐
25-
* │ ┌─────────────┘ │ No previous session
26-
* │ │ Token/OIDC login succeeded │
27-
* │ │ ▼
28-
* │ │ ┌─────────────────┐
29-
* │ │ │ WELCOME │ (from all other states
30-
* │ │ │ │ except LOCK_STOLEN)
31-
* │ │ └─────────────────┘ │
32-
* │ │ "Create Account" │ │ "Sign in" │ Client logged out
33-
* │ │ ┌────────────────────────┘ │ │
34-
* │ │ │ │ ┌────────────────────┘
35-
* │ │ │ │ │
36-
* │ │ ▼ "Create an ▼ ▼ "Forgot
37-
* │ │ ┌─────────────────┐ account" ┌─────────────────┐ password" ┌─────────────────┐
38-
* │ │ │ REGISTER │◄───────────────│ LOGIN │───────────────►│ FORGOT_PASSWORD │
39-
* │ │ │ │───────────────►│ │◄───────────────│ │
40-
* │ │ └─────────────────┘ "Sign in here" └─────────────────┘ Complete / └─────────────────┘
41-
* │ │ │ │ "Sign in instead" ▲
42-
* │ │ └────────────────────────────────┐ │ │
43-
* │ └────────────────────────────────────────┐ │ │ │
44-
* │ ▼ ▼ ▼ │
45-
* │ ┌──────────────────┐ │
46-
* │ │ (postLoginSetup) │ │
47-
* │ └──────────────────┘ │
48-
* │ ┌────────────────────────────────────┘ │ │ │
49-
* │ │ E2EE not enabled ┌─────────────┘ └──────┐ │
50-
* │ │ │ Account has │ Account lacks │
51-
* │ │ │ cross-signing │ cross-signing │
52-
* │ │ │ keys │ keys │
53-
* │ │ Client started and ▼ ▼ │
54-
* │ │ force_verification ┌─────────────────┐ ┌─────────────────┐ │
55-
* │ │ pending │ COMPLETE_ │ │ E2E_SETUP │ │
56-
* │ │ ┌─────────────────►│ SECURITY │ │ │ │
57-
* │ │ │ └─────────────────┘ └─────────────────┘ │ "Forgotten
58-
* │ │ │ ┌───────────────────────┘ │ │ your
59-
* │ │ │ │ ┌───────────────────────────────────────────────┘ │ password?"
60-
* │ │ │ │ │ │
61-
* │ │ │ │ │ (from all other states │
62-
* │ │ │ │ │ except LOCK_STOLEN) │
63-
* │ │ │ │ │ └──────────────┐ │
64-
* ▼ ▼ │ ▼ ▼ Soft logout error ▼ │
65-
* ┌─────────────────┐ ┌─────────────────┐
66-
* │ LOGGED_IN │ Re-authentication succeeded │ SOFT_LOGOUT │
67-
* │ │◄────────────────────────────────────────────────────────│ │
68-
* └─────────────────┘ └─────────────────┘
23+
* Session recovered │ │ │ Token/OIDC login succeeded
24+
* ┌──────────────┘ │ └──────────────────────────────────────────────────────────────────┐
25+
* │ └───────────────────────────────────────────┐ │
26+
* │ │ No previous session │
27+
* │ ▼ │
28+
* │ (from all other states ┌─────────────────┐ │
29+
* │ except LOCK_STOLEN) │ WELCOME │ │
30+
* │ │ │ │ │
31+
* │ │ Client logged out └─────────────────┘ │
32+
* │ │ │ │ │
33+
* │ └──────────────────────────┐ "Sign in" │ │ "Create account" │
34+
* │ │ ┌────────────┘ └──────────────┐ │
35+
* │ │ │ │ │
36+
* │ "Forgot ▼ ▼ "Create an ▼ │
37+
* │ ┌─────────────────┐ password" ┌─────────────────┐ account" ┌─────────────────┐ │
38+
* │ │ FORGOT_PASSWORD │◄───────────────│ LOGIN │───────────────►│ REGISTER │ │
39+
* │ │ │───────────────►│ │◄───────────────│ │ │
40+
* │ └─────────────────┘ Complete / └─────────────────┘ "Sign in here" └─────────────────┘ │
41+
* │ ▲ "Sign in instead" │ │ │
42+
* │ │ └──────────────────────┐ ┌─────────┘ │
43+
* │ │"Forgotten your │ │ ┌──────────────────┘
44+
* │ │ password?" │ │ │
45+
* │ │ │ │ │
46+
* │ ┌─────────────────┐ Soft-logout error │ │ │
47+
* │ │ SOFT_LOGOUT │◄───────────── (from all other states │ │ │
48+
* │ │ │ except LOCK_STOLEN) │ │ │
49+
* │ └─────────────────┘ │ │ │
50+
* │ │ Re-authentication succeeded ▼ ▼ ▼
51+
* │ │ ┌──────────────────┐
52+
* ▼ ▼ │ (postLoginSetup) │
53+
* ┌─────────────────┐ └──────────────────┘
54+
* │ PENDING_CLIENT_ │ Account has │ │ │ Account lacks
55+
* │ START │ cross-signing │ │ │ cross-signing
56+
* └─────────────────┘ keys │ │ │ keys
57+
* │ │ │ │ │
58+
* │ └───────────────────────────────┐ │ │ │
59+
* │ Client started, │ │ │ └──────┐
60+
* │ force_verification pending │ │ │ │
61+
* │ ▼ │ │ │
62+
* │ Client started, ┌─────────────────┐ │ │ │
63+
* │ force_verification │ COMPLETE_ │◄────────────┘ │ ▼
64+
* │ not needed │ SECURITY │ │ ┌─────────────────┐
65+
* │ └─────────────────┘ │ │ E2E_SETUP │
66+
* │ │ │ │ │
67+
* │ ┌─────────────────────────────────────┘ E2EE not enabled │ └─────────────────┘
68+
* │ │ ┌─────────────────────────────────────────────────────────────┘ │
69+
* │ │ │ ┌──────────────────────────────────────────────────────────────────────┘
70+
* │ │ │ │
71+
* │ │ │ │
72+
* │ │ │ │
73+
* │ │ │ │
74+
* ▼ ▼ ▼ ▼
75+
* ┌─────────────────┐
76+
* │ LOGGED_IN │
77+
* │ │
78+
* └─────────────────┘
6979
*
7080
* (from all other states)
7181
* │
@@ -102,6 +112,12 @@ enum Views {
102112
// flow to setup SSSS / cross-signing on this account
103113
E2E_SETUP,
104114

115+
/**
116+
* We have successfully recovered a session from localstorage, but the client
117+
* has not yet been started.
118+
*/
119+
PENDING_CLIENT_START,
120+
105121
// we are logged in with an active matrix client. The logged_in state also
106122
// includes guests users as they too are logged in at the client level.
107123
LOGGED_IN,

0 commit comments

Comments
 (0)