From a2dcb6fff16aec7dec0ab9faecb8484191e20cc6 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Thu, 25 Apr 2024 11:41:20 +0100 Subject: [PATCH] Service worker tweaks including auto reload --- src/index.tsx | 3 +++ tsconfig.json | 3 ++- vite.config.ts | 7 ++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 48edb877e..e0501117c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,6 +7,9 @@ import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import App from "./App"; import reportWebVitals from "./reportWebVitals"; +import { registerSW } from "virtual:pwa-register"; + +registerSW({ immediate: true }); const root = createRoot(document.getElementById("root")!); root.render( diff --git a/tsconfig.json b/tsconfig.json index 1d72bb95f..f0e7c5a52 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,8 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "types": ["vite-plugin-pwa/client"] }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] diff --git a/vite.config.ts b/vite.config.ts index 75b1fde75..4f717c77a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -57,10 +57,6 @@ export default defineConfig(({ mode }) => { VitePWA({ registerType: "autoUpdate", workbox: { - // A better chance of the runtime caches taking affect on first visit. - clientsClaim: true, - skipWaiting: true, - cleanupOutdatedCaches: true, // Ignore all language related assets and cache these at runtime instead. globIgnores: [ "**/{pyright-locale*.js,typeshed*.js,search.worker*.js,ui*.js}", @@ -112,7 +108,8 @@ export default defineConfig(({ mode }) => { }, }, { - urlPattern: /.*(?:pyright-locale|search\.worker|typeshed).*.js/, + urlPattern: + /.*(?:pyright-locale|search\.worker|typeshed|ui\.).*.js/, handler: "NetworkFirst", options: { cacheName: "lang-cache",