From daa755017e5a4f0ed5e444cd2c0d68cb4e9c9813 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 1 Oct 2020 14:04:11 +0100 Subject: [PATCH 1/5] Revert "consolidate" This reverts commit aa2f3918 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/platform/WebPlatform.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index d91bb2593e..3f93ad712e 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -39,12 +39,15 @@ export default class WebPlatform extends VectorBasePlatform { // load service worker if available on this platform if ('serviceWorker' in navigator) { + // clean up old dummy sw.js + navigator.serviceWorker.getRegistration('sw.js').then(reg => reg.unregister()); + // Service worker is disabled in webpack-dev-server: https://github.com/GoogleChrome/workbox/issues/1790 if (!process.env.WEBPACK_DEV_SERVER) { navigator.serviceWorker.register('service-worker.js'); } else { // we no longer run workbox when in webpack-dev-server, clean it up - navigator.serviceWorker.getRegistration().then(reg => reg && reg.unregister()); + navigator.serviceWorker.getRegistration('service-worker.js').then(reg => reg.unregister()); } } } From 87c42934ea8c434aba4dd5e68e060c32bf34fd2b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 1 Oct 2020 14:04:21 +0100 Subject: [PATCH 2/5] Revert "Disable workbox when running in webpack dev server, not in dev mode" This reverts commit 11e676ce Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/platform/WebPlatform.ts | 15 ++++----------- webpack.config.js | 6 +----- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index 3f93ad712e..0a82b28e3c 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -38,20 +38,13 @@ export default class WebPlatform extends VectorBasePlatform { super(); // load service worker if available on this platform - if ('serviceWorker' in navigator) { - // clean up old dummy sw.js - navigator.serviceWorker.getRegistration('sw.js').then(reg => reg.unregister()); - - // Service worker is disabled in webpack-dev-server: https://github.com/GoogleChrome/workbox/issues/1790 - if (!process.env.WEBPACK_DEV_SERVER) { - navigator.serviceWorker.register('service-worker.js'); - } else { - // we no longer run workbox when in webpack-dev-server, clean it up - navigator.serviceWorker.getRegistration('service-worker.js').then(reg => reg.unregister()); - } + // Service worker is disabled in development: https://github.com/GoogleChrome/workbox/issues/1790 + if ('serviceWorker' in navigator && process.env.NODE_ENV === "production") { + navigator.serviceWorker.register('service-worker.js'); } } + getHumanReadableName(): string { return 'Web Platform'; // no translation required: only used for analytics } diff --git a/webpack.config.js b/webpack.config.js index a3a8af31c5..1b59d87406 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,4 @@ const path = require('path'); -const {EnvironmentPlugin} = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const TerserPlugin = require('terser-webpack-plugin'); @@ -33,8 +32,6 @@ module.exports = (env, argv) => { const jsSdkSrcDir = path.resolve(require.resolve("matrix-js-sdk/package.json"), '..', 'src'); const plugins = [ - new EnvironmentPlugin(["WEBPACK_DEV_SERVER"]), // pass this as it is used for conditionally loading workbox - // This exports our CSS using the splitChunks and loaders above. new MiniCssExtractPlugin({ filename: 'bundles/[hash]/[name].css', @@ -95,8 +92,7 @@ module.exports = (env, argv) => { }), ]; - const isDevServer = process.env.WEBPACK_DEV_SERVER; - if (!isDevServer) { + if (argv.mode === "production") { plugins.push(new WorkboxPlugin.GenerateSW({ maximumFileSizeToCacheInBytes: 22000000, runtimeCaching: [{ From 1edbe36547a20a60a1f9ae0d377487d7ee99ae50 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 1 Oct 2020 14:04:32 +0100 Subject: [PATCH 3/5] Revert "Tidy up Service Worker, only run Workbox in production" This reverts commit c47532fe Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/index.ts | 5 + src/vector/platform/WebPlatform.ts | 11 -- webpack.config.js | 167 ++++++++++++++--------------- 3 files changed, 86 insertions(+), 97 deletions(-) diff --git a/src/vector/index.ts b/src/vector/index.ts index 14e656f4ba..374055fbaa 100644 --- a/src/vector/index.ts +++ b/src/vector/index.ts @@ -28,6 +28,11 @@ require('highlight.js/styles/github.css'); import {parseQsFromFragment} from "./url_utils"; import './modernizr'; +// load service worker if available on this platform +if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('service-worker.js'); +} + async function settled(...promises: Array>) { for (const prom of promises) { try { diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index 0a82b28e3c..2e739a2660 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -34,17 +34,6 @@ const POKE_RATE_MS = 10 * 60 * 1000; // 10 min export default class WebPlatform extends VectorBasePlatform { private runningVersion: string = null; - constructor() { - super(); - - // load service worker if available on this platform - // Service worker is disabled in development: https://github.com/GoogleChrome/workbox/issues/1790 - if ('serviceWorker' in navigator && process.env.NODE_ENV === "production") { - navigator.serviceWorker.register('service-worker.js'); - } - } - - getHumanReadableName(): string { return 'Web Platform'; // no translation required: only used for analytics } diff --git a/webpack.config.js b/webpack.config.js index 1b59d87406..b58d35146f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -31,84 +31,6 @@ module.exports = (env, argv) => { const reactSdkSrcDir = path.resolve(require.resolve("matrix-react-sdk/package.json"), '..', 'src'); const jsSdkSrcDir = path.resolve(require.resolve("matrix-js-sdk/package.json"), '..', 'src'); - const plugins = [ - // This exports our CSS using the splitChunks and loaders above. - new MiniCssExtractPlugin({ - filename: 'bundles/[hash]/[name].css', - ignoreOrder: false, // Enable to remove warnings about conflicting order - }), - - // This is the app's main entry point. - new HtmlWebpackPlugin({ - template: './src/vector/index.html', - - // we inject the links ourselves via the template, because - // HtmlWebpackPlugin will screw up our formatting like the names - // of the themes and which chunks we actually care about. - inject: false, - excludeChunks: ['mobileguide', 'usercontent', 'jitsi'], - minify: argv.mode === 'production', - vars: { - og_image_url: og_image_url, - }, - }), - - // This is the jitsi widget wrapper (embedded, so isolated stack) - new HtmlWebpackPlugin({ - template: './src/vector/jitsi/index.html', - filename: 'jitsi.html', - minify: argv.mode === 'production', - chunks: ['jitsi'], - }), - - // This is the mobile guide's entry point (separate for faster mobile loading) - new HtmlWebpackPlugin({ - template: './src/vector/mobile_guide/index.html', - filename: 'mobile_guide/index.html', - minify: argv.mode === 'production', - chunks: ['mobileguide'], - }), - - // These are the static error pages for when the javascript env is *really unsupported* - new HtmlWebpackPlugin({ - template: './src/vector/static/unable-to-load.html', - filename: 'static/unable-to-load.html', - minify: argv.mode === 'production', - chunks: [], - }), - new HtmlWebpackPlugin({ - template: './src/vector/static/incompatible-browser.html', - filename: 'static/incompatible-browser.html', - minify: argv.mode === 'production', - chunks: [], - }), - - // This is the usercontent sandbox's entry point (separate for iframing) - new HtmlWebpackPlugin({ - template: './node_modules/matrix-react-sdk/src/usercontent/index.html', - filename: 'usercontent/index.html', - minify: argv.mode === 'production', - chunks: ['usercontent'], - }), - ]; - - if (argv.mode === "production") { - plugins.push(new WorkboxPlugin.GenerateSW({ - maximumFileSizeToCacheInBytes: 22000000, - runtimeCaching: [{ - urlPattern: /i18n\/.*\.json$/, - handler: 'CacheFirst', - - options: { - cacheName: 'i18n', - expiration: { - maxEntries: 2, - }, - }, - }], - })); - } - return { ...development, @@ -226,8 +148,8 @@ module.exports = (env, argv) => { }, loader: 'babel-loader', options: { - cacheDirectory: true, - }, + cacheDirectory: true + } }, { test: /\.css$/, @@ -238,7 +160,7 @@ module.exports = (env, argv) => { options: { importLoaders: 1, sourceMap: true, - }, + } }, { loader: 'postcss-loader', @@ -276,7 +198,7 @@ module.exports = (env, argv) => { "local-plugins": true, }, }, - ], + ] }, { test: /\.scss$/, @@ -287,7 +209,7 @@ module.exports = (env, argv) => { options: { importLoaders: 1, sourceMap: true, - }, + } }, { loader: 'postcss-loader', @@ -314,7 +236,7 @@ module.exports = (env, argv) => { "local-plugins": true, }, }, - ], + ] }, { test: /\.wasm$/, @@ -372,10 +294,83 @@ module.exports = (env, argv) => { }, ], }, - ], + ] }, - plugins, + plugins: [ + // This exports our CSS using the splitChunks and loaders above. + new MiniCssExtractPlugin({ + filename: 'bundles/[hash]/[name].css', + ignoreOrder: false, // Enable to remove warnings about conflicting order + }), + + // This is the app's main entry point. + new HtmlWebpackPlugin({ + template: './src/vector/index.html', + + // we inject the links ourselves via the template, because + // HtmlWebpackPlugin will screw up our formatting like the names + // of the themes and which chunks we actually care about. + inject: false, + excludeChunks: ['mobileguide', 'usercontent', 'jitsi'], + minify: argv.mode === 'production', + vars: { + og_image_url: og_image_url, + }, + }), + + // This is the jitsi widget wrapper (embedded, so isolated stack) + new HtmlWebpackPlugin({ + template: './src/vector/jitsi/index.html', + filename: 'jitsi.html', + minify: argv.mode === 'production', + chunks: ['jitsi'], + }), + + // This is the mobile guide's entry point (separate for faster mobile loading) + new HtmlWebpackPlugin({ + template: './src/vector/mobile_guide/index.html', + filename: 'mobile_guide/index.html', + minify: argv.mode === 'production', + chunks: ['mobileguide'], + }), + + // These are the static error pages for when the javascript env is *really unsupported* + new HtmlWebpackPlugin({ + template: './src/vector/static/unable-to-load.html', + filename: 'static/unable-to-load.html', + minify: argv.mode === 'production', + chunks: [], + }), + new HtmlWebpackPlugin({ + template: './src/vector/static/incompatible-browser.html', + filename: 'static/incompatible-browser.html', + minify: argv.mode === 'production', + chunks: [], + }), + + // This is the usercontent sandbox's entry point (separate for iframing) + new HtmlWebpackPlugin({ + template: './node_modules/matrix-react-sdk/src/usercontent/index.html', + filename: 'usercontent/index.html', + minify: argv.mode === 'production', + chunks: ['usercontent'], + }), + + new WorkboxPlugin.GenerateSW({ + runtimeCaching: [{ + urlPattern: /i18n\/.*\.json$/, + handler: 'CacheFirst', + + options: { + cacheName: 'i18n', + expiration: { + maxEntries: 2, + }, + }, + }], + }), + ], output: { path: path.join(__dirname, "webapp"), From cfee4c925a43a5792ac5854235e0410fa9cea060 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 1 Oct 2020 14:05:07 +0100 Subject: [PATCH 4/5] Revert "Attempt to fix tests some more" This reverts commit c76a5f2c Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- package.json | 3 +- res/sw.js | 1 + scripts/copy-res.js | 1 + src/vector/index.html | 10 + src/vector/index.ts | 2 +- webpack.config.js | 20 +- yarn.lock | 1336 ++--------------------------------------- 7 files changed, 67 insertions(+), 1306 deletions(-) create mode 100644 res/sw.js diff --git a/package.json b/package.json index 59d998d90f..936116180c 100644 --- a/package.json +++ b/package.json @@ -143,8 +143,7 @@ "typescript": "^3.7.3", "webpack": "^4.41.2", "webpack-cli": "^3.3.10", - "webpack-dev-server": "^3.9.0", - "workbox-webpack-plugin": "^5.1.4" + "webpack-dev-server": "^3.9.0" }, "jest": { "testEnvironment": "jest-environment-jsdom-fourteen", diff --git a/res/sw.js b/res/sw.js new file mode 100644 index 0000000000..dfe665a16f --- /dev/null +++ b/res/sw.js @@ -0,0 +1 @@ +self.addEventListener('fetch', () => {}); diff --git a/scripts/copy-res.js b/scripts/copy-res.js index 6c55f3d5dd..ebe1c625ea 100755 --- a/scripts/copy-res.js +++ b/scripts/copy-res.js @@ -61,6 +61,7 @@ const INCLUDE_LANGS = [ // "dest/b/...". const COPY_LIST = [ ["res/manifest.json", "webapp"], + ["res/sw.js", "webapp"], ["res/welcome.html", "webapp"], ["res/welcome/**", "webapp/welcome"], ["res/themes/**", "webapp/themes"], diff --git a/src/vector/index.html b/src/vector/index.html index 3ddc8482fb..4cda4b37a5 100644 --- a/src/vector/index.html +++ b/src/vector/index.html @@ -55,6 +55,16 @@
+ + + + + + + + + +