From 797fdbdc83f19ad3945094d949d9b1c778d37868 Mon Sep 17 00:00:00 2001 From: Sheraff Date: Fri, 4 Oct 2024 17:56:58 +0200 Subject: [PATCH] fix: move service worker registration to main.tsx --- index.html | 1 - src/main.tsx | 13 +++++++++++++ src/register.ts | 13 ------------- 3 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 src/register.ts diff --git a/index.html b/index.html index caf727e..da25ef9 100644 --- a/index.html +++ b/index.html @@ -36,7 +36,6 @@
- diff --git a/src/main.tsx b/src/main.tsx index 30ce843..fc860c9 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2,6 +2,19 @@ import ReactDOM from 'react-dom/client' import App from './App' import { NavigationProvider } from '~/file-router/Navigation' +if (!window.isSecureContext) { + console.log("Not registering service worker because the site is not hosted on HTTPS.") +} else { + navigator.serviceWorker.register('./sw.js') + .then(registration => { + console.log(`Service worker registered: scope "${registration.scope}"`) + registration.addEventListener("updatefound", () => window.location.reload()) + if (registration.active && !navigator.serviceWorker.controller) { + window.location.reload() + } + }) +} + ReactDOM.createRoot(document.getElementById('root')!).render( diff --git a/src/register.ts b/src/register.ts deleted file mode 100644 index aa0d7a3..0000000 --- a/src/register.ts +++ /dev/null @@ -1,13 +0,0 @@ -const controlling = navigator.serviceWorker && navigator.serviceWorker.controller -if (!window.isSecureContext) { - console.log("Not registering service worker because the site is not hosted on HTTPS.") -} else { - navigator.serviceWorker.register('./sw.js') - .then(registration => { - console.log(`Service worker registered: scope "${registration.scope}"`) - registration.addEventListener("updatefound", () => window.location.reload()) - if (registration.active && !navigator.serviceWorker.controller) { - window.location.reload() - } - }) -} \ No newline at end of file