Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove code which loads legacy libolm #27650

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"@types/react": "17.0.80"
},
"dependencies": {
"@matrix-org/olm": "3.2.15",
"@matrix-org/react-sdk-module-api": "^2.3.0",
"jsrsasign": "^11.0.0",
"katex": "^0.16.0",
Expand Down
3 changes: 0 additions & 3 deletions src/vector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ async function start(): Promise<void> {
rageshakePromise,
setupLogStorage,
preparePlatform,
loadOlm,
loadConfig,
loadLanguage,
loadTheme,
Expand Down Expand Up @@ -148,7 +147,6 @@ async function start(): Promise<void> {
}
}

const loadOlmPromise = loadOlm();
// set the platform for react sdk
preparePlatform();
// load config requires the platform to be ready
Expand Down Expand Up @@ -215,7 +213,6 @@ async function start(): Promise<void> {
// app load critical path starts here
// assert things started successfully
// ##################################
await loadOlmPromise;
await loadModulesPromise;
await loadThemePromise;
await loadLanguagePromise;
Expand Down
46 changes: 0 additions & 46 deletions src/vector/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import olmWasmPath from "@matrix-org/olm/olm.wasm";
import Olm from "@matrix-org/olm";
import * as ReactDOM from "react-dom";
import * as React from "react";
import * as languageHandler from "matrix-react-sdk/src/languageHandler";
Expand Down Expand Up @@ -76,48 +72,6 @@ export async function loadConfig(): Promise<void> {
}
}

export function loadOlm(): Promise<void> {
/* Load Olm. We try the WebAssembly version first, and then the legacy,
* asm.js version if that fails. For this reason we need to wait for this
* to finish before continuing to load the rest of the app. In future
* we could somehow pass a promise down to react-sdk and have it wait on
* that so olm can be loading in parallel with the rest of the app.
*
* We also need to tell the Olm js to look for its wasm file at the same
* level as index.html. It really should be in the same place as the js,
* ie. in the bundle directory, but as far as I can tell this is
* completely impossible with webpack. We do, however, use a hashed
* filename to avoid caching issues.
*/
return Olm.init({
locateFile: () => olmWasmPath,
})
.then(() => {
logger.log("Using WebAssembly Olm");
})
.catch((wasmLoadError) => {
logger.log("Failed to load Olm: trying legacy version", wasmLoadError);
return new Promise((resolve, reject) => {
const s = document.createElement("script");
s.src = "olm_legacy.js"; // XXX: This should be cache-busted too
s.onload = resolve;
s.onerror = reject;
document.body.appendChild(s);
})
.then(() => {
// Init window.Olm, ie. the one just loaded by the script tag,
// not 'Olm' which is still the failed wasm version.
return window.Olm.init();
})
.then(() => {
logger.log("Using legacy Olm");
})
.catch((legacyLoadError) => {
logger.log("Both WebAssembly and asm.js Olm failed!", legacyLoadError);
});
});
}

export async function loadLanguage(): Promise<void> {
const prefLang = SettingsStore.getValue("language", null, /*excludeDefault=*/ true);
let langs: string[] = [];
Expand Down
26 changes: 5 additions & 21 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,6 @@ module.exports = (env, argv) => {
// there is no need for webpack to parse them - they can just be
// included as-is.
/highlight\.js[\\/]lib[\\/]languages/,

// olm takes ages for webpack to process, and it's already heavily
// optimised, so there is little to gain by us uglifying it.
/olm[\\/](javascript[\\/])?olm\.js$/,
],
rules: [
useHMR && {
Expand Down Expand Up @@ -443,20 +439,6 @@ module.exports = (env, argv) => {
},
],
},
{
// the olm library wants to load its own wasm, rather than have webpack do it.
// We therefore use the `file-loader` to tell webpack to dump the contents to
// a separate file and return the name, and override the default `type` for `.wasm` files
// (which is `webassembly/experimental` under webpack 4) to stop webpack trying to interpret
// the filename as webassembly. (see also https://github.com/webpack/webpack/issues/6725)
test: /olm\.wasm$/,
loader: "file-loader",
type: "javascript/auto",
options: {
name: "[name].[hash:7].[ext]",
outputPath: ".",
},
},
{
// Fix up the name of the opus-recorder worker (react-sdk dependency).
// We more or less just want it to be clear it's for opus and not something else.
Expand Down Expand Up @@ -498,8 +480,11 @@ module.exports = (env, argv) => {
},
},
{
// Same deal as olm.wasm: the decoderWorker wants to load the wasm artifact
// itself.
// The decoderWorker wants to load its own wasm, rather than have webpack do it.
// We therefore use the `file-loader` to tell webpack to dump the contents to
// a separate file and return the name, and override the default `type` for `.wasm` files
// (which is `webassembly/experimental` under webpack 4) to stop webpack trying to interpret
// the filename as webassembly. (see also https://github.com/webpack/webpack/issues/6725)
test: /decoderWorker\.min\.wasm$/,
loader: "file-loader",
type: "javascript/auto",
Expand Down Expand Up @@ -750,7 +735,6 @@ module.exports = (env, argv) => {
{ from: "vector-icons/**", context: path.resolve(__dirname, "res") },
{ from: "decoder-ring/**", context: path.resolve(__dirname, "res") },
{ from: "media/**", context: path.resolve(__dirname, "node_modules/matrix-react-sdk/res/") },
"node_modules/@matrix-org/olm/olm_legacy.js",
{ from: "config.json", noErrorOnMissing: true },
"contribute.json",
],
Expand Down
Loading