fix(05-review): CR-03 notificationclick uses matchAll+focus+navigate for deep-link URLs
This commit is contained in:
+17
-6
@@ -134,8 +134,15 @@ self.addEventListener('push', (event: PushEvent) => {
|
|||||||
// notificationclick handler (D-14 — deep-link on tap).
|
// notificationclick handler (D-14 — deep-link on tap).
|
||||||
//
|
//
|
||||||
// Closes the notification, then:
|
// Closes the notification, then:
|
||||||
// 1. If a window is already open at the target URL, focus it.
|
// 1. Find any existing same-origin window with clients.matchAll (not exact-URL
|
||||||
// 2. Otherwise, open a new window at the target 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) => {
|
self.addEventListener('notificationclick', (event: NotificationEvent) => {
|
||||||
event.notification.close()
|
event.notification.close()
|
||||||
@@ -149,13 +156,17 @@ self.addEventListener('notificationclick', (event: NotificationEvent) => {
|
|||||||
self.clients
|
self.clients
|
||||||
.matchAll({ type: 'window', includeUncontrolled: true })
|
.matchAll({ type: 'window', includeUncontrolled: true })
|
||||||
.then((clientList) => {
|
.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) {
|
for (const client of clientList) {
|
||||||
if (client.url === url && 'focus' in client) {
|
if ('focus' in client) {
|
||||||
return (client as WindowClient).focus()
|
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) {
|
if (self.clients.openWindow) {
|
||||||
return self.clients.openWindow(url)
|
return self.clients.openWindow(url)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user