From e5f7b1ab7ce21a5a9ea285c0bdf1c1a67f4ca586 Mon Sep 17 00:00:00 2001 From: Lucas Berger Date: Tue, 9 Jun 2026 22:22:27 -0400 Subject: [PATCH] fix(05-review): CR-03 notificationclick uses matchAll+focus+navigate for deep-link URLs --- apps/pwa/src/sw.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/pwa/src/sw.ts b/apps/pwa/src/sw.ts index 8fd6daa..7b318d5 100644 --- a/apps/pwa/src/sw.ts +++ b/apps/pwa/src/sw.ts @@ -134,8 +134,15 @@ self.addEventListener('push', (event: PushEvent) => { // notificationclick handler (D-14 — deep-link on tap). // // Closes the notification, then: -// 1. If a window is already open at the target URL, focus it. -// 2. Otherwise, open a new window at the target URL. +// 1. Find any existing same-origin window with clients.matchAll (not exact-URL +// match — deep-link URLs differ from the current window URL). Focus it and +// navigate it to the target URL so the deep-link is honoured (CR-03 fix). +// 2. If no window exists, open a new one at the target URL. +// +// CR-03: The previous exact-URL match (client.url === url) never fired for +// deep-link notifications whose query string differed from the current window URL +// (e.g. notification for /calendar?event=uid while window is at /calendar). +// Using any existing window + navigate() satisfies D-14 on both Android and iOS. // --------------------------------------------------------------------------- self.addEventListener('notificationclick', (event: NotificationEvent) => { event.notification.close() @@ -149,13 +156,17 @@ self.addEventListener('notificationclick', (event: NotificationEvent) => { self.clients .matchAll({ type: 'window', includeUncontrolled: true }) .then((clientList) => { - // Focus an existing window already at the target URL + // Focus any existing window on this origin and navigate it to the target URL. + // We don't match on client.url — the deep-link URL will almost always differ + // from the current window location (query string with event uid / date). for (const client of clientList) { - if (client.url === url && 'focus' in client) { - return (client as WindowClient).focus() + if ('focus' in client) { + return (client as WindowClient).focus().then(() => + (client as WindowClient).navigate(url) + ) } } - // No existing window — open a new one + // No existing window — open a new one at the deep-link URL if (self.clients.openWindow) { return self.clients.openWindow(url) }