Repository navigation
Description
Context
The notificationclick listener takes the first window clients.matchAll({ type: "window", includeUncontrolled: true }) returns, focuses it and calls navigate(url) on it (packages/ui-sdk/src/client/push-handlers.ts:92-112).
WindowClient.navigate() rejects with a TypeError when the window is not controlled by this service worker (a page opened with a hard reload, or one loaded before the worker took control). The rejection escapes the waitUntil promise, openWindow is never reached, and the tap only focuses the app on whatever it was showing: the deep link (for Actions, /#/activity) is lost. windows[0] is also just the most recently focused window, not necessarily a controlled or visible one.
The module comment (push-handlers.ts:11-14) promises "focuses an open app window and navigates it to the deep link, or opens a new one", which this path breaks.
Guide: (no guide). Support (MDN BCD 8.1.6): WindowClient.navigate Chrome for Android 49, Samsung Internet 4, Firefox for Android 50; WindowClient.focused/visibilityState and Clients.openWindow are in all three targets.
Binding: Action notifications (the payload and its url stay as they are). docs/decisions/http-api-boundary.md:67 cites (subscribeUrl, packages/ui-sdk/src/client/push-handlers.ts:72); a PR that moves that line updates the citation (tests/decision-citations.test.ts).
Scope
- Find controlled windows with
clients.matchAll({ type: "window" })(noincludeUncontrolled): by the Clients API, every window it returns is controlled by this worker, so no id comparison is needed. Do not callnavigateon a window from theincludeUncontrolled: truelist. - Among the controlled windows, choose in this order: one whose
focusedistrue, then one whosevisibilityStateis"visible", then the first controlled window inmatchAllorder. A window whosefocusedorvisibilityStateis absent ranks as "not known focused / not known visible", so a scope that does not supply them gets today's first-window choice, restricted to controlled windows. - Focus it and
navigate(url)inside atry. Ifnavigateis missing, rejects, or resolvesnull, fall back toclients.openWindow(url). ThewaitUntilpromise resolves in every branch. - With no controlled window, call
openWindow(url). - Widen the exported
PushCapableScope(packages/ui-sdk/src/client/push-handlers.ts:39-56) additively: the element type returned byclients.matchAllgains optionalid?: string,focused?: booleanandvisibilityState?: string. Nothing becomes required, so every structural implementation accepted today still type-checks and still works through the fallbacks above. - Update the module comment (
push-handlers.ts:11-14) to describe the new order and fallback.
Out of scope
- A
postMessagechannel from the worker to the page for in-app routing (it would need a listener inui-react; file it separately if wanted). - The
pushandpushsubscriptionchangelisteners (ui-sdk: a push subscription the browser renews is never sent to the server #2568, ui-sdk: push notifications show a generic Android status-bar icon instead of the brand badge #2570). - Notification actions or the payload shape.
- Changing how the app restores a hash after login.
Acceptance criteria
- With one uncontrolled and one controlled window, the controlled one is focused and navigated to
data.url. - When
navigaterejects,openWindow(data.url)is called and thewaitUntilpromise resolves. - When
navigateis absent,openWindow(data.url)is called. - With only uncontrolled windows,
openWindow(data.url)is called and nonavigateis attempted on them. - A focused controlled window wins over a visible one, which wins over a hidden one.
- Compatibility: a structural scope whose window clients carry only
url,focusandnavigate(today's shape, noid/focused/visibilityState) still type-checks againstregisterPushHandlers(a type-level test) and, at runtime, navigates the first controlled window. -
api-report/ui-sdk.txtshows only the three added optional members. - A new
packages/ui-sdk/tests/push-handlers.test.tsdrives the registerednotificationclicklistener through a structural scope and covers the criteria above; the rejecting-navigatecase fails on the tree before the change. - Neither Playwright nor CDP can dispatch
notificationclickto a real worker, so the PR states that the listener-level test is the proof and names this limit.
Verification
bun run test packages/ui-sdk/tests/push-handlers.test.ts
bun run typecheck
bun run lint
bun run api-reportContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit.PushCapableScopeis exported from the ordinary./push-handlersentry (packages/ui-sdk/package.json:68-72) and is the parameter type ofregisterPushHandlers(packages/ui-sdk/src/client/push-handlers.ts:68-71), so it is supported surface underdocs/decisions/public-export-boundary.md:10-21even thoughdocs/integration-contract/package-api.mddoes not list it. Record the additive widening there. - This changes a published package's behaviour, so it needs a changeset (minor, additive). Not breaking: the new members are optional, and the push payload and
PushHandlerOptionsare unchanged.
2026-10-24: corrected the contract classification (PushCapableScope is signature-reachable public surface, so this is a contract change); specified the new members as optional with fallbacks, replaced the id-match controlled check with the non-includeUncontrolled matchAll, and added compatibility criteria for today's structural shape.
Activity
schlessera commentedon Oct 23, 2026
2026-10-24 restructuring: added
contract. The selected work changes a supported surface: an ordinary TypeScript export, a CLI command, an environment setting, a route or a contract type (docs/integration-contract.md). The body's Contract impact section is being corrected to match.