@ultimat3/pwa 29.3.2 → 30.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +3 -3
- package/README.md +4 -2
- package/package.json +16 -6
- package/src/index.ts +2 -2
- package/src/push-send.ts +21 -14
- package/src/push.ts +20 -4
- package/src/route-rules.ts +1 -1
- package/src/service-worker.ts +6 -6
- package/src/strategies.ts +1 -1
- package/src/version-skew.ts +1 -38
package/CLAUDE.md
CHANGED
|
@@ -33,8 +33,8 @@ role's boot loads, `@ultimat3/mcp/schema`'s shape; `serve-graph.test.ts` exempts
|
|
|
33
33
|
| Precache revision | content hash. Never the build id — that re-downloads everything per deploy. |
|
|
34
34
|
| A truncation of author text | CODE POINTS, never `slice`. `short_name` falls back to the first 12 of `name`, and a UTF-16 `slice` cuts inside a surrogate pair — the lone half encodes as U+FFFD, so an app named with an emoji got a home-screen label ending in a replacement character. `Array.from(name).slice(0, n).join('')` is the form. |
|
|
35
35
|
| Declared and never wired | `ServiceWorkerConfig.shellUrl` / `shellRevision` / `shellBytes` and `PwaRoute.dataUrl`. No caller in the framework's build path sets any of them, so `precache.ts`'s `reason: 'shell'` and `reason: 'route-data'` branches are reachable only from a hand-built `generateServiceWorker` call. Each doc comment now says so; the shell trio's said "precached for every `spa` route" while `spa` was already deleted from `RENDER_MODES`. **Kept, not deleted** — a public field is a major — and carried as candidates for the next major's declared-and-never-wired half. `revision` and `bytes` are the pair that IS fed, by the CLI's prerender pass. |
|
|
36
|
-
| Every byte count and every threshold | a whole number of 0 or more, screened with `finiteCount` where it is READ — `buildPrecacheManifest`'s `warnBytes` AND each entry's own `bytes` (shell, route, asset), `installController`'s `minEngagementMs
|
|
37
|
-
| Precache KEY | the bare URL, always. The revision addresses the FETCH (`?v=<hash>`), never the key: every strategy looks an entry up with `caches.match(req)` and `ignoreSearch` defaults to `false`, so an entry left keyed under `?v=` is a permanent miss — offline serves the fallback document instead of the precached page, and online every precached byte is downloaded twice. Each entry is fetched and `put` on its own, `As of 22.3.4`: `addAll`'s all-or-nothing let one 404 (a stylesheet another pod minted) fail the install of every deploy, so every visitor stayed on the first worker that ever installed (
|
|
36
|
+
| Every byte count and every threshold | a whole number of 0 or more, screened with `finiteCount` where it is READ — `buildPrecacheManifest`'s `warnBytes` AND each entry's own `bytes` (shell, route, asset), `installController`'s `minEngagementMs`. `totalBytes > warnBytes` is false when EITHER side is `NaN`, so one asset whose byte count did not arrive as a number took down the install-size warning for every other entry, silently, in the function whose output is otherwise byte-identical per commit; `now() - startedAt < NaN` is false at every instant, so the install prompt fired on first paint; and `Math.max(1, NaN)` is `NaN` with `slice(0, NaN)` `[]`, so a retention plan evicted every deploy including the running one. `Math.max` is not a validator — it propagates. `keep: 0` still means 1 (`version-skew.test.ts` pins it), so the floor is 0 everywhere here. `bun run finite-bounds` is the ratchet. |
|
|
37
|
+
| Precache KEY | the bare URL, always. The revision addresses the FETCH (`?v=<hash>`), never the key: every strategy looks an entry up with `caches.match(req)` and `ignoreSearch` defaults to `false`, so an entry left keyed under `?v=` is a permanent miss — offline serves the fallback document instead of the precached page, and online every precached byte is downloaded twice. Each entry is fetched and `put` on its own, `As of 22.3.4`: `addAll`'s all-or-nothing let one 404 (a stylesheet another pod minted) fail the install of every deploy, so every visitor stayed on the first worker that ever installed (one adopter). A failed entry costs its offline copy only. `service-worker-runtime.test.ts` executes the emitted `sw.js` against stub `caches`/`fetch` rather than asserting its text. |
|
|
38
38
|
| Precache FETCH | the revision is appended with `?` or `&`, picked per entry. `PrecacheAsset.url` is public API and a bundler emits `?v=<hash>` of its own, so a fixed `?` built `...?locale=en?v=<rev>`; `addAll` is all-or-nothing, so one non-200 there means `install` rejects and the worker never activates at all. |
|
|
39
39
|
| SW scope | `assertScope` refuses a relative `swPath`. `lastIndexOf('/')` on `sw.js` is `-1`, so the directory was `''` and `scope.startsWith('')` passed for every scope — the check waved through exactly the config most likely to be wrong. |
|
|
40
40
|
| HTML sinks | one escaper: `escapeHtml` from `@ultimat3/core`, the framework's one character table (`bun run flight-copies`, `X_HELPER_COPY`). `appleTouchLinks` and `renderThemeColorMeta` interpolate app config into attributes; both escape. Never a second escaper here. |
|
|
@@ -47,7 +47,7 @@ role's boot loads, `@ultimat3/mcp/schema`'s shape; `serve-graph.test.ts` exempts
|
|
|
47
47
|
| `AppUpdateAvailable` | declares exactly the fields the emitted `activate` block posts, and no more. `version-skew.test.ts` reads the literal back out of the generated source and compares it to a fixture typed `Required<AppUpdateAvailable>` — a field added to the interface stops compiling, a field added to the worker fails the assertion. It declared five and posted two until 9.0.0; the three extra described a forced reload nothing performed. |
|
|
48
48
|
| Forced reload | **not a capability of this package.** `updateSignal`/`updatePolicy` computed `forced`/`deadlineAt` with no runtime caller and were deleted in 9.0.0. The two runtimes holding both build ids are BELOW this one — `http`'s `ctx.clientBuildId` (tier 2), `sync`'s `update-available` frame (tier 3) — so neither could ever have called into tier 4 to act on one. The app renders its own affordance; the framework never navigates a client. |
|
|
49
49
|
| A cache copy is never awaited before answering | `Cache.put` reads the whole body, so a strategy that awaited it held a streamed (or slow) document away from the tab until it had ENDED. The emitted strategies hand the copy to `later(wait, …)` — the fetch event's `waitUntil` — and return the response at once. `service-worker-runtime.test.ts` streams a gated body and asserts the page reads the first chunk before it ends; its `StubCache.put` reads the whole body, as the real one does, or the test could not fail. |
|
|
50
|
-
| A per-member document | NEVER stored, in any cache, under any rule (22.3.3, security). `openCache` guards every cache a strategy opens: a response that is `private`/`no-store` or carries `x-ultimate-scope` (`CLIENT_SCOPE_HEADER`) is answered and dropped. 21.0.0 kept one in a per-principal partition (`PAGES~<scope>`) for offline, and after sign-out an offline navigation on a shared device showed the previous member's cases (
|
|
50
|
+
| A per-member document | NEVER stored, in any cache, under any rule (22.3.3, security). `openCache` guards every cache a strategy opens: a response that is `private`/`no-store` or carries `x-ultimate-scope` (`CLIENT_SCOPE_HEADER`) is answered and dropped. 21.0.0 kept one in a per-principal partition (`PAGES~<scope>`) for offline, and after sign-out an offline navigation on a shared device showed the previous member's cases (one adopter). A PERSONAL route (`PwaRoute.personal`: a policy, a `stream`, a `no-store`/`private` cache) is also `network-only` in `strategyFor` and skipped by `buildPrecacheManifest`. `{type:'clear-pages'}` (`CLEAR_PAGES_MESSAGE`) deletes every `x-pages-*` cache — old partitions included — and answers `pages-cleared`. `offline.personalPages: 'last-member'` (an app's explicit opt-in) restores 21.0.0's partition — `pagesCacheSource(mode)` emits one of the two, and `routeRules(routes, mode)` gives a personal page a `pages` rule whatever its `offline` (a `precache` rule was never filled, so it was never kept). `service-worker-pages.test.ts` runs both modes. |
|
|
51
51
|
| The installing page | cached on `activate`. It loaded before the worker controlled it, so no strategy saw it and an `offline: 'runtime'` route was unavailable offline until a second online visit. After `clients.claim()` each controlled window's URL runs through its OWN route's strategy (`warm`) — only rules with `c: 'pages'`, same origin, not `NEVER_CACHE` — never a second caching rule. Best effort; a failed warm-up never fails activation. It runs AFTER activation, never inside its `waitUntil`: a fetch event waits for the worker to finish activating, so a warm-up copying a streamed page's whole body there held the claimed tab's every request — the `/feed` e2e hang. The offline page read (`pageOffline`) awaits it instead. `service-worker-runtime.test.ts` runs it. |
|
|
52
52
|
| Outbox drain | the worker SENDS NOTHING, `As of 21.0.0`. The outbox is `@ultimat3/realtime`'s and lives in the page (IndexedDB), so the `sync` event — and the `{type:'flush-outbox'}` fallback message, posted by `registerBackgroundSyncSource` wherever `registration.sync` is absent (Safari, Firefox) — both run `drainOutbox`, which posts `OUTBOX_DRAIN_MESSAGE` (`@ultimat3/core`) to EVERY open window client; realtime's listener drains. No client open = the handler resolves and the next load drains; it never fakes work. `/_x/outbox/flush`, `DEFAULT_FLUSH_ENDPOINT`, and `BackgroundSyncOptions` were deleted, and `X_PWA_SYNC_FLUSH_FAILED` / `X_PWA_SYNC_INCOMPLETE` are still registered but thrown by nothing (shipped codes are stable forever): the worker POSTed to a route nothing in the framework ever mounted. The fallback branch lives in the shared message handler, so `CAPABILITY_SW_MARKERS.backgroundSync` carrying `d.type==='flush-outbox'` is what keeps it gated with the `drainOutbox` it calls. `background-sync.test.ts` and `service-worker-runtime.test.ts` run the emitted code and assert the posted messages. |
|
|
53
53
|
| Outbox | queue, replay, retry and idempotency are all `@ultimat3/realtime`'s. This package only registers the sync trigger and schedules **no retry** — `RetryPolicy`, `DEFAULT_RETRY`, `retryDelayMs`, `shouldRetry` and `BackgroundSyncOptions.retry` were deleted 2026-08-23. |
|
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
whole thesis: a hand-written service worker encodes routing decisions a second time, and
|
|
5
5
|
the second copy is the one nobody updates.
|
|
6
6
|
|
|
7
|
+
`bun add @ultimat3/pwa` · guide: [PWA And Offline](https://github.com/developerz-ai/ultimate/wiki/PWA-And-Offline)
|
|
8
|
+
|
|
7
9
|
```ts
|
|
8
10
|
const { source, precache, warnings } = generateServiceWorker(describePages(), config, buildId);
|
|
9
11
|
```
|
|
@@ -68,7 +70,7 @@ and the app dies with a blank screen and no error anyone can act on.
|
|
|
68
70
|
|---|---|
|
|
69
71
|
| Build id | immutable per deploy, derived from the commit sha; `X_BUILD_ID_MISSING` if absent |
|
|
70
72
|
| Client → server | every SW-proxied request carries `x-ultimate-build` — `@ultimat3/core`'s `BUILD_ID_HEADER` |
|
|
71
|
-
| Retention | `
|
|
73
|
+
| Retention | the server's, not this package's: `assets: { retain: { disk, builds } }` in `app.config.ts` keeps earlier builds' hashed files served. `retentionPlan` was removed in 30.0.0 |
|
|
72
74
|
| Stale client | gets `AppUpdateAvailable`, never a 404 |
|
|
73
75
|
| Forced reload | none. This package never navigates a client — the app decides what to do with the message |
|
|
74
76
|
| Preview deploys | cache names are `x-<kind>-<buildId>`, so a branch build cannot poison production |
|
|
@@ -197,7 +199,7 @@ a job boundary the class is gone and the `code` is what survives — match on th
|
|
|
197
199
|
| `routeRules`, `assetRules` | the worker's rule list: routes most specific first, runtime asset prefixes (`/islands/`) ahead of them. `routeRules(routes, personalPages)` — `'last-member'` gives a personal page a `pages` rule; a pattern matches the browser's percent-encoded pathname, and a catch-all its bare prefix |
|
|
198
200
|
| `CLEAR_PAGES_MESSAGE`, `PAGES_CLEARED_MESSAGE` | `{ type: 'clear-pages' }` — post it to the worker on sign-out; it empties every pages cache and answers `{ type: 'pages-cleared' }` |
|
|
199
201
|
| `buildPrecacheManifest` | precache entries (url + content-hash revision), size warnings |
|
|
200
|
-
| `buildId`, `detectSkew
|
|
202
|
+
| `buildId`, `detectSkew` | version skew (`detectSkew` also on `./client`) |
|
|
201
203
|
| `generateWebManifest` | the manifest + `theme-color` metas for both schemes, from a `WebManifestInput`. Called by `@ultimat3/cli` (`pwa-artifacts.ts`) `As of 2026-08-27`, so `x dev`, the container and the static export all emit `manifest.webmanifest` |
|
|
202
204
|
| `planIcons`, `requireSourceIcon`, `maskableSafeZone` | icons and splashes from one source |
|
|
203
205
|
| `BuiltinImagePipeline` | renders that plan: one square PNG per entry, deterministic |
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/pwa",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "30.0.0",
|
|
4
4
|
"description": "Generated service worker, web manifest, icons, push and version-skew handling.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ultimate",
|
|
7
|
+
"bun",
|
|
8
|
+
"framework",
|
|
9
|
+
"pwa",
|
|
10
|
+
"service-worker",
|
|
11
|
+
"offline",
|
|
12
|
+
"push"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/developerz-ai/ultimate/wiki/PWA-And-Offline",
|
|
5
15
|
"license": "MIT",
|
|
6
16
|
"type": "module",
|
|
7
17
|
"repository": {
|
|
@@ -34,10 +44,10 @@
|
|
|
34
44
|
"test": "bun test"
|
|
35
45
|
},
|
|
36
46
|
"dependencies": {
|
|
37
|
-
"@ultimat3/action": "
|
|
38
|
-
"@ultimat3/core": "
|
|
39
|
-
"@ultimat3/i18n": "
|
|
40
|
-
"@ultimat3/policy": "
|
|
41
|
-
"@ultimat3/schema": "
|
|
47
|
+
"@ultimat3/action": "30.0.0",
|
|
48
|
+
"@ultimat3/core": "30.0.0",
|
|
49
|
+
"@ultimat3/i18n": "30.0.0",
|
|
50
|
+
"@ultimat3/policy": "30.0.0",
|
|
51
|
+
"@ultimat3/schema": "30.0.0"
|
|
42
52
|
}
|
|
43
53
|
}
|
package/src/index.ts
CHANGED
|
@@ -184,7 +184,7 @@ export {
|
|
|
184
184
|
} from './vapid';
|
|
185
185
|
export type { ResolvedVapidKeys } from './vapid-keys';
|
|
186
186
|
export { DEV_VAPID_KEYS, resolveVapidKeys, usesDevVapidKeys } from './vapid-keys';
|
|
187
|
-
export type { BuildIdInput,
|
|
188
|
-
export { assertBuildId, buildId, cacheNamespace
|
|
187
|
+
export type { BuildIdInput, DeployChannel } from './version-skew';
|
|
188
|
+
export { assertBuildId, buildId, cacheNamespace } from './version-skew';
|
|
189
189
|
export type { PushNotification, PushReport, WebPusher } from './web-push';
|
|
190
190
|
export { pushToActor, webPush } from './web-push';
|
package/src/push-send.ts
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import type { Clock } from '@ultimat3/core';
|
|
6
6
|
import {
|
|
7
|
+
abandonment,
|
|
7
8
|
classifyAddress,
|
|
8
9
|
isRetryableStatus,
|
|
9
10
|
renderThrowable,
|
|
10
11
|
retryAfterSecondsOf,
|
|
11
12
|
} from '@ultimat3/core';
|
|
13
|
+
import { outboundResponse } from '@ultimat3/core/outbound';
|
|
12
14
|
import {
|
|
13
15
|
PwaPushFailedError,
|
|
14
16
|
PwaPushHostUnlistedError,
|
|
@@ -146,23 +148,28 @@ export async function sendPushMessage(input: PushSendInput): Promise<PushSendOut
|
|
|
146
148
|
}
|
|
147
149
|
let response: Response;
|
|
148
150
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
151
|
+
// Through core's `outbound()`: a deadline (one service that accepts and never answers must
|
|
152
|
+
// not hold the rest of the fan-out), the caller's signal beside the ambient one, ONE attempt
|
|
153
|
+
// (an encrypted push replayed is a second notification), and a 3xx never followed — a redirect
|
|
154
|
+
// would carry a token signed for one origin to another. `dial: 'named'`: the host passed the
|
|
155
|
+
// push-service allow-list above, so it is one this app names, never the caller's choice.
|
|
156
|
+
response = await outboundResponse(
|
|
157
|
+
{
|
|
158
|
+
url: input.target.endpoint,
|
|
159
|
+
vendor: 'push',
|
|
160
|
+
dial: 'named',
|
|
161
|
+
method: 'POST',
|
|
162
|
+
headers,
|
|
163
|
+
body,
|
|
164
|
+
deadlineMs: PUSH_SEND_TIMEOUT_MS,
|
|
165
|
+
signal: input.signal,
|
|
166
|
+
},
|
|
167
|
+
input.fetch === undefined ? {} : { fetch: input.fetch },
|
|
168
|
+
);
|
|
162
169
|
} catch (error) {
|
|
163
170
|
// The CALLER cancelled: not the push service's fault, so not the retryable class — a retry
|
|
164
171
|
// would re-deliver to every device already served. Rethrown as is; the fan-out stops.
|
|
165
|
-
if (input.signal?.aborted === true) throw error;
|
|
172
|
+
if (input.signal?.aborted === true || abandonment() !== undefined) throw error;
|
|
166
173
|
throw new PwaPushFailedError({ origin, status: null, detail: renderThrowable(error) });
|
|
167
174
|
}
|
|
168
175
|
if (response.status >= 200 && response.status < 300) {
|
package/src/push.ts
CHANGED
|
@@ -69,7 +69,12 @@ export interface PushPayload {
|
|
|
69
69
|
/** Alert again when the `tag` above is replaced. Ignored, with a warning, without one. */
|
|
70
70
|
readonly renotify?: boolean;
|
|
71
71
|
readonly requireInteraction?: boolean;
|
|
72
|
-
|
|
72
|
+
/** Buttons; a button's `url` is what tapping IT opens (this origin only), else `url` above. */
|
|
73
|
+
readonly actions?: readonly {
|
|
74
|
+
readonly action: string;
|
|
75
|
+
readonly titleKey: string;
|
|
76
|
+
readonly url?: string;
|
|
77
|
+
}[];
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
export interface RenderedNotification {
|
|
@@ -81,7 +86,11 @@ export interface RenderedNotification {
|
|
|
81
86
|
readonly badge: string | null;
|
|
82
87
|
readonly renotify: boolean;
|
|
83
88
|
readonly requireInteraction: boolean;
|
|
84
|
-
readonly actions: readonly {
|
|
89
|
+
readonly actions: readonly {
|
|
90
|
+
readonly action: string;
|
|
91
|
+
readonly title: string;
|
|
92
|
+
readonly url?: string;
|
|
93
|
+
}[];
|
|
85
94
|
readonly locale: string;
|
|
86
95
|
/**
|
|
87
96
|
* What the composing server must see and the device must not: a missing-key marker (`⟦key⟧`),
|
|
@@ -135,6 +144,7 @@ export function renderPushPayload(
|
|
|
135
144
|
actions: (payload.actions ?? []).map((action) => ({
|
|
136
145
|
action: action.action,
|
|
137
146
|
title: render(action.titleKey),
|
|
147
|
+
...(action.url === undefined ? {} : { url: action.url }),
|
|
138
148
|
})),
|
|
139
149
|
locale,
|
|
140
150
|
warnings,
|
|
@@ -189,9 +199,12 @@ self.addEventListener('push',(event)=>{
|
|
|
189
199
|
// are truthy in JS while converting to '' and '[object Object]'. !!d.tag therefore enabled
|
|
190
200
|
// renotify for a JSON [] whose converted tag is empty — the rejection this line exists to avoid.
|
|
191
201
|
const tg=typeof d.tag==='string'&&d.tag!==''?d.tag:undefined;
|
|
202
|
+
// A button's url rides in data: notificationclick sees the notification, never the push body.
|
|
203
|
+
const acts=Array.isArray(d.actions)?d.actions:[],au={};
|
|
204
|
+
for(const a of acts)if(a&&typeof a.action==='string'&&typeof a.url==='string')au[a.action]=a.url;
|
|
192
205
|
const opts={body:d.body||'',icon:d.icon||${icon},badge:d.badge||${badge},
|
|
193
206
|
tag:tg,renotify:!!d.renotify&&tg!==undefined,requireInteraction:!!d.requireInteraction,
|
|
194
|
-
lang:d.lang||undefined,actions:
|
|
207
|
+
lang:d.lang||undefined,actions:acts,data:{url:d.url||'/',actions:au}};
|
|
195
208
|
await self.registration.showNotification(d.title||'',opts);${
|
|
196
209
|
badging ? '\n if(navigator.setAppBadge)await navigator.setAppBadge();' : ''
|
|
197
210
|
}
|
|
@@ -210,7 +223,10 @@ self.addEventListener('notificationclick',(event)=>{
|
|
|
210
223
|
// PushPayload.url is a PATH and WindowClient.url is absolute, so the comparison below is only
|
|
211
224
|
// ever true after resolving — unresolved it matched no client at all and every tap opened a
|
|
212
225
|
// second window on an app the user already had open. Same resolve as the fetch block's.
|
|
213
|
-
|
|
226
|
+
// A button opens its own url when it has one; own-property only, so an action named
|
|
227
|
+
// 'constructor' never reads Object's prototype. Every other tap opens the payload's url.
|
|
228
|
+
const n=event.notification.data||{},m=n.actions;
|
|
229
|
+
const url=tapTarget(event.action&&m&&Object.hasOwn(m,event.action)?m[event.action]:n.url);
|
|
214
230
|
event.waitUntil(clients.matchAll({type:'window',includeUncontrolled:true}).then((ws)=>{
|
|
215
231
|
for(const w of ws){if(w.url===url&&'focus'in w)return w.focus()}
|
|
216
232
|
return clients.openWindow(url)
|
package/src/route-rules.ts
CHANGED
|
@@ -118,7 +118,7 @@ function toPattern(path: string): string {
|
|
|
118
118
|
* `runtimeAssets` as rules, AHEAD of every page rule: a prefix like `/islands/` names
|
|
119
119
|
* content-addressed chunks, so the first copy is the only copy and `cache-first` is exact. They are
|
|
120
120
|
* what the precache leaves out — every island in the app was precached, so a first anonymous visit
|
|
121
|
-
* downloaded the admin, KYC and payment islands too (~1 MB on
|
|
121
|
+
* downloaded the admin, KYC and payment islands too (~1 MB on one adopter's app, 22.3.2).
|
|
122
122
|
*/
|
|
123
123
|
export function assetRules(prefixes: readonly string[], scope: string): readonly RouteRule[] {
|
|
124
124
|
return [...new Set(prefixes)].sort(byCodeUnit).map((prefix) => {
|
package/src/service-worker.ts
CHANGED
|
@@ -68,8 +68,6 @@ export interface ServiceWorkerConfig {
|
|
|
68
68
|
* precached, never the default locale's page.
|
|
69
69
|
*/
|
|
70
70
|
readonly localePrefixes?: readonly string[];
|
|
71
|
-
/** Build ids whose caches must survive this activation (see `retentionPlan`). */
|
|
72
|
-
readonly retainBuildIds?: readonly string[];
|
|
73
71
|
readonly precacheWarnBytes?: number;
|
|
74
72
|
}
|
|
75
73
|
|
|
@@ -145,7 +143,8 @@ export function generateServiceWorker(
|
|
|
145
143
|
});
|
|
146
144
|
|
|
147
145
|
const usedStrategies = [...new Set(rules.map((rule) => rule.strategy))].sort();
|
|
148
|
-
|
|
146
|
+
// This build's caches only: an earlier build's files are the server's to keep (`assets.retain`).
|
|
147
|
+
const retained = [buildId];
|
|
149
148
|
|
|
150
149
|
const blocks: string[] = [
|
|
151
150
|
header(buildId),
|
|
@@ -232,7 +231,7 @@ function serializeRules(rules: readonly RouteRule[]): string {
|
|
|
232
231
|
* of the page that was precached, and online every precached byte is downloaded a second time.
|
|
233
232
|
* Each entry is fetched and stored on its own, `As of 22.3.4`: `addAll`'s all-or-nothing was meant
|
|
234
233
|
* to stop a half-populated precache from activating, and instead one 404 blocked every install
|
|
235
|
-
* of every deploy (
|
|
234
|
+
* of every deploy (one adopter, 22.3.2) — a stuck worker is worse than a missing offline copy.
|
|
236
235
|
*
|
|
237
236
|
* The separator in front of `v=` is chosen per entry, because `PrecacheAsset.url` is public API
|
|
238
237
|
* and a bundler emits a query of its own: a fixed `?` built `...?locale=en?v=<rev>`, and a single
|
|
@@ -248,7 +247,7 @@ function serializeRules(rules: readonly RouteRule[]): string {
|
|
|
248
247
|
* navigation is answered network-first by the new worker.
|
|
249
248
|
*
|
|
250
249
|
* The fill is THROTTLED to `PRECACHE_CONCURRENCY` requests in flight: `Promise.all` over every
|
|
251
|
-
* entry opened them all at once (72 entries, 2.9 MB on
|
|
250
|
+
* entry opened them all at once (72 entries, 2.9 MB on one adopter's app), on the visitor's first
|
|
252
251
|
* visit, against the same connection their first click needs. Nothing waits on the fill but the
|
|
253
252
|
* worker's own activation, so slower is free.
|
|
254
253
|
*/
|
|
@@ -286,7 +285,8 @@ function activateBlock(): string {
|
|
|
286
285
|
return `
|
|
287
286
|
self.addEventListener('activate',(event)=>{
|
|
288
287
|
event.waitUntil((async()=>{
|
|
289
|
-
//
|
|
288
|
+
// Every other build's caches go: a tab open across a release gets earlier chunks from the
|
|
289
|
+
// server's assets.retain window, never from a cache this worker keeps.
|
|
290
290
|
const names=await caches.keys();
|
|
291
291
|
await Promise.all(names.filter((n)=>n.startsWith('x-')&&RETAINED.indexOf(n)===-1)
|
|
292
292
|
.map((n)=>caches.delete(n)));
|
package/src/strategies.ts
CHANGED
|
@@ -64,7 +64,7 @@ export interface PwaRoute {
|
|
|
64
64
|
* they are `immutable` in the browser's HTTP cache. `static: 'cache-first'` and
|
|
65
65
|
* `isr`/`stream: 'stale-while-revalidate'` answered an ONLINE navigation from the copy the old
|
|
66
66
|
* worker held, and that copy is the old HTML naming the old hashed CSS and islands, so a visitor saw
|
|
67
|
-
* a deploy only after Shift+F5 (measured on
|
|
67
|
+
* a deploy only after Shift+F5 (measured on one adopter's app, 22.3.1). A precached or pages-cached
|
|
68
68
|
* document is the OFFLINE answer, which `networkFirst` already is on a failed fetch; the render
|
|
69
69
|
* mode still decides WHERE that copy lives (`cacheFor`: precache or pages), not whether it is
|
|
70
70
|
* served while the network answers. A per-route `strategy` is still the override.
|
package/src/version-skew.ts
CHANGED
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
* a blank screen. Nothing here is optional:
|
|
5
5
|
*
|
|
6
6
|
* immutable build id per deploy → the client sends it on every request →
|
|
7
|
-
* old builds' assets
|
|
7
|
+
* old builds' assets stay served (`assets.retain`) → a stale client gets
|
|
8
8
|
* `AppUpdateAvailable`, never a 404.
|
|
9
9
|
*
|
|
10
10
|
* The app decides what to do with that message. This package never navigates a client.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { finiteCount } from '@ultimat3/core';
|
|
14
13
|
import { BuildIdMissingError } from './errors';
|
|
15
14
|
|
|
16
15
|
// The header every proxied request carries is core's `BUILD_ID_HEADER`, the document meta core's
|
|
@@ -74,41 +73,5 @@ export function cacheNamespace(id: string, kind: 'precache' | 'runtime' | 'pages
|
|
|
74
73
|
return `x-${kind}-${id}`;
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
export interface Deploy {
|
|
78
|
-
readonly buildId: string;
|
|
79
|
-
/** Epoch milliseconds. */
|
|
80
|
-
readonly deployedAt: number;
|
|
81
|
-
readonly channel?: DeployChannel;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface RetentionPlan {
|
|
85
|
-
readonly retain: readonly string[];
|
|
86
|
-
readonly evict: readonly string[];
|
|
87
|
-
readonly caches: readonly string[];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Keep the last N builds' assets alive. N is how many deploys a tab may sit open across
|
|
92
|
-
* before it is allowed to break; 3 is the sane default for a daily-deploy team.
|
|
93
|
-
*/
|
|
94
|
-
export function retentionPlan(deploys: readonly Deploy[], keep = 3): RetentionPlan {
|
|
95
|
-
// `Math.max` is not a validator, it PROPAGATES: `Math.max(1, NaN)` is `NaN`, `slice(0, NaN)` is
|
|
96
|
-
// `[]`, and the plan then retains nothing and evicts every deploy — the running one included,
|
|
97
|
-
// which is the case `never evicts everything` pins as impossible. `0` keeps its meaning below.
|
|
98
|
-
const bound = Math.max(1, finiteCount('retentionPlan', 'keep', keep));
|
|
99
|
-
const ordered = [...deploys].sort((a, b) => b.deployedAt - a.deployedAt);
|
|
100
|
-
const retained = ordered.slice(0, bound);
|
|
101
|
-
const evicted = ordered.slice(bound);
|
|
102
|
-
return {
|
|
103
|
-
retain: retained.map((d) => d.buildId),
|
|
104
|
-
evict: evicted.map((d) => d.buildId),
|
|
105
|
-
caches: retained.flatMap((d) => [
|
|
106
|
-
cacheNamespace(d.buildId, 'precache'),
|
|
107
|
-
cacheNamespace(d.buildId, 'runtime'),
|
|
108
|
-
cacheNamespace(d.buildId, 'pages'),
|
|
109
|
-
]),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
76
|
// `SkewState`, `detectSkew` and `AppUpdateAvailable` — the page's half of skew — live in `skew.ts`,
|
|
114
77
|
// which the browser entry (`client.ts`) re-exports without this file's error table.
|