Skip to content

Commit c0b4ab9

Browse files
authored
Merge pull request element-hq#13095 from vector-im/t3chguy/app_load2
App load order changes to catch errors better
2 parents 121728b + c67dcae commit c0b4ab9

6 files changed

Lines changed: 230 additions & 141 deletions

File tree

‎src/@types/global.d.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import {ReactNode} from "react";
1817
import "modernizr";
18+
import {Renderer} from "react-dom";
1919

2020
declare global {
2121
interface Window {
@@ -25,7 +25,10 @@ declare global {
2525
};
2626

2727
mxSendRageshake: (text: string, withLogs?: boolean) => void;
28-
matrixChat: ReactNode;
28+
matrixChat: ReturnType<Renderer>;
29+
30+
// electron-only
31+
ipcRenderer: any;
2932
}
3033

3134
// workaround for https://github.com/microsoft/TypeScript/issues/30933
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2020 New Vector Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import * as React from "react";
18+
import * as PropTypes from "prop-types";
19+
20+
import { _t } from "matrix-react-sdk/src/languageHandler";
21+
22+
interface IProps {
23+
title: string;
24+
messages?: string[];
25+
}
26+
27+
const ErrorView: React.FC<IProps> = ({title, messages}) => {
28+
return <div className="mx_GenericErrorPage">
29+
<div className="mx_GenericErrorPage_box">
30+
<h1>{title}</h1>
31+
<div>
32+
{messages && messages.map(msg => <p key={msg}>
33+
{ _t(msg) }
34+
</p>)}
35+
</div>
36+
</div>
37+
</div>;
38+
};
39+
40+
ErrorView.propTypes = {
41+
title: PropTypes.string.isRequired,
42+
messages: PropTypes.arrayOf(PropTypes.string.isRequired),
43+
};
44+
45+
export default ErrorView;
46+

‎src/i18n/strings/en_EN.json‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
2+
"Missing indexeddb worker script!": "Missing indexeddb worker script!",
3+
"Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.": "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.",
4+
"Invalid configuration: no default server specified.": "Invalid configuration: no default server specified.",
5+
"Your Riot is misconfigured": "Your Riot is misconfigured",
26
"Your Riot configuration contains invalid JSON. Please correct the problem and reload the page.": "Your Riot configuration contains invalid JSON. Please correct the problem and reload the page.",
37
"The message from the parser is: %(message)s": "The message from the parser is: %(message)s",
48
"Invalid JSON": "Invalid JSON",
5-
"Your Riot is misconfigured": "Your Riot is misconfigured",
9+
"Unable to load config file: please refresh the page to try again.": "Unable to load config file: please refresh the page to try again.",
610
"Unexpected error preparing the app. See console for details.": "Unexpected error preparing the app. See console for details.",
7-
"Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.": "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.",
8-
"Invalid configuration: no default server specified.": "Invalid configuration: no default server specified.",
911
"Open user settings": "Open user settings",
1012
"Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s",
1113
"Go to your browser to complete Sign In": "Go to your browser to complete Sign In",

‎src/vector/app.js‎

Lines changed: 21 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ global.React = React;
2626
import * as sdk from 'matrix-react-sdk';
2727
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg';
2828
import * as VectorConferenceHandler from 'matrix-react-sdk/src/VectorConferenceHandler';
29-
import {_t, _td, newTranslatableError} from 'matrix-react-sdk/src/languageHandler';
29+
import {_td, newTranslatableError} from 'matrix-react-sdk/src/languageHandler';
3030
import AutoDiscoveryUtils from 'matrix-react-sdk/src/utils/AutoDiscoveryUtils';
3131
import {AutoDiscovery} from "matrix-js-sdk/src/autodiscovery";
3232
import * as Lifecycle from "matrix-react-sdk/src/Lifecycle";
@@ -37,10 +37,8 @@ import {parseQs, parseQsFromFragment} from './url_utils';
3737

3838
import {MatrixClientPeg} from 'matrix-react-sdk/src/MatrixClientPeg';
3939
import SdkConfig from "matrix-react-sdk/src/SdkConfig";
40-
import {setTheme} from "matrix-react-sdk/src/theme";
4140

4241
import CallHandler from 'matrix-react-sdk/src/CallHandler';
43-
import {loadConfig, preparePlatform, loadLanguage, loadOlm} from "./init";
4442

4543
let lastLocationHashSet = null;
4644

@@ -128,7 +126,7 @@ function onTokenLoginCompleted() {
128126
window.location.href = formatted;
129127
}
130128

131-
export async function loadApp(fragParams: {}, acceptBrowser: boolean) {
129+
export async function loadApp(fragParams: {}) {
132130
// XXX: the way we pass the path to the worker script from webpack via html in body's dataset is a hack
133131
// but alternatives seem to require changing the interface to passing Workers to js-sdk
134132
const vectorIndexeddbWorkerScript = document.body.dataset.vectorIndexeddbWorkerScript;
@@ -137,99 +135,37 @@ export async function loadApp(fragParams: {}, acceptBrowser: boolean) {
137135
// the bundling. The js-sdk will just fall back to accessing
138136
// indexeddb directly with no worker script, but we want to
139137
// make sure the indexeddb script is present, so fail hard.
140-
throw new Error("Missing indexeddb worker script!");
138+
throw newTranslatableError(_td("Missing indexeddb worker script!"));
141139
}
142140
MatrixClientPeg.setIndexedDbWorkerScript(vectorIndexeddbWorkerScript);
143141
CallHandler.setConferenceHandler(VectorConferenceHandler);
144142

145143
window.addEventListener('hashchange', onHashChange);
146144

147-
await loadOlm();
148-
149-
// set the platform for react sdk
150-
preparePlatform();
151145
const platform = PlatformPeg.get();
152146

153-
// Load the config from the platform
154-
const configError = await loadConfig();
155-
156-
// Load language after loading config.json so that settingsDefaults.language can be applied
157-
await loadLanguage();
158-
159147
const params = parseQs(window.location);
160148

161-
// as quickly as we possibly can, set a default theme...
162-
await setTheme();
163-
164-
// Now that we've loaded the theme (CSS), display the config syntax error if needed.
165-
if (configError && configError.err && configError.err instanceof SyntaxError) {
166-
const errorMessage = (
167-
<div>
168-
<p>
169-
{_t(
170-
"Your Riot configuration contains invalid JSON. Please correct the problem " +
171-
"and reload the page.",
172-
)}
173-
</p>
174-
<p>
175-
{_t(
176-
"The message from the parser is: %(message)s",
177-
{message: configError.err.message || _t("Invalid JSON")},
178-
)}
179-
</p>
180-
</div>
181-
);
182-
183-
const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage");
184-
return <GenericErrorPage message={errorMessage} title={_t("Your Riot is misconfigured")} />;
185-
}
186-
187149
const urlWithoutQuery = window.location.protocol + '//' + window.location.host + window.location.pathname;
188150
console.log("Vector starting at " + urlWithoutQuery);
189-
if (configError) {
190-
return <div className="error">
191-
Unable to load config file: please refresh the page to try again.
192-
</div>;
193-
} else if (acceptBrowser) {
194-
platform.startUpdater();
195-
196-
try {
197-
// Don't bother loading the app until the config is verified
198-
const config = await verifyServerConfig();
199-
const MatrixChat = sdk.getComponent('structures.MatrixChat');
200-
return <MatrixChat
201-
onNewScreen={onNewScreen}
202-
makeRegistrationUrl={makeRegistrationUrl}
203-
ConferenceHandler={VectorConferenceHandler}
204-
config={config}
205-
realQueryParams={params}
206-
startingFragmentQueryParams={fragParams}
207-
enableGuest={!config.disable_guests}
208-
onTokenLoginCompleted={onTokenLoginCompleted}
209-
initialScreenAfterLogin={getScreenFromLocation(window.location)}
210-
defaultDeviceDisplayName={platform.getDefaultDeviceDisplayName()}
211-
/>;
212-
} catch (err) {
213-
console.error(err);
214-
215-
let errorMessage = err.translatedMessage
216-
|| _t("Unexpected error preparing the app. See console for details.");
217-
errorMessage = <span>{errorMessage}</span>;
218-
219-
// Like the compatibility page, AWOOOOOGA at the user
220-
const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage");
221-
return <GenericErrorPage message={errorMessage} title={_t("Your Riot is misconfigured")} />;
222-
}
223-
} else {
224-
console.error("Browser is missing required features.");
225-
// take to a different landing page to AWOOOOOGA at the user
226-
const CompatibilityPage = sdk.getComponent("structures.CompatibilityPage");
227-
return <CompatibilityPage onAccept={function() {
228-
if (window.localStorage) window.localStorage.setItem('mx_accepts_unsupported_browser', true);
229-
console.log("User accepts the compatibility risks.");
230-
loadApp();
231-
}} />;
232-
}
151+
152+
platform.startUpdater();
153+
154+
// Don't bother loading the app until the config is verified
155+
const config = await verifyServerConfig();
156+
const MatrixChat = sdk.getComponent('structures.MatrixChat');
157+
return <MatrixChat
158+
onNewScreen={onNewScreen}
159+
makeRegistrationUrl={makeRegistrationUrl}
160+
ConferenceHandler={VectorConferenceHandler}
161+
config={config}
162+
realQueryParams={params}
163+
startingFragmentQueryParams={fragParams}
164+
enableGuest={!config.disable_guests}
165+
onTokenLoginCompleted={onTokenLoginCompleted}
166+
initialScreenAfterLogin={getScreenFromLocation(window.location)}
167+
defaultDeviceDisplayName={platform.getDefaultDeviceDisplayName()}
168+
/>;
233169
}
234170

235171
async function verifyServerConfig() {

0 commit comments

Comments
 (0)