Repository navigation
Description
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 callapi.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.tsthat re-asserts an existing subscription and reports"none" | "other-key" | "bound". It throws on a server failure. rebindPushSubscriptionAfterLogindelegates 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 toPushState.PushTogglesubscribes tonavigator.permissions.query({ name: "notifications" })change, and also re-evaluates onvisibilitychangeto 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.subscriptionMatchesKeyusestoBase64({ alphabet: "base64url", omitPadding: true })whentypeof 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
PushSwitch's look, copy or states (push-switch.tsx).- Unsubscribing on the server when permission is revoked; the sender's 404/410 pruning handles it.
- The service-worker side (ui-sdk: a push subscription the browser renews is never sent to the server #2568).
- Zone reporting (
reportNotificationZone,createZoneRefresher). - Requesting permission anywhere other than the existing enable action.
Acceptance criteria
- With the toggle mounted as
subscribed, aPermissionStatuschangetodeniedmoves it toblocked, and topromptmoves it tonot-asked, without remounting. A test fails on the tree before the change. - The same transition happens on
visibilitychangeto visible when nochangeevent fired. - Without
navigator.permissions, or whenqueryrejects, the toggle behaves as today (mount-time read), with no error surfaced. -
rebindPushSubscriptionAfterLoginand the toggle both call the shared helper;git grep -n "pushSubscribe(" packages/ui-react/srcshows one re-assert call site plus the enable path. -
subscriptionMatchesKeyreturns the same result with and without nativetoBase64for 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 lintContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT: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