Skip to content

Commit 03de7f9

Browse files
committed
Cache-bust olm.wasm
In the same way as we now do images/fonts
1 parent 68fd1f0 commit 03de7f9

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

scripts/copy-res.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ const COPY_LIST = [
5858
["node_modules/matrix-react-sdk/res/media/**", "webapp/media"],
5959
["node_modules/emojione/assets/svg/*", "webapp/emojione/svg/"],
6060
["node_modules/emojione/assets/png/*", "webapp/emojione/png/"],
61-
// XXX: This is tied quite heavily to the matching olm.js so it really should be
62-
// in the bundle dir with the js to avoid caching issues giving us wasm that
63-
// doesn't match our js, but I cannot find any way to get webpack to do this.
64-
["node_modules/olm/olm.wasm", "webapp", { directwatch: 1 }],
6561
["node_modules/olm/olm_legacy.js", "webapp", { directwatch: 1 }],
6662
["./config.json", "webapp", { directwatch: 1 }],
6763
];

src/vector/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ require('gfm.css/gfm.css');
2424
require('highlight.js/styles/github.css');
2525
require('draft-js/dist/Draft.css');
2626

27+
import olmWasmPath from 'olm/olm.wasm';
28+
2729
import './rageshakesetup';
2830

2931
import React from 'react';
@@ -379,18 +381,19 @@ function loadOlm() {
379381
*
380382
* We also need to tell the Olm js to look for its wasm file at the same
381383
* level as index.html. It really should be in the same place as the js,
382-
* ie. in the bundle directory, to avoid caching issues, but as far as I
383-
* can tell this is completely impossible with webpack.
384+
* ie. in the bundle directory, but as far as I can tell this is
385+
* completely impossible with webpack. We do, however, use a hashed
386+
* filename to avoid caching issues.
384387
*/
385388
return Olm.init({
386-
locateFile: () => 'olm.wasm',
389+
locateFile: () => olmWasmPath,
387390
}).then(() => {
388391
console.log("Using WebAssembly Olm");
389392
}).catch((e) => {
390393
console.log("Failed to load Olm: trying legacy version");
391394
return new Promise((resolve, reject) => {
392395
const s = document.createElement('script');
393-
s.src = 'olm_legacy.js';
396+
s.src = 'olm_legacy.js'; // XXX: This should be cache-busted too
394397
s.onload = resolve;
395398
s.onerror = reject;
396399
document.body.appendChild(s);

webpack.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ module.exports = {
2525
rules: [
2626
{ enforce: 'pre', test: /\.js$/, use: "source-map-loader", exclude: /node_modules/, },
2727
{ test: /\.js$/, use: "babel-loader", include: path.resolve(__dirname, 'src') },
28+
{
29+
test: /\.wasm$/,
30+
loader: "file-loader",
31+
type: "javascript/auto", // https://github.com/webpack/webpack/issues/6725
32+
options: {
33+
name: '[name].[hash:7].[ext]',
34+
outputPath: '.',
35+
},
36+
},
2837
{
2938
test: /\.scss$/,
3039
// 1. postcss-loader turns the SCSS into normal CSS.

0 commit comments

Comments
 (0)