Skip to content

Commit

Permalink
fix: move service worker registration to main.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheraff committed Oct 4, 2024
1 parent 96aa50c commit 797fdbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
</head>
<body>
<div id="root"></div>
<script src="/src/register.ts"></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<NavigationProvider>
<App />
Expand Down
13 changes: 0 additions & 13 deletions src/register.ts

This file was deleted.

0 comments on commit 797fdbd

Please sign in to comment.