@timber-js/app 0.2.0-alpha.223 → 0.2.0-alpha.225
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/dist/_chunks/{actions-7dTXYJfu.js → actions-B1xSIv32.js} +2 -2
- package/dist/_chunks/{actions-7dTXYJfu.js.map → actions-B1xSIv32.js.map} +1 -1
- package/dist/_chunks/{cache-api-TDZ4hlDc.js → cache-api-DsSXA4Sp.js} +68 -47
- package/dist/_chunks/cache-api-DsSXA4Sp.js.map +1 -0
- package/dist/_chunks/{cli-check-Dv3f8d2j.js → cli-check-B33yhAPa.js} +2 -2
- package/dist/_chunks/{cli-check-Dv3f8d2j.js.map → cli-check-B33yhAPa.js.map} +1 -1
- package/dist/_chunks/cli-context-BPdyA7Fp.js +1 -0
- package/dist/_chunks/{cli-context-CbZp32SK.js → cli-context-CwTKMjVe.js} +10 -2
- package/dist/_chunks/cli-context-CwTKMjVe.js.map +1 -0
- package/dist/_chunks/{dev-server-C61GWpGg.js → dev-server-B7o4As0l.js} +15 -1
- package/dist/_chunks/dev-server-B7o4As0l.js.map +1 -0
- package/dist/_chunks/dev-server-hZzmbMvK.js +1 -0
- package/dist/_chunks/{error-boundary-DRQXGWCp.js → error-boundary-D3YyVVuP.js} +2 -2
- package/dist/_chunks/{error-boundary-DRQXGWCp.js.map → error-boundary-D3YyVVuP.js.map} +1 -1
- package/dist/_chunks/{singleflight-BChPMjwH.js → singleflight-CzoOVB9Y.js} +2 -3
- package/dist/_chunks/singleflight-CzoOVB9Y.js.map +1 -0
- package/dist/_chunks/{status-page-marker-XIQXlTOb.js → status-page-marker-C8POawuF.js} +2 -2
- package/dist/_chunks/{status-page-marker-XIQXlTOb.js.map → status-page-marker-C8POawuF.js.map} +1 -1
- package/dist/adapters/cloudflare-kv-cache.d.ts +0 -1
- package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -1
- package/dist/adapters/cloudflare-kv-cache.js.map +1 -1
- package/dist/cache/index.d.ts +5 -5
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cache/redis-handler.d.ts +0 -1
- package/dist/cache/redis-handler.d.ts.map +1 -1
- package/dist/cache/singleflight.d.ts +12 -2
- package/dist/cache/singleflight.d.ts.map +1 -1
- package/dist/cache/stable-stringify.d.ts +6 -0
- package/dist/cache/stable-stringify.d.ts.map +1 -1
- package/dist/cache/tag-aware-handler.d.ts +0 -1
- package/dist/cache/tag-aware-handler.d.ts.map +1 -1
- package/dist/cache/timber-cache.d.ts +1 -1
- package/dist/cache/timber-cache.d.ts.map +1 -1
- package/dist/cli-context.d.ts +8 -0
- package/dist/cli-context.d.ts.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +9 -3
- package/dist/cli.js.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/internal.js +3 -3
- package/dist/config-types.d.ts +18 -0
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +545 -9
- package/dist/index.js.map +1 -1
- package/dist/plugins/client-in-server-package-deps.d.ts +63 -0
- package/dist/plugins/client-in-server-package-deps.d.ts.map +1 -0
- package/dist/plugins/optimize-package-imports-defaults.d.ts +13 -0
- package/dist/plugins/optimize-package-imports-defaults.d.ts.map +1 -0
- package/dist/plugins/optimize-package-imports.d.ts +124 -0
- package/dist/plugins/optimize-package-imports.d.ts.map +1 -0
- package/dist/server/flight-injector-core.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/internal.js +162 -33
- package/dist/server/internal.js.map +1 -1
- package/dist/server/pipeline-helpers.d.ts +5 -2
- package/dist/server/pipeline-helpers.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/prebuilt-runtime.d.ts.map +1 -1
- package/dist/server/response-framing.d.ts +43 -0
- package/dist/server/response-framing.d.ts.map +1 -0
- package/docs/api/34-api-config.mdx +20 -0
- package/package.json +2 -2
- package/src/adapters/cloudflare-kv-cache.ts +1 -5
- package/src/cache/index.ts +7 -27
- package/src/cache/redis-handler.ts +1 -5
- package/src/cache/singleflight.ts +17 -5
- package/src/cache/stable-stringify.ts +53 -0
- package/src/cache/tag-aware-handler.ts +1 -5
- package/src/cache/timber-cache.ts +55 -52
- package/src/cli-context.ts +9 -0
- package/src/cli.ts +16 -0
- package/src/config-types.ts +18 -0
- package/src/config-validation.ts +20 -0
- package/src/index.ts +4 -0
- package/src/plugins/client-in-server-package-deps.ts +139 -0
- package/src/plugins/optimize-package-imports-defaults.ts +88 -0
- package/src/plugins/optimize-package-imports.ts +439 -0
- package/src/server/flight-injector-core.ts +13 -9
- package/src/server/pipeline-helpers.ts +9 -5
- package/src/server/pipeline.ts +7 -0
- package/src/server/prebuilt-runtime.ts +125 -121
- package/src/server/response-framing.ts +59 -0
- package/dist/_chunks/cache-api-TDZ4hlDc.js.map +0 -1
- package/dist/_chunks/cli-context-CbZp32SK.js.map +0 -1
- package/dist/_chunks/cli-context-n5hmkdla.js +0 -1
- package/dist/_chunks/dev-server-C61GWpGg.js.map +0 -1
- package/dist/_chunks/dev-server-CBvvM7Lr.js +0 -1
- package/dist/_chunks/singleflight-BChPMjwH.js.map +0 -1
|
@@ -211,7 +211,10 @@ export declare function loadFallbackModule(file: ManifestLoader, req: Request, s
|
|
|
211
211
|
* per request that joined it, so the report happens inside the body. A
|
|
212
212
|
* body still running when the singleflight times out is reported then,
|
|
213
213
|
* with the timeout error (the signal's reason), and its later rejection
|
|
214
|
-
* is
|
|
214
|
+
* is not reported again.
|
|
215
|
+
* - **Settles with the work's outcome.** The value or the error passes
|
|
216
|
+
* through, so an inline re-render that joined this flight receives the
|
|
217
|
+
* captured bytes, or the failure, instead of `undefined`.
|
|
215
218
|
* - **Against the request whose stale read started it**, read from the
|
|
216
219
|
* request context the work runs in. With no request (the build-time
|
|
217
220
|
* capture store) it is only logged.
|
|
@@ -220,5 +223,5 @@ export declare function loadFallbackModule(file: ManifestLoader, req: Request, s
|
|
|
220
223
|
* revalidated page tree included). The request's own abort does not
|
|
221
224
|
* suppress the report: the work runs after the response either way.
|
|
222
225
|
*/
|
|
223
|
-
export declare function runBackgroundFlight(signal: AbortSignal, work: () => Promise<
|
|
226
|
+
export declare function runBackgroundFlight<T>(signal: AbortSignal, work: () => Promise<T>, log: (error: unknown) => void): Promise<T>;
|
|
224
227
|
//# sourceMappingURL=pipeline-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline-helpers.d.ts","sourceRoot":"","sources":["../../src/server/pipeline-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAU9C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAElF,OAAO,EAAsC,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAClG,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAuC,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAUvD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,OAAO,EACZ,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,YAAY,GACvB,QAAQ,GAAG,IAAI,CAWjB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,OAAO,EACZ,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,OAAO,EAC3B,UAAU,EAAE,YAAY,GACvB,QAAQ,GAAG,IAAI,CAQjB;AAeD;;;;GAIG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AOG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAA;CAAO,GAC5E,IAAI,CAIN;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,OAAO,EACZ,QAAQ,CAAC,EAAE,SAAS,mBAAmB,EAAE,GACxC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAwBzC;AAiBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAC5B,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/server/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAa3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/server/pipeline.ts"],"names":[],"mappings":"AAA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AAc,CAAC;IAC3B,wEAAwE;IACxE,WAAW,CAAC,EAAE,oBAAoB,CAAC;CACpC;AAID;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA4S1F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prebuilt-runtime.d.ts","sourceRoot":"","sources":["../../src/server/prebuilt-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAkDH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"prebuilt-runtime.d.ts","sourceRoot":"","sources":["../../src/server/prebuilt-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAkDH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAqB3E;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAElE;AAYD;;;;;;GAMG;AACH,MAAM,WAAW,wBAAwB;IACvC,wEAAwE;IACxE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IACjE,2EAA2E;IAC3E,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;;OAIG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;CAC1C;AAED,2DAA2D;AAE3D,KAAK,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC;AAY/C,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,EAAE,wBAAwB,CAAC;CACnC;AAoDD,UAAU,YAAY;IACpB,wBAAwB,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnF,YAAY,EAAE,YAAY,CAAC;CAC5B;AAID;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAEvD;AAgeD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,eAAe,EAClD,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,CAAC,EACZ,OAAO,GAAE,wBAA6B,GACrC,CAAC,CAuFH;AAED,qDAAqD;AACrD,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAEpF;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,IAAI,WAAW,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAE/E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upstream framing on forwarded responses (GHSA-pc58-hwjq-p385 class,
|
|
3
|
+
* design/13-security.md #42).
|
|
4
|
+
*
|
|
5
|
+
* `fetch()` transparently decodes a gzip/br/deflate/zstd body but keeps the
|
|
6
|
+
* upstream's `Content-Encoding` and `Content-Length`, along with its
|
|
7
|
+
* connection-level headers. A route handler, proxy.ts or middleware that
|
|
8
|
+
* returns that `Response` — directly or through
|
|
9
|
+
* `new Response(res.body, { headers: res.headers })` — would otherwise send
|
|
10
|
+
* the decoded bytes framed by the encoded length. On a keep-alive HTTP/1.1
|
|
11
|
+
* connection the surplus bytes are read as the *next* response: a reverse
|
|
12
|
+
* proxy that queues several clients on one backend connection hands an
|
|
13
|
+
* upstream-controlled response to another client, or one client's response
|
|
14
|
+
* to the wrong one.
|
|
15
|
+
*
|
|
16
|
+
* Whether a body was decoded is not observable from the `Response` (the
|
|
17
|
+
* header-copying proxy pattern produces an ordinary constructed `Response`),
|
|
18
|
+
* so the rule is stated on the headers alone:
|
|
19
|
+
*
|
|
20
|
+
* - A response that declares `Content-Encoding` loses it and its
|
|
21
|
+
* `Content-Length`. The length described the encoded bytes; the server
|
|
22
|
+
* frames what it actually writes, and the adapter's compression step may
|
|
23
|
+
* re-encode it. Matches Next.js (vercel/next.js#101108). The cost: a
|
|
24
|
+
* handler cannot hand back a pre-compressed body under its own
|
|
25
|
+
* `Content-Encoding`.
|
|
26
|
+
* - Hop-by-hop headers (RFC 9110 §7.6.1) describe the upstream's
|
|
27
|
+
* connection, not this one, and are owned by the server writing the
|
|
28
|
+
* socket. They are always dropped. A forwarded `Connection: keep-alive` otherwise
|
|
29
|
+
* overrides the client's `Connection: close`, and a forwarded
|
|
30
|
+
* `Transfer-Encoding` claims a framing the server did not choose.
|
|
31
|
+
* The extra headers a `Connection` value names are deliberately not
|
|
32
|
+
* honored: the response's headers here are the upstream's merged with
|
|
33
|
+
* the app's own (cookies, middleware headers), and an upstream sending
|
|
34
|
+
* `Connection: set-cookie` must not be able to delete the app's session.
|
|
35
|
+
* - A `Content-Length` on an unencoded response is the route's own claim
|
|
36
|
+
* and is kept — a HEAD response relies on it (head-requests.test.ts).
|
|
37
|
+
*
|
|
38
|
+
* Applied at the pipeline's single exit, before compression, so every
|
|
39
|
+
* producer is covered — including ones added later. Timber's own renderers
|
|
40
|
+
* set none of these headers inside the pipeline.
|
|
41
|
+
*/
|
|
42
|
+
export declare function dropUpstreamFraming(response: Response): void;
|
|
43
|
+
//# sourceMappingURL=response-framing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-framing.d.ts","sourceRoot":"","sources":["../../src/server/response-framing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAYH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAM5D"}
|
|
@@ -29,6 +29,7 @@ interface TimberUserConfig {
|
|
|
29
29
|
stripSensitiveFields?: boolean | readonly string[];
|
|
30
30
|
};
|
|
31
31
|
pageExtensions?: string[];
|
|
32
|
+
optimizePackageImports?: string[];
|
|
32
33
|
slowRequestMs?: number;
|
|
33
34
|
renderTimeoutMs?: number;
|
|
34
35
|
devBrowserLogs?: 'error' | 'warn' | 'info' | 'none';
|
|
@@ -167,6 +168,25 @@ Status/error conventions (`error.*`, `global-error.*`, status files like `404.*`
|
|
|
167
168
|
|
|
168
169
|
Two files claiming the same convention in one directory (e.g. `page.tsx` + `page.jsx`) are a build error — filesystem order is platform-dependent, so timber refuses to pick one silently.
|
|
169
170
|
|
|
171
|
+
### `optimizePackageImports`
|
|
172
|
+
|
|
173
|
+
- **Type:** `string[]`
|
|
174
|
+
- **Default:** a built-in list (`lucide-react`, `date-fns`, `lodash-es`, `@heroicons/react/24/solid`, `react-icons/fa`, `@mui/material`, `recharts`, …, the same one Next.js uses)
|
|
175
|
+
|
|
176
|
+
Packages whose entry file (a "barrel") re-exports many modules. For these packages, timber imports each name from the module that defines it, so `import { Play } from 'lucide-react'` compiles the one icon module that defines `Play`, not every icon the package re-exports. On relisten.net this cut the first dev request from 18s to 5s and the production build from 14s to 8s.
|
|
177
|
+
|
|
178
|
+
Your list adds to the built-in one. Entries are exact import specifiers, so list each entry point you import from (`'react-icons/fa'`, not `'react-icons'`). Only list a package if its modules don't rely on each other's import-time side effects. The modules you don't import are no longer loaded:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
export default defineConfig({
|
|
182
|
+
optimizePackageImports: ['@acme/icons'],
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
It applies to production builds. In `timber dev` it applies to server rendering of packages that Vite compiles itself, which in practice means packages with a `react` peer dependency (icon sets, component libraries). Dev hands other packages to Node, which loads them without compiling.
|
|
187
|
+
|
|
188
|
+
When timber can't map an import exactly, it leaves the import as written. For example: a namespace import, a name the barrel only re-exports through `export *` or from another package, or a barrel that runs code of its own or carries a `'use client'` or `'use server'` directive.
|
|
189
|
+
|
|
170
190
|
### `debug`
|
|
171
191
|
|
|
172
192
|
- **Type:** `boolean`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timber-js/app",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.225",
|
|
4
4
|
"description": "Vite-native React framework built for Servers and Serverless Platforms — correct HTTP semantics, real status codes, pages that work without JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
"cookie": "^2.0.1",
|
|
158
158
|
"jsonc-parser": "^3.3.1",
|
|
159
159
|
"magic-string": "^1.4.5",
|
|
160
|
-
"nitro": "3.0.
|
|
160
|
+
"nitro": "3.0.261102-rc",
|
|
161
161
|
"oxc-transform-react": "^0.156.0",
|
|
162
162
|
"srvx": "^1.0.8"
|
|
163
163
|
},
|
|
@@ -113,11 +113,7 @@ export class CloudflareKVCacheHandler implements CacheHandler {
|
|
|
113
113
|
return { value: entry.value, stale };
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
async set(
|
|
117
|
-
key: string,
|
|
118
|
-
value: unknown,
|
|
119
|
-
opts: { ttl: number; tags: string[]; generation?: number }
|
|
120
|
-
): Promise<void> {
|
|
116
|
+
async set(key: string, value: unknown, opts: { ttl: number; tags: string[] }): Promise<void> {
|
|
121
117
|
warnLossyJsonValue(value, key);
|
|
122
118
|
const kv = this.getKV();
|
|
123
119
|
const entry: KVCacheEntry = {
|
package/src/cache/index.ts
CHANGED
|
@@ -4,11 +4,7 @@ import { estimateByteSize } from './sizeof.ts';
|
|
|
4
4
|
|
|
5
5
|
export interface CacheHandler {
|
|
6
6
|
get(key: string): Promise<{ value: unknown; stale: boolean } | null>;
|
|
7
|
-
set(
|
|
8
|
-
key: string,
|
|
9
|
-
value: unknown,
|
|
10
|
-
opts: { ttl: number; tags: string[]; generation?: number }
|
|
11
|
-
): Promise<void>;
|
|
7
|
+
set(key: string, value: unknown, opts: { ttl: number; tags: string[] }): Promise<void>;
|
|
12
8
|
invalidate(opts: { key?: string; tag?: string }): Promise<void>;
|
|
13
9
|
}
|
|
14
10
|
|
|
@@ -18,8 +14,11 @@ export interface CacheOptions<Fn extends (...args: any[]) => any> {
|
|
|
18
14
|
key?: (...args: Parameters<Fn>) => string;
|
|
19
15
|
staleWhileRevalidate?: boolean;
|
|
20
16
|
tags?: string[] | ((...args: Parameters<Fn>) => string[]);
|
|
21
|
-
/** Timeout (ms) for
|
|
22
|
-
* permanently blocking all future callers for the same cache key
|
|
17
|
+
/** Timeout (ms) for an execution this wrapper starts. Prevents hung fn() from
|
|
18
|
+
* permanently blocking all future callers for the same cache key (TIM-518).
|
|
19
|
+
* A call that joins an execution already in flight for the key waits under
|
|
20
|
+
* that execution's timeout, so wrappers sharing an explicit `key` should
|
|
21
|
+
* agree on it (design/06 §Residual write races). */
|
|
23
22
|
timeoutMs?: number;
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -42,7 +41,6 @@ export class MemoryCacheHandler implements CacheHandler {
|
|
|
42
41
|
string,
|
|
43
42
|
{ value: unknown; expiresAt: number; tags: string[]; byteSize: number }
|
|
44
43
|
>();
|
|
45
|
-
private generations = new Map<string, number>();
|
|
46
44
|
private maxEntries: number;
|
|
47
45
|
private maxBytes: number | undefined;
|
|
48
46
|
private maxEntryBytes: number | undefined;
|
|
@@ -69,17 +67,7 @@ export class MemoryCacheHandler implements CacheHandler {
|
|
|
69
67
|
return { value: entry.value, stale };
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
async set(
|
|
73
|
-
key: string,
|
|
74
|
-
value: unknown,
|
|
75
|
-
opts: { ttl: number; tags: string[]; generation?: number }
|
|
76
|
-
) {
|
|
77
|
-
// CAS guard: skip write if a newer generation has already been written
|
|
78
|
-
if (opts.generation !== undefined) {
|
|
79
|
-
const current = this.generations.get(key) ?? 0;
|
|
80
|
-
if (opts.generation < current) return;
|
|
81
|
-
}
|
|
82
|
-
|
|
70
|
+
async set(key: string, value: unknown, opts: { ttl: number; tags: string[] }) {
|
|
83
71
|
const byteSize = this._trackBytes ? estimateByteSize(value) : 0;
|
|
84
72
|
|
|
85
73
|
// Reject entries exceeding per-entry byte limit
|
|
@@ -110,11 +98,6 @@ export class MemoryCacheHandler implements CacheHandler {
|
|
|
110
98
|
}
|
|
111
99
|
}
|
|
112
100
|
|
|
113
|
-
// Record generation only after all admission checks pass
|
|
114
|
-
if (opts.generation !== undefined) {
|
|
115
|
-
this.generations.set(key, opts.generation);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
101
|
this.store.set(key, {
|
|
119
102
|
value,
|
|
120
103
|
expiresAt: Date.now() + opts.ttl * 1000,
|
|
@@ -131,14 +114,12 @@ export class MemoryCacheHandler implements CacheHandler {
|
|
|
131
114
|
this.currentBytes -= entry.byteSize;
|
|
132
115
|
this.store.delete(opts.key);
|
|
133
116
|
}
|
|
134
|
-
this.generations.delete(opts.key);
|
|
135
117
|
}
|
|
136
118
|
if (opts.tag) {
|
|
137
119
|
for (const [key, entry] of this.store) {
|
|
138
120
|
if (entry.tags.includes(opts.tag)) {
|
|
139
121
|
this.currentBytes -= entry.byteSize;
|
|
140
122
|
this.store.delete(key);
|
|
141
|
-
this.generations.delete(key);
|
|
142
123
|
}
|
|
143
124
|
}
|
|
144
125
|
}
|
|
@@ -161,7 +142,6 @@ export class MemoryCacheHandler implements CacheHandler {
|
|
|
161
142
|
const entry = this.store.get(oldest)!;
|
|
162
143
|
this.currentBytes -= entry.byteSize;
|
|
163
144
|
this.store.delete(oldest);
|
|
164
|
-
this.generations.delete(oldest);
|
|
165
145
|
}
|
|
166
146
|
}
|
|
167
147
|
}
|
|
@@ -169,11 +169,7 @@ export class RedisCacheHandler implements CacheHandler {
|
|
|
169
169
|
return { value: entry.value, stale };
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
async set(
|
|
173
|
-
key: string,
|
|
174
|
-
value: unknown,
|
|
175
|
-
opts: { ttl: number; tags: string[]; generation?: number }
|
|
176
|
-
): Promise<void> {
|
|
172
|
+
async set(key: string, value: unknown, opts: { ttl: number; tags: string[] }): Promise<void> {
|
|
177
173
|
warnLossyJsonValue(value, key);
|
|
178
174
|
const ck = this.cacheKey(key);
|
|
179
175
|
const expiresAt = Date.now() + opts.ttl * 1000;
|
|
@@ -12,12 +12,22 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
export interface SingleflightOptions {
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Default maximum time (ms) a coalesced call may run before being
|
|
17
|
+
* rejected. A `timeoutMs` passed to `do()` overrides it for that flight.
|
|
18
|
+
*/
|
|
16
19
|
timeoutMs?: number;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export interface Singleflight {
|
|
20
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Run `fn` once per key; concurrent callers join the in-flight call.
|
|
25
|
+
* `timeoutMs` (default: the instance option) applies to the flight this
|
|
26
|
+
* call starts — a caller that joins an existing flight inherits its
|
|
27
|
+
* timeout. Passing it per call lets callers with different timeouts
|
|
28
|
+
* share one keyspace instead of each needing its own instance.
|
|
29
|
+
*/
|
|
30
|
+
do<T>(key: string, fn: (signal: AbortSignal) => Promise<T>, timeoutMs?: number): Promise<T>;
|
|
21
31
|
/** Return the in-flight promise for a key, or undefined if none. */
|
|
22
32
|
get(key: string): Promise<unknown> | undefined;
|
|
23
33
|
}
|
|
@@ -35,10 +45,12 @@ export class SingleflightTimeoutError extends Error {
|
|
|
35
45
|
|
|
36
46
|
export function createSingleflight(opts?: SingleflightOptions): Singleflight {
|
|
37
47
|
const inflight = new Map<string, Promise<unknown>>();
|
|
38
|
-
const timeoutMs = opts?.timeoutMs;
|
|
39
|
-
|
|
40
48
|
return {
|
|
41
|
-
do<T>(
|
|
49
|
+
do<T>(
|
|
50
|
+
key: string,
|
|
51
|
+
fn: (signal: AbortSignal) => Promise<T>,
|
|
52
|
+
timeoutMs = opts?.timeoutMs
|
|
53
|
+
): Promise<T> {
|
|
42
54
|
const existing = inflight.get(key);
|
|
43
55
|
if (existing) return existing as Promise<T>;
|
|
44
56
|
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* instances holding data behind getters or internal slots) — throw instead:
|
|
12
12
|
* every such value would collapse to the same cache key, silently returning
|
|
13
13
|
* one argument's cached data for another (TIM-1020).
|
|
14
|
+
*
|
|
15
|
+
* The same rule covers what JSON.stringify flattens: NaN, Infinity and
|
|
16
|
+
* -Infinity all become `null` there and -0 becomes `0`, and a typed array
|
|
17
|
+
* becomes a plain index object, so `Uint8Array`, `Int8Array` and
|
|
18
|
+
* `{ "0": 1 }` with the same values would share an entry. Both get a
|
|
19
|
+
* representation of their own (GHSA-rhh4-g77r-r9qj class).
|
|
14
20
|
*/
|
|
15
21
|
export function stableStringify(value: unknown): string {
|
|
16
22
|
if (value === null || value === undefined) return String(value);
|
|
@@ -22,6 +28,7 @@ export function stableStringify(value: unknown): string {
|
|
|
22
28
|
'all such values would collide. Provide an explicit `key` option to cache().'
|
|
23
29
|
);
|
|
24
30
|
}
|
|
31
|
+
if (type === 'number') return stringifyNumber(value as number);
|
|
25
32
|
if (type !== 'object') return JSON.stringify(value);
|
|
26
33
|
|
|
27
34
|
if (Array.isArray(value)) {
|
|
@@ -38,6 +45,18 @@ export function stableStringify(value: unknown): string {
|
|
|
38
45
|
if (json !== value) return stableStringify(json);
|
|
39
46
|
}
|
|
40
47
|
|
|
48
|
+
// A typed array is tagged with its element type, which decides how its
|
|
49
|
+
// bytes are read. Buffer never gets here (its toJSON runs above); DataView
|
|
50
|
+
// has no own state and throws below. The `<Type>Array(` prefix cannot
|
|
51
|
+
// collide with object, array, string, Map( or Set( output.
|
|
52
|
+
const typed = asTypedArray(value);
|
|
53
|
+
if (typed) {
|
|
54
|
+
const elements = Array.from(typed.view, (element) =>
|
|
55
|
+
typeof element === 'bigint' ? `${element}n` : stringifyNumber(element)
|
|
56
|
+
);
|
|
57
|
+
return `${typed.name}(${elements.join(',')})`;
|
|
58
|
+
}
|
|
59
|
+
|
|
41
60
|
// Map/Set have no enumerable own properties — serialize entries explicitly.
|
|
42
61
|
// Entries are sorted after serialization so insertion order doesn't change
|
|
43
62
|
// the key. The Map(/Set( prefixes can't collide with object ('{'), array
|
|
@@ -82,3 +101,37 @@ export function stableStringify(value: unknown): string {
|
|
|
82
101
|
|
|
83
102
|
return '{' + pairs.join(',') + '}';
|
|
84
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* JSON.stringify for a number, except the values it maps onto another
|
|
107
|
+
* value's output: NaN, ±Infinity (all `null`) and -0 (`0`). Their bare
|
|
108
|
+
* tokens cannot be produced by JSON output, so they cannot collide.
|
|
109
|
+
*/
|
|
110
|
+
function stringifyNumber(value: number): string {
|
|
111
|
+
if (Number.isFinite(value)) return Object.is(value, -0) ? '-0' : JSON.stringify(value);
|
|
112
|
+
return String(value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The %TypedArray%.prototype[Symbol.toStringTag] getter returns the
|
|
117
|
+
* element type name for a real typed array and undefined for anything else
|
|
118
|
+
* (spec §23.2.3.38). It reads an internal slot, so it holds across realms —
|
|
119
|
+
* unlike `instanceof`, which sent a DataView from a `vm` context into the
|
|
120
|
+
* typed-array branch, where it serialized as an empty, shared key — and it
|
|
121
|
+
* cannot be spoofed by an own `Symbol.toStringTag`.
|
|
122
|
+
*/
|
|
123
|
+
const typedArrayTag = Object.getOwnPropertyDescriptor(
|
|
124
|
+
Object.getPrototypeOf(Uint8Array.prototype),
|
|
125
|
+
Symbol.toStringTag
|
|
126
|
+
)?.get;
|
|
127
|
+
|
|
128
|
+
function asTypedArray(
|
|
129
|
+
value: object
|
|
130
|
+
): { name: string; view: ArrayLike<number | bigint> } | undefined {
|
|
131
|
+
const name: unknown = typedArrayTag?.call(value);
|
|
132
|
+
if (typeof name !== 'string') return undefined;
|
|
133
|
+
// The getter returning a name proves `value` is a typed array, but TS
|
|
134
|
+
// cannot see through a getter call to narrow on it, and `instanceof`
|
|
135
|
+
// (which it can narrow on) is the realm-bound check this replaces.
|
|
136
|
+
return { name, view: value as ArrayLike<number | bigint> };
|
|
137
|
+
}
|
|
@@ -125,11 +125,7 @@ export class TagAwareCacheHandler implements CacheHandler {
|
|
|
125
125
|
return { value: entry.value, stale };
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
async set(
|
|
129
|
-
key: string,
|
|
130
|
-
value: unknown,
|
|
131
|
-
opts: { ttl: number; tags: string[]; generation?: number }
|
|
132
|
-
): Promise<void> {
|
|
128
|
+
async set(key: string, value: unknown, opts: { ttl: number; tags: string[] }): Promise<void> {
|
|
133
129
|
const physicalTtl = Math.max(opts.ttl * 2 + 60, 120);
|
|
134
130
|
const strategy = this.strategy;
|
|
135
131
|
|
|
@@ -14,32 +14,26 @@ import { fnv1aHash } from './fast-hash.ts';
|
|
|
14
14
|
import { devDataCacheKey } from '../server/prebuilt/dev-store.ts';
|
|
15
15
|
import { KeyDisciplineViolation, observeKeyDiscipline } from './key-discipline.ts';
|
|
16
16
|
|
|
17
|
-
let defaultSingleflight = createSingleflight();
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* while the handler still holds the old higher generation, causing fresh
|
|
26
|
-
* writes to be rejected as stale.
|
|
18
|
+
* The one flight keyspace for every cache() wrapper. A wrapper with its own
|
|
19
|
+
* `timeoutMs` passes it per call rather than getting a private instance:
|
|
20
|
+
* two wrappers that share an explicit key must coalesce, or an older,
|
|
21
|
+
* slower execution can overwrite a newer result — there is no write
|
|
22
|
+
* ordering in the CacheHandler contract to stop it (TIM-1447).
|
|
27
23
|
*/
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return gen;
|
|
33
|
-
}
|
|
24
|
+
const flights = createSingleflight();
|
|
25
|
+
|
|
26
|
+
/** Timeout for calls without a per-wrapper `timeoutMs`; set at boot. */
|
|
27
|
+
let defaultTimeoutMs: number | undefined;
|
|
34
28
|
|
|
35
29
|
/**
|
|
36
|
-
* Set the timeout for
|
|
30
|
+
* Set the timeout for cache calls without a per-call timeoutMs.
|
|
37
31
|
* Called at framework boot with renderTimeoutMs from timber.config.ts so that
|
|
38
32
|
* cache calls without a per-call timeoutMs still get deadlock protection.
|
|
39
33
|
* See design/06-caching.md §"Singleflight Timeout — Deadlock Risk".
|
|
40
34
|
*/
|
|
41
35
|
export function setDefaultSingleflightTimeout(timeoutMs: number): void {
|
|
42
|
-
|
|
36
|
+
defaultTimeoutMs = timeoutMs;
|
|
43
37
|
}
|
|
44
38
|
|
|
45
39
|
/**
|
|
@@ -148,19 +142,15 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
148
142
|
// rate limit and, unlike deriveFallbackFnId, never warns.
|
|
149
143
|
const disciplineId = fnId ?? `key-fn:${fnv1aHash(fn.toString())}`;
|
|
150
144
|
|
|
151
|
-
// Per-call timeoutMs gets a dedicated singleflight instance. Otherwise
|
|
152
|
-
// resolve defaultSingleflight per invocation (not captured at creation
|
|
153
|
-
// time) so wrappers created before boot pick up the timeout once
|
|
154
|
-
// setDefaultSingleflightTimeout is called (TIM-1032, same rationale as
|
|
155
|
-
// getCacheHandler for TIM-1029).
|
|
156
|
-
const perCallSf =
|
|
157
|
-
opts.timeoutMs !== undefined ? createSingleflight({ timeoutMs: opts.timeoutMs }) : undefined;
|
|
158
|
-
|
|
159
145
|
// Cast to Fn to preserve the original function's generic call signature.
|
|
160
146
|
// Without this, generic type parameters (e.g. <T> in apiFetch<T>) are
|
|
161
147
|
// erased and callers lose type safety on the return type.
|
|
162
148
|
return (async (...args: Parameters<Fn>): Promise<Awaited<ReturnType<Fn>>> => {
|
|
163
|
-
|
|
149
|
+
// Resolve the default per invocation (not captured at creation time)
|
|
150
|
+
// so wrappers created before boot pick up the timeout once
|
|
151
|
+
// setDefaultSingleflightTimeout is called (TIM-1032, same rationale as
|
|
152
|
+
// getCacheHandler for TIM-1029).
|
|
153
|
+
const timeoutMs = opts.timeoutMs ?? defaultTimeoutMs;
|
|
164
154
|
const key = opts.key ? opts.key(...args) : defaultKeyGenerator(fnId as string, args);
|
|
165
155
|
|
|
166
156
|
// The key the handler sees: in dev, scoped to the source generation.
|
|
@@ -187,6 +177,9 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
187
177
|
// NUL separator: cannot collide with user-provided key strings. The
|
|
188
178
|
// store key, not the logical key: in dev it carries the source
|
|
189
179
|
// generation, so a caller after a save never joins a pre-save flight.
|
|
180
|
+
// One flight keyspace for the SWR refetch and the miss: a caller that
|
|
181
|
+
// misses while a refetch is running joins it rather than racing a
|
|
182
|
+
// second execution whose write could land under the first (TIM-1447).
|
|
190
183
|
const tags = resolveTags(opts, args);
|
|
191
184
|
const flightKey = `${storeKey}\u0000${lastInvalidationEpochFor(key, tags)}`;
|
|
192
185
|
|
|
@@ -196,13 +189,16 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
196
189
|
* - the key/tags were invalidated after fn started (TIM-1028), or
|
|
197
190
|
* - the singleflight timed out (signal aborted) — the timed-out
|
|
198
191
|
* flight's write could overwrite a newer value from a subsequent
|
|
199
|
-
* flight (TIM-1092)
|
|
200
|
-
*
|
|
201
|
-
*
|
|
192
|
+
* flight (TIM-1092).
|
|
193
|
+
* Those two guards plus the shared flight keyspace leave no second
|
|
194
|
+
* in-process execution for the key to race, as long as every wrapper
|
|
195
|
+
* using the key agrees on its tags (design/06 §Residual write races). A set issued just before
|
|
196
|
+
* a timeout can still land after the next flight's set; that, and
|
|
197
|
+
* writes from other processes, are last-write-wins and self-heal on
|
|
198
|
+
* the next miss (design/06 §Residual write races).
|
|
202
199
|
*/
|
|
203
200
|
const executeAndStore = async (signal: AbortSignal): Promise<Awaited<ReturnType<Fn>>> => {
|
|
204
201
|
const startEpoch = currentInvalidationEpoch();
|
|
205
|
-
const generation = nextGeneration(key);
|
|
206
202
|
// Observed on every execution — the miss path and the SWR refetch,
|
|
207
203
|
// which runs in the triggering request's context. Never on a hit:
|
|
208
204
|
// a hit runs no fn, so it reads nothing.
|
|
@@ -216,13 +212,10 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
216
212
|
// Strict key discipline rejected this fn, so any entry already
|
|
217
213
|
// under the key was computed by the same request-reading fn (stored
|
|
218
214
|
// before strict mode was on). Drop it rather than serve it to
|
|
219
|
-
// everyone as stale —
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
!signal.aborted &&
|
|
224
|
-
writeGenerations.get(key) === generation
|
|
225
|
-
) {
|
|
215
|
+
// everyone as stale — unless the flight timed out: a newer flight
|
|
216
|
+
// may already have replaced the entry. (A delete is never wrong,
|
|
217
|
+
// only a miss; this just avoids a needless one.)
|
|
218
|
+
if (err instanceof KeyDisciplineViolation && !signal.aborted) {
|
|
226
219
|
await getHandler()
|
|
227
220
|
.invalidate({ key: storeKey })
|
|
228
221
|
.catch((e: unknown) => swallow(e, `cache invalidate failed for key "${key}"`));
|
|
@@ -231,7 +224,7 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
231
224
|
}
|
|
232
225
|
if (!signal.aborted && !wasInvalidatedSince(startEpoch, key, tags)) {
|
|
233
226
|
try {
|
|
234
|
-
await getHandler().set(storeKey, result, { ttl: opts.ttl, tags
|
|
227
|
+
await getHandler().set(storeKey, result, { ttl: opts.ttl, tags });
|
|
235
228
|
} catch (err) {
|
|
236
229
|
// Cache-write failure must not fail the request (TIM-1046).
|
|
237
230
|
// JSON-serializing handlers (Redis, KV) throw on BigInt; network
|
|
@@ -250,20 +243,30 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
250
243
|
duration_ms: Math.round(performance.now() - cacheStart),
|
|
251
244
|
stale: true,
|
|
252
245
|
});
|
|
253
|
-
// Serve stale immediately, trigger background refetch
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
246
|
+
// Serve stale immediately, trigger background refetch. The flight
|
|
247
|
+
// settles with fn's own outcome, so a miss that joins it gets the
|
|
248
|
+
// value or the error; only this background handle swallows it.
|
|
249
|
+
const refetch = flights
|
|
250
|
+
.do(
|
|
251
|
+
flightKey,
|
|
252
|
+
(signal) =>
|
|
253
|
+
executeAndStore(signal).catch((err: unknown) => {
|
|
254
|
+
// Failed refetch — stale entry continues to be served (unless
|
|
255
|
+
// executeAndStore dropped it for a key-discipline violation).
|
|
256
|
+
// Logged inside the flight so a rejection that arrives after
|
|
257
|
+
// the singleflight timeout is still reported.
|
|
258
|
+
logSwrRefetchFailed({ cacheKey: key, error: err });
|
|
259
|
+
throw err;
|
|
260
|
+
}),
|
|
261
|
+
timeoutMs
|
|
262
|
+
)
|
|
263
|
+
.then(
|
|
264
|
+
() => {},
|
|
265
|
+
() => {
|
|
266
|
+
// Logged above; the timeout rejection itself stays silent, as
|
|
267
|
+
// the stale entry continues to be served.
|
|
262
268
|
}
|
|
263
|
-
|
|
264
|
-
.catch(() => {
|
|
265
|
-
// Singleflight promise rejection handled — stale continues.
|
|
266
|
-
});
|
|
269
|
+
);
|
|
267
270
|
// Platforms that cancel work when the handler returns (Cloudflare
|
|
268
271
|
// Workers, Lambda) would otherwise kill the refetch mid-flight —
|
|
269
272
|
// stale data re-served forever. Register the (never-rejecting)
|
|
@@ -277,7 +280,7 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
277
280
|
// Cache miss (or stale without SWR) — execute with singleflight.
|
|
278
281
|
// The handler.set lives inside the coalesced callback, so N concurrent
|
|
279
282
|
// misses produce exactly one write (TIM-1028).
|
|
280
|
-
const result = await
|
|
283
|
+
const result = await flights.do(flightKey, executeAndStore, timeoutMs);
|
|
281
284
|
|
|
282
285
|
// Record cache miss as OTEL span event (fire-and-forget).
|
|
283
286
|
addSpanEventSync('timber.cache.miss', {
|
package/src/cli-context.ts
CHANGED
|
@@ -33,6 +33,15 @@ export interface PluginWithApi {
|
|
|
33
33
|
api?: unknown;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Whether a resolved Vite plugin list includes timber. Vite resolves a
|
|
38
|
+
* missing config file to an empty one rather than failing, so a caller that
|
|
39
|
+
* needs timber must ask — `timber dev` would otherwise serve plain Vite.
|
|
40
|
+
*/
|
|
41
|
+
export function hasTimberPlugin(plugins: readonly { name: string }[]): boolean {
|
|
42
|
+
return plugins.some((plugin) => plugin.name === TIMBER_ROOT_SYNC_PLUGIN);
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
/**
|
|
37
46
|
* Vite's own `resolveConfig`, narrowed to what this module passes and reads.
|
|
38
47
|
*
|
package/src/cli.ts
CHANGED
|
@@ -177,6 +177,22 @@ export async function runDev(options: CommandOptions, _deps?: ViteDeps): Promise
|
|
|
177
177
|
const server = await createServer({
|
|
178
178
|
configFile: options.config,
|
|
179
179
|
});
|
|
180
|
+
// The supervisor respawns this worker whenever a config file changes,
|
|
181
|
+
// including when a git checkout removes it. Vite treats a missing config
|
|
182
|
+
// as an empty one, so without this check the respawned worker would serve
|
|
183
|
+
// plain Vite on its default port: no app, and full-page reloads for every
|
|
184
|
+
// .html file it sees, the build output included.
|
|
185
|
+
const { hasTimberPlugin } = await import('./cli-context.ts');
|
|
186
|
+
if (!hasTimberPlugin(server.config.plugins)) {
|
|
187
|
+
await server.close();
|
|
188
|
+
const where = server.config.configFile ?? `no Vite config found in ${server.config.root}`;
|
|
189
|
+
throw new Error(
|
|
190
|
+
`[timber] The Vite config does not use the timber plugin (${where}).\n\n` +
|
|
191
|
+
` \`timber dev\` stopped instead of starting plain Vite. This happens when a\n` +
|
|
192
|
+
` config file changes on disk, for example a git checkout to a branch\n` +
|
|
193
|
+
` without timber. Run \`timber dev\` again once vite.config.ts lists timber().`
|
|
194
|
+
);
|
|
195
|
+
}
|
|
180
196
|
await server.listen();
|
|
181
197
|
server.printUrls();
|
|
182
198
|
return;
|