aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-19 21:23:31 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-20 21:41:50 +0200
commitbeda5138e018d9a853d57bd7274a35c21fa5c366 (patch)
tree3f6ff98c917db824a850c85eee7fbd76021adc27
parentfeat(frontend): add PWA manifest (diff)
downloadrefinery-beda5138e018d9a853d57bd7274a35c21fa5c366.tar.gz
refinery-beda5138e018d9a853d57bd7274a35c21fa5c366.tar.zst
refinery-beda5138e018d9a853d57bd7274a35c21fa5c366.zip
fix(frontend): destroy service worker in dev mode
If the application is run in both production and development mode on the same domain, make sure to clean up the production service worker.
-rw-r--r--.gitignore1
-rw-r--r--subprojects/frontend/.eslintrc.cjs2
-rw-r--r--subprojects/frontend/build.gradle4
-rw-r--r--subprojects/frontend/src/RegisterServiceWorker.tsx3
-rw-r--r--subprojects/frontend/vite.config.ts7
5 files changed, 15 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 8fedc4bd..56961dd2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@
15!.yarn/versions 15!.yarn/versions
16bin/ 16bin/
17build/ 17build/
18dev-dist/
18emf-gen/ 19emf-gen/
19xtend-gen/ 20xtend-gen/
20*.xtendbin 21*.xtendbin
diff --git a/subprojects/frontend/.eslintrc.cjs b/subprojects/frontend/.eslintrc.cjs
index 68636f4e..625aab7a 100644
--- a/subprojects/frontend/.eslintrc.cjs
+++ b/subprojects/frontend/.eslintrc.cjs
@@ -36,7 +36,7 @@ module.exports = {
36 env: { 36 env: {
37 browser: true, 37 browser: true,
38 }, 38 },
39 ignorePatterns: ['build/**/*'], 39 ignorePatterns: ['build/**/*', 'dev-dist/**/*'],
40 rules: { 40 rules: {
41 // In typescript, some class methods implementing an inderface do not use `this`: 41 // In typescript, some class methods implementing an inderface do not use `this`:
42 // https://github.com/typescript-eslint/typescript-eslint/issues/1103 42 // https://github.com/typescript-eslint/typescript-eslint/issues/1103
diff --git a/subprojects/frontend/build.gradle b/subprojects/frontend/build.gradle
index da237411..dd50860c 100644
--- a/subprojects/frontend/build.gradle
+++ b/subprojects/frontend/build.gradle
@@ -93,6 +93,10 @@ tasks.register('serveFrontend', RunYarn) {
93 description = 'Start a Vite dev server with hot module replacement.' 93 description = 'Start a Vite dev server with hot module replacement.'
94} 94}
95 95
96tasks.named('clean') {
97 delete 'dev-dist'
98}
99
96sonarqube.properties { 100sonarqube.properties {
97 properties['sonar.sources'] += ['src'] 101 properties['sonar.sources'] += ['src']
98 property 'sonar.nodejs.executable', "${frontend.nodeInstallDirectory.get()}/bin/node" 102 property 'sonar.nodejs.executable', "${frontend.nodeInstallDirectory.get()}/bin/node"
diff --git a/subprojects/frontend/src/RegisterServiceWorker.tsx b/subprojects/frontend/src/RegisterServiceWorker.tsx
index c9b2e353..5f46bc3d 100644
--- a/subprojects/frontend/src/RegisterServiceWorker.tsx
+++ b/subprojects/frontend/src/RegisterServiceWorker.tsx
@@ -50,7 +50,8 @@ function UpdateSnackbarActions({
50export default function RegisterServiceWorker(): null { 50export default function RegisterServiceWorker(): null {
51 const { enqueueSnackbar, closeSnackbar } = useSnackbar(); 51 const { enqueueSnackbar, closeSnackbar } = useSnackbar();
52 useEffect(() => { 52 useEffect(() => {
53 if (import.meta.env.DEV) { 53 if (window.location.host === 'localhost') {
54 // Do not register service worker during local development.
54 return; 55 return;
55 } 56 }
56 if (!('serviceWorker' in navigator)) { 57 if (!('serviceWorker' in navigator)) {
diff --git a/subprojects/frontend/vite.config.ts b/subprojects/frontend/vite.config.ts
index 7c0c2605..bb421788 100644
--- a/subprojects/frontend/vite.config.ts
+++ b/subprojects/frontend/vite.config.ts
@@ -66,6 +66,12 @@ export default defineConfig({
66 strategies: 'generateSW', 66 strategies: 'generateSW',
67 registerType: 'prompt', 67 registerType: 'prompt',
68 injectRegister: null, 68 injectRegister: null,
69 devOptions: {
70 enabled: true,
71 },
72 // Unregister service worker installed in production mode
73 // if Vite is started in development mode on the same domain.
74 selfDestroying: isDevelopment,
69 workbox: { 75 workbox: {
70 globPatterns: [ 76 globPatterns: [
71 '**/*.{css,html,js}', 77 '**/*.{css,html,js}',
@@ -74,6 +80,7 @@ export default defineConfig({
74 ], 80 ],
75 dontCacheBustURLsMatching: /\.(?:css|js|woff2?)$/, 81 dontCacheBustURLsMatching: /\.(?:css|js|woff2?)$/,
76 navigateFallbackDenylist: [/^\/xtext-service/], 82 navigateFallbackDenylist: [/^\/xtext-service/],
83 sourcemap: isDevelopment,
77 }, 84 },
78 includeAssets: ['apple-touch-icon.png', 'favicon.svg', 'mask-icon.svg'], 85 includeAssets: ['apple-touch-icon.png', 'favicon.svg', 'mask-icon.svg'],
79 manifest: { 86 manifest: {