tried fixing infinite loop

This commit is contained in:
Mamalizz
2025-03-27 14:15:14 +03:30
parent 8fd03bba13
commit 5d78f61f87
4 changed files with 192 additions and 49 deletions
+17 -15
View File
@@ -3,33 +3,36 @@ import { precacheAndRoute } from "workbox-precaching";
// Precaching configuration for PWA assets
precacheAndRoute(self.__WB_MANIFEST);
// Version
const VERSION = "1.0.4";
// Service Worker Installation
// Only enable skipWaiting and claim in production
const isProduction = process.env.NODE_ENV === "production";
self.addEventListener("install", (event) => {
self.skipWaiting();
if (isProduction) {
self.skipWaiting();
}
});
// Service Worker Activation
self.addEventListener("activate", (event) => {
event.waitUntil(
(async () => {
const clients = await self.clients.matchAll({ type: "window" });
// Notify all open clients about the version
clients.forEach((client) =>
client.postMessage({ type: "VERSION_CHECK", version: VERSION })
);
self.clients.claim();
if (isProduction) {
const clients = await self.clients.matchAll({ type: "window" });
clients.forEach((client) =>
client.postMessage({
type: "VERSION_CHECK",
version: VERSION,
})
);
self.clients.claim();
}
console.log("Service Worker Activated (Version: " + VERSION + ")");
})()
);
});
// Push Notification Handler for Django Web Push
// Rest of your existing handlers remain the same...
self.addEventListener("push", (event) => {
try {
const payload = event.data?.json() || {
@@ -51,7 +54,6 @@ self.addEventListener("push", (event) => {
}
});
// Notification Click Handler
self.addEventListener("notificationclick", (event) => {
event.notification.close();
event.waitUntil(clients.openWindow(event.notification.data?.url || "/"));