From 083410473c00d73369c1c8147f833a2cb9e6381f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 14 Jun 2026 10:46:23 +0200 Subject: [PATCH] refactor(pwa): defer push subscription to the app-wide registration The Web-Push opt-in registered its own `/sw.js` before subscribing. With the app-wide registrar now installing the worker for every user, that second `register` call is a redundant source of truth at the same scope. Replace it with `navigator.serviceWorker.ready`, which resolves with the active registration once the global worker is controlling the page. --- src/components/settings/web-push-card.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/settings/web-push-card.tsx b/src/components/settings/web-push-card.tsx index 57765ed8f..f3204b4dc 100644 --- a/src/components/settings/web-push-card.tsx +++ b/src/components/settings/web-push-card.tsx @@ -81,8 +81,12 @@ export function WebPushCard() { const vapidData = await vapidRes.json(); const vapidPublicKey = vapidData.data.publicKey; - const registration = await navigator.serviceWorker.register("/sw.js"); - await navigator.serviceWorker.ready; + // Defer to the app-wide registration (`` in + // the root providers) rather than re-registering here — same scope, + // so a second `register("/sw.js")` would only return the existing + // worker. `ready` resolves with the active registration once it is + // controlling the page. + const registration = await navigator.serviceWorker.ready; const subscription = await registration.pushManager.subscribe({ userVisibleOnly: true,