Skip to content

Commit 719865c

Browse files
committed
parallel load language and theme
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 2c5664b commit 719865c

3 files changed

Lines changed: 27 additions & 17 deletions

File tree

‎src/vector/app.js‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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} 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, configError: Error) {
129+
export async function loadApp(fragParams: {}, acceptBrowser: boolean, configError: Error|void) {
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;
@@ -146,14 +144,8 @@ export async function loadApp(fragParams: {}, acceptBrowser: boolean, configErro
146144

147145
const platform = PlatformPeg.get();
148146

149-
// Load language after loading config.json so that settingsDefaults.language can be applied
150-
await loadLanguage();
151-
152147
const params = parseQs(window.location);
153148

154-
// as quickly as we possibly can, set a default theme...
155-
await setTheme();
156-
157149
// Now that we've loaded the theme (CSS), display the config syntax error if needed.
158150
if (configError && configError.err && configError.err instanceof SyntaxError) {
159151
const errorMessage = (

‎src/vector/index.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ limitations under the License.
2121
// Require common CSS here; this will make webpack process it into bundle.css.
2222
// Our own CSS (which is themed) is imported via separate webpack entry points
2323
// in webpack.config.js
24-
import {loadConfig, preparePlatform} from "./init";
25-
2624
require('gfm.css/gfm.css');
2725
require('highlight.js/styles/github.css');
2826

@@ -83,7 +81,16 @@ function checkBrowserFeatures() {
8381
// try in react but fallback to an `alert`
8482
async function start() {
8583
// load init.ts async so that its code is not executed immediately and we can catch any exceptions
86-
const {rageshakePromise, preparePlatform, loadOlm, loadSkin, loadApp} = await import(
84+
const {
85+
rageshakePromise,
86+
preparePlatform,
87+
loadOlm,
88+
loadConfig,
89+
loadSkin,
90+
loadLanguage,
91+
loadTheme,
92+
loadApp,
93+
} = await import(
8794
/* webpackChunkName: "init" */
8895
/* webpackPreload: true */
8996
"./init");
@@ -110,11 +117,11 @@ async function start() {
110117
}
111118
}
112119

120+
const loadOlmPromise = loadOlm();
113121
// set the platform for react sdk
114122
preparePlatform();
115123
// load config requires the platform to be ready
116124
const loadConfigPromise = loadConfig();
117-
const loadOlmPromise = loadOlm();
118125

119126
await loadSkin();
120127

@@ -123,11 +130,17 @@ async function start() {
123130
acceptBrowser = Boolean(window.localStorage.getItem("mx_accepts_unsupported_browser"));
124131
}
125132

133+
// await config here
134+
const configError = await loadConfigPromise;
135+
// Load language after loading config.json so that settingsDefaults.language can be applied
136+
const loadLanguagePromise = loadLanguage();
137+
// as quickly as we possibly can, set a default theme...
138+
const loadThemePromise = loadTheme();
139+
126140
// await things starting successfully
127141
await loadOlmPromise;
128-
129-
130-
const configError = await loadConfigPromise;
142+
await loadThemePromise;
143+
await loadLanguagePromise;
131144

132145
// Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to
133146
// run on the components.

‎src/vector/init.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import ElectronPlatform from "./platform/ElectronPlatform";
2828
import WebPlatform from "./platform/WebPlatform";
2929
import PlatformPeg from "matrix-react-sdk/src/PlatformPeg";
3030
import SdkConfig from "matrix-react-sdk/src/SdkConfig";
31+
import {setTheme} from "matrix-react-sdk/src/theme";
3132

3233
import { initRageshake } from "./rageshakesetup";
3334

@@ -138,7 +139,11 @@ export async function loadSkin() {
138139
console.log("Skin loaded!");
139140
}
140141

141-
export async function loadApp(fragParams: {}, acceptBrowser: boolean, configError: Error) {
142+
export async function loadTheme() {
143+
setTheme();
144+
}
145+
146+
export async function loadApp(fragParams: {}, acceptBrowser: boolean, configError: Error|void) {
142147
// load app.js async so that its code is not executed immediately and we can catch any exceptions
143148
const module = await import(
144149
/* webpackChunkName: "riot-web-app" */

0 commit comments

Comments
 (0)