Skip to content

ui-sdk: a notification tap loses its deep link when the app window is not controlled #2567

Open

Description

@schlessera

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" }) (no includeUncontrolled): by the Clients API, every window it returns is controlled by this worker, so no id comparison is needed. Do not call navigate on a window from the includeUncontrolled: true list.
  • Among the controlled windows, choose in this order: one whose focused is true, then one whose visibilityState is "visible", then the first controlled window in matchAll order. A window whose focused or visibilityState is 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 a try. If navigate is missing, rejects, or resolves null, fall back to clients.openWindow(url). The waitUntil promise 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 by clients.matchAll gains optional id?: string, focused?: boolean and visibilityState?: 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

Acceptance criteria

  • With one uncontrolled and one controlled window, the controlled one is focused and navigated to data.url.
  • When navigate rejects, openWindow(data.url) is called and the waitUntil promise resolves.
  • When navigate is absent, openWindow(data.url) is called.
  • With only uncontrolled windows, openWindow(data.url) is called and no navigate is 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, focus and navigate (today's shape, no id/focused/visibilityState) still type-checks against registerPushHandlers (a type-level test) and, at runtime, navigates the first controlled window.
  • api-report/ui-sdk.txt shows only the three added optional members.
  • A new packages/ui-sdk/tests/push-handlers.test.ts drives the registered notificationclick listener through a structural scope and covers the criteria above; the rejecting-navigate case fails on the tree before the change.
  • Neither Playwright nor CDP can dispatch notificationclick to 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-report

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit. PushCapableScope is exported from the ordinary ./push-handlers entry (packages/ui-sdk/package.json:68-72) and is the parameter type of registerPushHandlers (packages/ui-sdk/src/client/push-handlers.ts:68-71), so it is supported surface under docs/decisions/public-export-boundary.md:10-21 even though docs/integration-contract/package-api.md does 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 PushHandlerOptions are 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

  1. added
    type: fix
    area: ui-sdk
    priority: p2
    agent-ready
    on Oct 22, 2026
  2. added
    contract
    on Oct 23, 2026
  3. schlessera commented on Oct 23, 2026

    @schlessera
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-sdkcontractpriority: p2type: fix

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions