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.
This commit is contained in:
Marc-André Bombeck committed 2026-06-14 10:46:23 +02:00
1 parent 0c4b6ab8ba
commit 083410473c
1 file changed
+6 -2
+6 -2
View File
@@ -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 (`<ServiceWorkerRegistrar>` 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,