Skip to content

ui-react: the push toggle keeps reading on after notifications are revoked in Android settings #2571

Open

Description

@schlessera

Context

PushToggle reads Notification.permission once, when it mounts or its root changes (PushToggle, packages/ui-react/src/components/activity/push-toggle.tsx:22-63, the permission branches at :33-40). A user who turns notifications off for the installed app in Android's settings comes back to a toggle that still reads "on" until the Activity surface remounts. The server keeps sending to an endpoint the browser has dropped until a send returns 404/410.

The same "re-assert an existing subscription" logic exists twice:

  • in the toggle's mount effect: read the subscription, compare its key with api.pushPublicKey(), and call api.pushSubscribe(...) (push-toggle.tsx:41-59);
  • in rebindPushSubscriptionAfterLogin (packages/ui-react/src/lib/push-registration.ts:62-76), driven with backoff by the connection gate (packages/ui-react/src/components/connectivity/connection-gate.tsx:114-149).

They differ only in how errors are handled and in the label guard, so a fix to one silently misses the other.

subscriptionMatchesKey hand-rolls base64url (push-registration.ts:161-167). Uint8Array.prototype.toBase64({ alphabet: "base64url", omitPadding: true }) does this natively in Chrome for Android 140, Samsung Internet 30 and Firefox for Android 133 (MDN BCD 8.1.6).

Guide: (no guide). Support (MDN BCD 8.1.6): navigator.permissions.query with notifications and PermissionStatus change are in Chrome for Android 43, Samsung Internet 4 and Firefox for Android 46 (where notifications is an alias of push).

Binding: Action notifications cites (rebindPushSubscriptionAfterLogin, packages/ui-react/src/lib/push-registration.ts:62-76). A PR that moves those lines updates that citation (tests/decision-citations.test.ts; find others with git grep -n 'push-registration.ts:' -- docs packages).

Scope

  • Extract one helper in push-registration.ts that re-asserts an existing subscription and reports "none" | "other-key" | "bound". It throws on a server failure.
  • rebindPushSubscriptionAfterLogin delegates to the helper and keeps its name, signature and throwing behaviour, so the connection gate's backoff is unchanged.
  • PushToggle's mount path uses the helper, catches server failures as today ("keep the browser's answer"), and maps the result to PushState.
  • PushToggle subscribes to navigator.permissions.query({ name: "notifications" }) change, and also re-evaluates on visibilitychange to visible, because a change made in system settings may land while the page is frozen. On re-evaluation it runs the same state derivation as mount. Remove both listeners on unmount or root change.
  • subscriptionMatchesKey uses toBase64({ alphabet: "base64url", omitPadding: true }) when typeof Uint8Array.prototype.toBase64 === "function", and the existing loop otherwise. If the configured TypeScript lib lacks the method, declare it structurally rather than changing the lib.

Out of scope

Acceptance criteria

  • With the toggle mounted as subscribed, a PermissionStatus change to denied moves it to blocked, and to prompt moves it to not-asked, without remounting. A test fails on the tree before the change.
  • The same transition happens on visibilitychange to visible when no change event fired.
  • Without navigator.permissions, or when query rejects, the toggle behaves as today (mount-time read), with no error surfaced.
  • rebindPushSubscriptionAfterLogin and the toggle both call the shared helper; git grep -n "pushSubscribe(" packages/ui-react/src shows one re-assert call site plus the enable path.
  • subscriptionMatchesKey returns the same result with and without native toBase64 for keys whose encoding needs padding stripped and +// replaced; both branches are tested by deleting the method in a test and restoring its property descriptor afterwards.
  • Existing push and connection-gate tests pass unchanged.

Verification

bun run test packages/ui-react/tests
bun run typecheck
bun run lint

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.
  • This changes a published package's behaviour, so it needs a changeset.

Not contract: no export, HTTP shape or payload changes.

Activity

  1. added
    type: fix
    area: ui-react
    priority: p3
    agent-ready
    on Oct 22, 2026
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-reactpriority: p3type: fix

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions