Repository navigation
Description
Outcome
An installed brain-kit PWA on Android notices a deploy while it stays open, hands over to the new service worker once every open app tab is idle, without losing code a running page still needs, renews and opens push notifications reliably, shows the app's own badge and status-bar colour, and keeps no timer or poller running while it is hidden.
Why now
A review of the UI against Google Chrome's public modern-web-guidance skill, plus a read of the service-worker and push code against current platform behaviour, found gaps that only show on an installed Android app kept open for days: deploys go unnoticed, a renewed push endpoint is dropped, a notification tap can lose its deep link, and background pollers run while the app is hidden. Chrome for Android 138 and Samsung Internet 30 started firing pushsubscriptionchange with newSubscription, so the renewal path is now live code on both targets.
Shared context
- Service-worker building blocks live in
packages/ui-sdk/src/client/: the lifecycle, precache, API, asset and navigation policy (registerDefaultRoutes,packages/ui-sdk/src/client/sw-policy.ts:162-297), the push listeners (registerPushHandlers,packages/ui-sdk/src/client/push-handlers.ts:68-136), the share-target handler and stash (share-target-handler.ts,share-store.ts). Workbox is injected; the SDK only declares structural types (ServiceWorkerPolicyScope,sw-policy.ts:57-67). - The host owns
index.html, the web app manifest, the viewport meta and the builtservice-worker.jsthat calls these building blocks (offline continuity, "the generated worker entry, precache/web-app manifests, index and offline pages belong to the public hosting template"). Anything that needs a host change gets a separatebrain-hosting-templateissue. - Registration and update run in
useServiceWorkerUpdates(packages/ui-react/src/hooks/use-service-worker-updates.ts:43-186): register, track an installing worker, and reload once oncontrollerchangewhen every update hold is idle (registerUpdateHold,packages/ui-react/src/lib/update-holds.ts). - How the shell is served today: a navigation to
/matches the precache route first (Workbox'sdirectoryIndexmaps/to the precached/index.html), so every launch is cache-first and only a new service worker brings a new version. The network-first navigation handler (sw-policy.ts:264-287) serves only paths that are not precached. - A real worker test harness exists:
packages/ui-react/tests/browser/offline/cold-capture/(a worker built fromregisterDefaultRoutes, run bypackages/ui-react/tests/browser/cold-capture.offline.tsxin theui-react-layoutproject,bun run test:layout). Use it for anything whose proof is a real worker's lifecycle. - Browser support policy: Chrome for Android stable (installed WebAPK) and Samsung Internet current (v30 = Chromium 143, per MDN browser-compat-data 8.1.6) keep full function. Firefox for Android degrades gracefully. Anything not in both Chromium targets is feature-detected with a named fallback; no polyfill dependencies.
- Guide references come from the modern-web-guidance guides
performance(Service Workers section) anddeprioritize-background-fetches. Most service-worker and push items have no guide; their support data comes from MDN browser-compat-data.
Constraints and non-goals
- D31 (foundations): a stale PWA must fail loudly, never subtly. Nothing here weakens the stale-client checks.
- Update holds (offline continuity, ui-react: hold service-worker update reloads while dictation, review text or local work is pending #1015, ui-react: keep staged track files reachable and reload-safe across per-session drafts #1112): a reload never fires over unsaved drafts, staged tracks, dictation or review text. The
controllerchangeand idle-reload chain stays. The takeover itself changes under ui-sdk: a new service worker activates under a busy page and deletes the lazy chunks it still needs #2569's ruling (idle-gated, all open app tabs idle): a busy, suspended or unresponsive tab blocks activation, so an update can wait indefinitely behind it, still bounded by D31's stale-client checks. - No authenticated API caching:
/apistays NetworkOnly (sw-policy.ts:222-234). - Push follows Action notifications: the payload stays
{ title, body, tag, url }(wire contract); notification copy carries no operational detail. - Share intake follows the ownership model from ui-react: share review admission deletes the durable original before confirmation #1804 (PR fix(ui-react): retain share originals through review #1899).
- Non-goals: Background Sync, Periodic Background Sync, offline API data, the Badging API, a custom install prompt, and any change to the host's manifest or HTML inside this repo.
Breakdown
- ui-react: an installed app left open never checks for a new service worker #2566: check for a new service worker when the app returns to the foreground or comes back online.
- ui-sdk: a notification tap loses its deep link when the app window is not controlled #2567: a notification tap always lands on its deep link.
- ui-sdk: a push subscription the browser renews is never sent to the server #2568: a renewed push endpoint is sent to the server.
- ui-sdk: a new service worker activates under a busy page and deletes the lazy chunks it still needs #2569: a new worker waits until every open app tab is idle before it activates (ruled: idle-gated handover, all tabs idle, required scope members; an approved break shipping as a pre-1.0 minor changeset).
- ui-sdk: push notifications show a generic Android status-bar icon instead of the brand badge #2570: notifications carry the brand badge and icon.
- ui-react: the push toggle keeps reading on after notifications are revoked in Android settings #2571: the push toggle follows a permission revoked in system settings, and its rebind code is shared.
- ui-react: pollers and elapsed tickers keep running while the app is hidden #2572: pollers and tickers stop while the app is hidden.
- ui-react: share intake rescans IndexedDB every second to recover abandoned shares #2573: share recovery waits on the browser lock instead of polling IndexedDB every second (ruled hybrid: queued Web Locks, account-scoped BroadcastChannel announcements, one safety rescan every 60 seconds only while visible).
- ui-kit: the Android status bar stays dark when the app is switched to Paper #2574: the Android status bar follows the in-app theme (host half: shell: declare theme colour per scheme and OS text scale in the app HTML brain-hosting-template#34).
- ui-react: the dev share harness cannot submit a share as a real navigation #2575: the dev share harness can submit a real form navigation.
Definition of done
- On a Chromium-based Android target, an app left open across a deploy detects the new version on its next foreground return, and activates and reloads into it once every open app tab is idle, without losing unsaved work or lazy chunks a busy tab still needs, proven by real-worker browser tests (ui-react: an installed app left open never checks for a new service worker #2566, ui-sdk: a new service worker activates under a busy page and deletes the lazy chunks it still needs #2569). While any open app tab is busy, suspended or unresponsive, the old version keeps running by design.
- Every push path (show, click, renewal) has a test that drives the registered listener, and the notification carries the brand badge.
- No
setInterval/setTimeoutpoller inpackages/ui-react/srckeeps firing whiledocument.visibilityState === "hidden", except where a comment states why. - The ui-sdk: a new service worker activates under a busy page and deletes the lazy chunks it still needs #2569 and ui-react: share intake rescans IndexedDB every second to recover abandoned shares #2573 rulings are implemented and recorded in
docs/decisions/design-kit/offline-continuity.mdwhere they change a recorded decision.
2026-10-24: replaced "needs a decision" on #2569 and #2573 with their accepted policies (all-tabs-idle handover; hybrid lock/broadcast recovery), and qualified the next-foreground update claims by the approved blocking behaviour of busy or unresponsive tabs.
Activity