Ensure that Olm is only loaded once

React 18's strict mode intentionally mounts all components twice, which was causing Olm to get double-loaded. Also, it doesn't need to be loaded if the app is running as a widget.
This commit is contained in:
Robin Townsend
2022-10-31 13:43:03 -04:00
parent e42a83bbc4
commit d4caa1585b
5 changed files with 67 additions and 52 deletions

View File

@@ -18,6 +18,7 @@ import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { Room } from "matrix-js-sdk/src/models/room";
import IndexedDBWorker from "./IndexedDBWorker?worker";
import { getUrlParams } from "./UrlParams";
import { loadOlm } from "./olm";
export const defaultHomeserver =
(import.meta.env.VITE_DEFAULT_HOMESERVER as string) ??
@@ -72,8 +73,9 @@ export async function initClient(
clientOptions: ICreateClientOpts,
restore: boolean
): Promise<MatrixClient> {
let indexedDB: IDBFactory;
await loadOlm();
let indexedDB: IDBFactory;
try {
indexedDB = window.indexedDB;
} catch (e) {}