Skip to content

Commit 7147c7e

Browse files
jedryczkatymonAntoni-Czaplicki
authored andcommitted
chore: move to manifest.ts
1 parent ff91a5b commit 7147c7e

2 files changed

Lines changed: 23 additions & 43 deletions

File tree

public/manifest.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/components/service-worker-register.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@ import { useEffect } from "react";
44

55
export function ServiceWorkerRegister() {
66
useEffect(() => {
7-
if ("serviceWorker" in navigator) {
8-
window.addEventListener("load", () => {
9-
navigator.serviceWorker.register("/sw.js").then(
10-
(registration) => {
11-
console.warn(
12-
"Service Worker registration successful with scope:",
13-
registration.scope,
14-
);
15-
},
16-
(error: unknown) => {
17-
console.error("Service Worker registration failed:", error);
18-
},
19-
);
20-
});
7+
if (!("serviceWorker" in navigator)) {
8+
return;
219
}
10+
const registerServiceWorker = () => {
11+
navigator.serviceWorker.register("/sw.js").then(
12+
(registration) => {
13+
console.log(
14+
"Service Worker registration successful with scope: ",
15+
registration.scope,
16+
);
17+
},
18+
(err) => {
19+
console.error("Service Worker registration failed: ", err);
20+
},
21+
);
22+
};
23+
if (document.readyState === "complete") {
24+
registerServiceWorker();
25+
return;
26+
}
27+
window.addEventListener("load", registerServiceWorker);
28+
return () => {
29+
window.removeEventListener("load", registerServiceWorker);
30+
};
2231
}, []);
2332

2433
return null;

0 commit comments

Comments
 (0)