@timber-js/app 0.2.0-alpha.220 → 0.2.0-alpha.222
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-BwkmAYXq.js → actions-vBHr2vqd.js} +3 -3
- package/dist/_chunks/{actions-BwkmAYXq.js.map → actions-vBHr2vqd.js.map} +1 -1
- package/dist/_chunks/{cache-api-LA3sBpUS.js → cache-api-DdcDLpBj.js} +72 -145
- package/dist/_chunks/cache-api-DdcDLpBj.js.map +1 -0
- package/dist/_chunks/chains-B8TCLved.js +1 -0
- package/dist/_chunks/{chains-e_Buf9vg.js → chains-BchW_AtW.js} +2 -2
- package/dist/_chunks/{chains-e_Buf9vg.js.map → chains-BchW_AtW.js.map} +1 -1
- package/dist/_chunks/{classify-2Yp3xJY1.js → classify-IqzMpxMs.js} +2 -2
- package/dist/_chunks/{classify-2Yp3xJY1.js.map → classify-IqzMpxMs.js.map} +1 -1
- package/dist/_chunks/{cli-check-DDwCkeDY.js → cli-check-DQne_YhU.js} +3 -3
- package/dist/_chunks/{cli-check-DDwCkeDY.js.map → cli-check-DQne_YhU.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-BdIebmk3.js → cli-schema-sync-BS-RFGE2.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-BdIebmk3.js.map → cli-schema-sync-BS-RFGE2.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CLNfXQDK.js → cli-schema-sync-v872sHms.js} +1 -1
- package/dist/_chunks/{client-dep-entries-BOkpKjj1.js → client-dep-entries-BJyP9SIu.js} +2 -2
- package/dist/_chunks/{client-dep-entries-BOkpKjj1.js.map → client-dep-entries-BJyP9SIu.js.map} +1 -1
- package/dist/_chunks/{convention-lint-ByKJ6aqD.js → convention-lint-VwzrtjIt.js} +3 -3
- package/dist/_chunks/{convention-lint-ByKJ6aqD.js.map → convention-lint-VwzrtjIt.js.map} +1 -1
- package/dist/_chunks/{dev-server-DnODXuNM.js → dev-server-BNr5drEO.js} +57 -8
- package/dist/_chunks/dev-server-BNr5drEO.js.map +1 -0
- package/dist/_chunks/dev-server-CUg7Mqh_.js +1 -0
- package/dist/_chunks/dev-store-BOa304m_.js +283 -0
- package/dist/_chunks/dev-store-BOa304m_.js.map +1 -0
- package/dist/_chunks/{error-boundary-xxxLtXt6.js → error-boundary-Bc8QPZuq.js} +71 -21
- package/dist/_chunks/error-boundary-Bc8QPZuq.js.map +1 -0
- package/dist/_chunks/{flight-source-node-0dE-t3kq.js → flight-source-node-BdHUOUqg.js} +6 -7
- package/dist/_chunks/flight-source-node-BdHUOUqg.js.map +1 -0
- package/dist/_chunks/global-context-B9PFncvb.js +48 -0
- package/dist/_chunks/global-context-B9PFncvb.js.map +1 -0
- package/dist/_chunks/{json-lossy-check-C8zBY2uZ.js → json-lossy-check-C3Sht92C.js} +2 -2
- package/dist/_chunks/{json-lossy-check-C8zBY2uZ.js.map → json-lossy-check-C3Sht92C.js.map} +1 -1
- package/dist/_chunks/{live-graph-tSWrv8eH.js → live-graph-DEu_GWbc.js} +4 -4
- package/dist/_chunks/{live-graph-tSWrv8eH.js.map → live-graph-DEu_GWbc.js.map} +1 -1
- package/dist/_chunks/{logger-CbLdcy-W.js → logger-CI_hThfy.js} +10 -2
- package/dist/_chunks/{logger-CbLdcy-W.js.map → logger-CI_hThfy.js.map} +1 -1
- package/dist/_chunks/{node-response-Dibufw_b.js → node-response-bF0bKoig.js} +49 -3
- package/dist/_chunks/node-response-bF0bKoig.js.map +1 -0
- package/dist/_chunks/{poison-scan-C4FgMxFl.js → poison-scan-DTWIfNgD.js} +2 -2
- package/dist/_chunks/{poison-scan-C4FgMxFl.js.map → poison-scan-DTWIfNgD.js.map} +1 -1
- package/dist/_chunks/{purge-store-Byr8XOjU.js → purge-store-WZaxu-3m.js} +2 -2
- package/dist/_chunks/purge-store-WZaxu-3m.js.map +1 -0
- package/dist/_chunks/{render-timeout-DOf_BBcO.js → render-timeout-Ln_u7fX-.js} +19 -11
- package/dist/_chunks/render-timeout-Ln_u7fX-.js.map +1 -0
- package/dist/_chunks/{resolve-schema-CBR6Lm4i.js → resolve-schema-CkAInout.js} +2 -2
- package/dist/_chunks/{resolve-schema-CBR6Lm4i.js.map → resolve-schema-CkAInout.js.map} +1 -1
- package/dist/_chunks/{scanner-Cb3fSjAC.js → scanner-C8fdKvKG.js} +2 -2
- package/dist/_chunks/{scanner-Cb3fSjAC.js.map → scanner-C8fdKvKG.js.map} +1 -1
- package/dist/_chunks/{schema-bridge-C83xa9lT.js → schema-bridge-DpOmvZlI.js} +60 -23
- package/dist/_chunks/schema-bridge-DpOmvZlI.js.map +1 -0
- package/dist/_chunks/{segment-context-xtPUGfdq.js → segment-context-D3DNxKFq.js} +4 -8
- package/dist/_chunks/segment-context-D3DNxKFq.js.map +1 -0
- package/dist/_chunks/{sizeof-QPE5nd3u.js → sizeof-CO3dk0V1.js} +2 -2
- package/dist/_chunks/{sizeof-QPE5nd3u.js.map → sizeof-CO3dk0V1.js.map} +1 -1
- package/dist/_chunks/{walkers-qu8TpiLh.js → walkers-BqzxnwGC.js} +3 -3
- package/dist/_chunks/{walkers-qu8TpiLh.js.map → walkers-BqzxnwGC.js.map} +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cache/cache-api.d.ts.map +1 -1
- package/dist/cache/guarded-read.d.ts +29 -0
- package/dist/cache/guarded-read.d.ts.map +1 -0
- package/dist/cache/handler-store.d.ts +13 -1
- package/dist/cache/handler-store.d.ts.map +1 -1
- package/dist/cache/index.js +3 -2
- package/dist/cache/invalidation-epoch.d.ts +7 -0
- package/dist/cache/invalidation-epoch.d.ts.map +1 -1
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cache/timber-cache.d.ts.map +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/purge-store.d.ts +10 -1
- package/dist/cdn/purge-store.d.ts.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/browser-entry/router-init.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/global-context.d.ts +21 -1
- package/dist/client/global-context.d.ts.map +1 -1
- package/dist/client/index.js +9 -27
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.js +38 -65
- package/dist/client/internal.js.map +1 -1
- package/dist/client/link.d.ts.map +1 -1
- package/dist/client/navigation-context.d.ts.map +1 -1
- package/dist/client/navigation-transition.d.ts +68 -14
- package/dist/client/navigation-transition.d.ts.map +1 -1
- package/dist/client/params-context.d.ts.map +1 -1
- package/dist/client/router-effects.d.ts +35 -31
- package/dist/client/router-effects.d.ts.map +1 -1
- package/dist/client/router-pipeline.d.ts +2 -6
- package/dist/client/router-pipeline.d.ts.map +1 -1
- package/dist/client/router-types.d.ts +10 -30
- package/dist/client/router-types.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/client/slot-context.d.ts +2 -2
- package/dist/client/slot-context.d.ts.map +1 -1
- package/dist/codec.js +1 -1
- package/dist/cookies/index.js +1 -1
- package/dist/dev-tools/logs.d.ts +2 -2
- package/dist/dev-tools/logs.d.ts.map +1 -1
- package/dist/index.js +149 -56
- package/dist/index.js.map +1 -1
- package/dist/params/index.js +1 -1
- package/dist/plugins/dev-server.d.ts +1 -1
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/plugins/dev-store-clear.d.ts +28 -0
- package/dist/plugins/dev-store-clear.d.ts.map +1 -0
- package/dist/plugins/entries.d.ts +5 -0
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/plugins/orphaned-modules.d.ts +57 -0
- package/dist/plugins/orphaned-modules.d.ts.map +1 -0
- package/dist/plugins/prebuilt.d.ts +6 -6
- package/dist/plugins/prerender-sugar.d.ts.map +1 -1
- package/dist/plugins/routing.d.ts +1 -1
- package/dist/plugins/routing.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/rsc-runtime/dev-reference-cache.d.ts +47 -0
- package/dist/rsc-runtime/dev-reference-cache.d.ts.map +1 -0
- package/dist/rsc-runtime/rsc.d.ts +0 -15
- package/dist/rsc-runtime/rsc.d.ts.map +1 -1
- package/dist/rsc-runtime/ssr.d.ts +0 -11
- package/dist/rsc-runtime/ssr.d.ts.map +1 -1
- package/dist/schema-bridge.d.ts +28 -19
- package/dist/schema-bridge.d.ts.map +1 -1
- package/dist/search-params/define.d.ts +1 -1
- package/dist/search-params/define.d.ts.map +1 -1
- package/dist/search-params/index.js +7 -8
- package/dist/search-params/index.js.map +1 -1
- package/dist/search-params/wrappers.d.ts +3 -3
- package/dist/server/abort-scope.d.ts +27 -0
- package/dist/server/abort-scope.d.ts.map +1 -0
- package/dist/server/flight-source-node.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/instrumentation.d.ts +2 -1
- package/dist/server/instrumentation.d.ts.map +1 -1
- package/dist/server/internal.d.ts +1 -1
- package/dist/server/internal.d.ts.map +1 -1
- package/dist/server/internal.js +350 -151
- package/dist/server/internal.js.map +1 -1
- package/dist/server/logger.d.ts +9 -0
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/pipeline-helpers.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts +10 -7
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/prebuilt/cache-key.d.ts +26 -0
- package/dist/server/prebuilt/cache-key.d.ts.map +1 -1
- package/dist/server/prebuilt/capture-render.d.ts +9 -4
- package/dist/server/prebuilt/capture-render.d.ts.map +1 -1
- package/dist/server/prebuilt/capture-routes.d.ts +1 -1
- package/dist/server/prebuilt/dev-store.d.ts +103 -0
- package/dist/server/prebuilt/dev-store.d.ts.map +1 -0
- package/dist/server/prebuilt/overlay.d.ts +14 -3
- package/dist/server/prebuilt/overlay.d.ts.map +1 -1
- package/dist/server/prebuilt/payload-source.d.ts +8 -0
- package/dist/server/prebuilt/payload-source.d.ts.map +1 -1
- package/dist/server/prebuilt/slots.d.ts +5 -6
- package/dist/server/prebuilt/slots.d.ts.map +1 -1
- package/dist/server/prebuilt-builder.d.ts.map +1 -1
- package/dist/server/prebuilt-runtime.d.ts +5 -10
- package/dist/server/prebuilt-runtime.d.ts.map +1 -1
- package/dist/server/render-timeout.d.ts.map +1 -1
- package/dist/server/rsc-entry/action-dispatcher.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/ssr-render.d.ts.map +1 -1
- package/docs/api/32-api-cache.mdx +2 -0
- package/docs/api/33-api-search-params.mdx +3 -1
- package/docs/learn/06-typed-params.mdx +2 -2
- package/docs/learn/10-caching.mdx +12 -0
- package/docs/learn/11-middleware.mdx +2 -0
- package/package.json +1 -1
- package/src/cache/cache-api.ts +7 -1
- package/src/cache/guarded-read.ts +44 -0
- package/src/cache/handler-store.ts +38 -1
- package/src/cache/invalidation-epoch.ts +18 -6
- package/src/cache/timber-cache.ts +9 -3
- package/src/cdn/purge-store.ts +29 -1
- package/src/client/browser-entry/action-dispatch.ts +5 -5
- package/src/client/browser-entry/router-init.ts +2 -4
- package/src/client/global-context.ts +42 -14
- package/src/client/link.tsx +14 -18
- package/src/client/navigation-context.ts +4 -11
- package/src/client/navigation-transition.ts +86 -33
- package/src/client/params-context.ts +5 -17
- package/src/client/router-effects.ts +70 -45
- package/src/client/router-lifecycle.ts +1 -1
- package/src/client/router-pipeline.ts +52 -65
- package/src/client/router-types.ts +11 -31
- package/src/client/router.ts +98 -104
- package/src/client/segment-update-context.ts +1 -1
- package/src/client/slot-content-cache-context.ts +1 -1
- package/src/client/slot-context.ts +6 -17
- package/src/dev-tools/logs.ts +76 -50
- package/src/plugins/dev-server.ts +58 -9
- package/src/plugins/dev-store-clear.ts +47 -0
- package/src/plugins/entries.ts +6 -0
- package/src/plugins/orphaned-modules.ts +78 -0
- package/src/plugins/prebuilt.ts +17 -17
- package/src/plugins/prerender-sugar.ts +38 -6
- package/src/plugins/routing.ts +23 -1
- package/src/rsc-runtime/dev-reference-cache.ts +115 -0
- package/src/rsc-runtime/rsc.ts +10 -0
- package/src/rsc-runtime/ssr.ts +10 -0
- package/src/rsc-runtime/vendor-types.d.ts +8 -0
- package/src/schema-bridge.ts +93 -38
- package/src/search-params/define.ts +5 -6
- package/src/search-params/wrappers.ts +3 -3
- package/src/server/abort-scope.ts +49 -0
- package/src/server/action-handler.ts +18 -2
- package/src/server/flight-source-node.ts +5 -4
- package/src/server/instrumentation.ts +32 -8
- package/src/server/internal.ts +1 -6
- package/src/server/logger.ts +9 -0
- package/src/server/pipeline-helpers.ts +5 -3
- package/src/server/pipeline.ts +31 -20
- package/src/server/prebuilt/cache-key.ts +41 -0
- package/src/server/prebuilt/capture-render.ts +10 -6
- package/src/server/prebuilt/capture-routes.ts +1 -1
- package/src/server/prebuilt/dev-store.ts +173 -0
- package/src/server/prebuilt/overlay.ts +21 -5
- package/src/server/prebuilt/payload-source.ts +19 -0
- package/src/server/prebuilt/slots.ts +5 -6
- package/src/server/prebuilt-builder.ts +3 -2
- package/src/server/prebuilt-runtime.ts +194 -177
- package/src/server/render-timeout.ts +12 -17
- package/src/server/rsc-entry/action-dispatcher.ts +3 -1
- package/src/server/rsc-entry/index.ts +47 -13
- package/src/server/ssr-render.ts +9 -11
- package/dist/_chunks/cache-api-LA3sBpUS.js.map +0 -1
- package/dist/_chunks/chains-CDK1AWZQ.js +0 -1
- package/dist/_chunks/dev-server-DkytOEG2.js +0 -1
- package/dist/_chunks/dev-server-DnODXuNM.js.map +0 -1
- package/dist/_chunks/error-boundary-xxxLtXt6.js.map +0 -1
- package/dist/_chunks/flight-source-node-0dE-t3kq.js.map +0 -1
- package/dist/_chunks/node-response-Dibufw_b.js.map +0 -1
- package/dist/_chunks/purge-store-Byr8XOjU.js.map +0 -1
- package/dist/_chunks/render-timeout-DOf_BBcO.js.map +0 -1
- package/dist/_chunks/schema-bridge-C83xa9lT.js.map +0 -1
- package/dist/_chunks/segment-context-xtPUGfdq.js.map +0 -1
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
* cache.component (TIM-1140).
|
|
5
5
|
*
|
|
6
6
|
* `cache.component(fn, opts)` call sites are rewritten at build time to
|
|
7
|
-
* `__prebuilt(stableId, fn, opts)
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* `__prebuilt(stableId, fn, opts)`, in dev and production alike. It is
|
|
8
|
+
* exported via #server-internal — framework plumbing, never called by user
|
|
9
|
+
* code directly. In dev the build artifact is replaced by the in-memory dev
|
|
10
|
+
* store (prebuilt/dev-store.ts): a prerender entry is captured on its first
|
|
11
|
+
* request and served until a watched file changes (TIM-1588).
|
|
10
12
|
*
|
|
11
13
|
* Cache hits are served by FLIGHT REVIVAL: the cached `.flight` payload is
|
|
12
14
|
* decoded back into React elements inside the RSC environment with
|
|
@@ -37,8 +39,7 @@ import { createElement } from 'react';
|
|
|
37
39
|
|
|
38
40
|
import { requestContextAls, type RequestContextStore } from './als-registry.ts';
|
|
39
41
|
import type { CoercedParams } from '../shared/param-value.ts';
|
|
40
|
-
import
|
|
41
|
-
import { computeComponentCacheKey, tryCanonicalize } from './prebuilt/cache-key.ts';
|
|
42
|
+
import { computeComponentCacheKey, resolveKeyParams } from './prebuilt/cache-key.ts';
|
|
42
43
|
import {
|
|
43
44
|
resolveSlotNames,
|
|
44
45
|
prepareSlotRender,
|
|
@@ -59,12 +60,24 @@ import {
|
|
|
59
60
|
import { hasRuntimeLifetime, resolveTags, warnNestingClamps } from './prebuilt/lifetime.ts';
|
|
60
61
|
import {
|
|
61
62
|
hasPrebuiltPayloadSource,
|
|
62
|
-
lookupPrebuiltPayload,
|
|
63
|
-
getManifestEntry,
|
|
64
63
|
isParamIndependent,
|
|
64
|
+
lookupArtifactSeed,
|
|
65
|
+
type Seed,
|
|
65
66
|
} from './prebuilt/payload-source.ts';
|
|
66
67
|
import { lookupOverlay, storeOverlayEntry, overlayKey } from './prebuilt/overlay.ts';
|
|
68
|
+
import {
|
|
69
|
+
clearDevPrebuiltStore,
|
|
70
|
+
discardDevEntry,
|
|
71
|
+
getDevSeed,
|
|
72
|
+
isDevPrebuiltCacheBypassed,
|
|
73
|
+
isDevPrebuiltStoreActive,
|
|
74
|
+
isHardReload,
|
|
75
|
+
setDevSeed,
|
|
76
|
+
} from './prebuilt/dev-store.ts';
|
|
77
|
+
import { renderEntry } from './prebuilt/capture-render.ts';
|
|
78
|
+
import { BuildTimeContextError } from './prebuilt/synthetic-store.ts';
|
|
67
79
|
import { getWaitUntil } from './waituntil-bridge.ts';
|
|
80
|
+
import { swallow } from './logger.ts';
|
|
68
81
|
import { runBackgroundFlight } from './pipeline-helpers.ts';
|
|
69
82
|
import { runOutsideReactCacheScope } from './react-cache-scope.ts';
|
|
70
83
|
import { collectFlightBytes, type RenderFlight } from './flight-source.ts';
|
|
@@ -162,66 +175,13 @@ export interface PrebuiltRegistration {
|
|
|
162
175
|
/**
|
|
163
176
|
* Server-side component registry, keyed by stable component ID. Populated at
|
|
164
177
|
* module load time by `__prebuilt` calls; consumed by the post-build capture
|
|
165
|
-
* pass (TIM-1119). Never serialized — component functions are not
|
|
178
|
+
* pass (TIM-1119). Not written in dev, where nothing walks it. Never serialized — component functions are not
|
|
166
179
|
* Flight-serializable.
|
|
167
180
|
*/
|
|
168
181
|
const registry = new Map<string, PrebuiltRegistration>();
|
|
169
182
|
|
|
170
|
-
/**
|
|
171
|
-
|
|
172
|
-
* render is unkeyable.
|
|
173
|
-
*
|
|
174
|
-
* A wrapper rendered inside a parallel slot reads params merged with that
|
|
175
|
-
* slot's overrides (`getSegmentParams`: `{...segmentParams, ...slotParams}`)
|
|
176
|
-
* — but the cache key hashes only the route-level params, and the wrapper
|
|
177
|
-
* cannot know which slot it renders under. The route params are usable
|
|
178
|
-
* only when every slot's merged view canonicalizes identically to them;
|
|
179
|
-
* otherwise two renders with the same key could see different effective
|
|
180
|
-
* inputs and a hit could serve the WRONG cached subtree — so the render
|
|
181
|
-
* goes live: slower, never wrong. (Build-time capture doesn't model slot
|
|
182
|
-
* params either, so a divergent request could never have a faithful
|
|
183
|
-
* entry. Codex review on PR #835; revisit with segment-path-scoped keys
|
|
184
|
-
* if slot-scoped prebuilt is ever needed.)
|
|
185
|
-
*
|
|
186
|
-
* Comparison happens through `tryCanonicalize` — the same single
|
|
187
|
-
* definition of value equality the cache key uses — so anything it
|
|
188
|
-
* cannot represent faithfully (bigint-coerced codec params, accessors,
|
|
189
|
-
* aliases, …) is unkeyable here too, and this guard can never throw.
|
|
190
|
-
*/
|
|
191
|
-
function resolveKeyParams(store: {
|
|
192
|
-
segmentParams?: CoercedParams;
|
|
193
|
-
slotParams?: SlotParamsRecord;
|
|
194
|
-
}): CoercedParams | null {
|
|
195
|
-
const main = store.segmentParams ?? {};
|
|
196
|
-
const slots = store.slotParams;
|
|
197
|
-
if (!slots || Object.keys(slots).length === 0) return main;
|
|
198
|
-
// Spread before canonicalizing: param records are framework-produced
|
|
199
|
-
// Object.create(null) objects (prototype-pollution defense) — normalize
|
|
200
|
-
// the records themselves, let nested values face the full allowlist.
|
|
201
|
-
const mainCanonical = tryCanonicalize({ ...main });
|
|
202
|
-
if (mainCanonical === null) return null;
|
|
203
|
-
for (const slotParams of Object.values(slots)) {
|
|
204
|
-
const merged = tryCanonicalize({ ...main, ...slotParams });
|
|
205
|
-
if (merged === null || merged !== mainCanonical) return null;
|
|
206
|
-
}
|
|
207
|
-
return main;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Mirror the production cache-key decision for a slot render, with no
|
|
212
|
-
* cache IO — used by the dev wrapper so slot substitution happens in dev
|
|
213
|
-
* exactly when production would serve the cache path rather than the
|
|
214
|
-
* live fallback (dev/prod parity, codex P2 on PR #890): requires an ALS
|
|
215
|
-
* store, keyable params (slot-param divergence unkeys), and keyable data
|
|
216
|
-
* props (after the children slot outlet strip).
|
|
217
|
-
*/
|
|
218
|
-
function isSlotRenderKeyable(dataProps: Record<string, unknown>): boolean {
|
|
219
|
-
const store = requestContextAls.getStore();
|
|
220
|
-
if (!store) return false;
|
|
221
|
-
const keyParams = resolveKeyParams(store);
|
|
222
|
-
if (keyParams === null) return false;
|
|
223
|
-
return computeComponentCacheKey(withoutChildrenOutlet(dataProps), keyParams) !== null;
|
|
224
|
-
}
|
|
183
|
+
/** Dev: IDs registered so far, to detect a module re-evaluating (no functions held). */
|
|
184
|
+
const devRegisteredIds = new Set<string>();
|
|
225
185
|
|
|
226
186
|
/** Wrap payload bytes as a single-chunk ReadableStream for the decoder. */
|
|
227
187
|
function bytesToStream(bytes: Uint8Array): ReadableStream<Uint8Array> {
|
|
@@ -244,15 +204,14 @@ function bytesToStream(bytes: Uint8Array): ReadableStream<Uint8Array> {
|
|
|
244
204
|
* Null on any miss — the caller renders live with the original props.
|
|
245
205
|
*/
|
|
246
206
|
async function tryReviveSlotShell(
|
|
247
|
-
|
|
248
|
-
options: PrebuiltComponentOptions,
|
|
207
|
+
registration: PrebuiltRegistration,
|
|
249
208
|
slots: readonly string[],
|
|
250
209
|
props: Record<string, unknown>
|
|
251
210
|
): Promise<{ element: unknown } | null> {
|
|
252
211
|
const render = prepareSlotRender(props, slots);
|
|
253
212
|
if (render === null) return null; // top-level props unkeyable → live render
|
|
254
213
|
const { shellProps, dataProps, slotValues } = render;
|
|
255
|
-
const revived = await tryRevivePayload(
|
|
214
|
+
const revived = await tryRevivePayload(registration, shellProps, dataProps);
|
|
256
215
|
if (revived === null) return null;
|
|
257
216
|
return { element: wrapInSlotsProvider(revived.element, slotValues) };
|
|
258
217
|
}
|
|
@@ -388,6 +347,10 @@ async function captureComponentPayload(
|
|
|
388
347
|
* warning follows the store: a capture that is discarded (aborted,
|
|
389
348
|
* invalidated mid-render, failed store) holds no clamped copy, and must
|
|
390
349
|
* not spend the pair's one warning.
|
|
350
|
+
*
|
|
351
|
+
* A failed store is swallowed, like a failed `cache.data` write (TIM-1046):
|
|
352
|
+
* the captured payload is valid and still answers the request. Thrown, it
|
|
353
|
+
* would discard the capture and render the component a second time.
|
|
391
354
|
*/
|
|
392
355
|
async function storeCapturedEntry(
|
|
393
356
|
id: string,
|
|
@@ -397,7 +360,12 @@ async function storeCapturedEntry(
|
|
|
397
360
|
tags: string[],
|
|
398
361
|
hasSeed: boolean
|
|
399
362
|
): Promise<void> {
|
|
400
|
-
|
|
363
|
+
try {
|
|
364
|
+
await storeOverlayEntry(id, cacheKey, captured.bytes, { ttl: options.ttl, tags, hasSeed });
|
|
365
|
+
} catch (err) {
|
|
366
|
+
swallow(err, `cache.component overlay store failed for "${id}"`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
401
369
|
warnNestingClamps({ id, options, tags }, captured.nested, warnedNestingPairs, (m) =>
|
|
402
370
|
console.warn(m)
|
|
403
371
|
);
|
|
@@ -521,21 +489,94 @@ function backgroundRerender(
|
|
|
521
489
|
}
|
|
522
490
|
}
|
|
523
491
|
|
|
492
|
+
/** Components already announced by the one-time dev log. */
|
|
493
|
+
const devLoggedIds = new Set<string>();
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Dev: the seed for a prerender entry — the stored capture, or a new one
|
|
497
|
+
* rendered exactly as the build would render it (synthetic store, isolated
|
|
498
|
+
* render, nested wrappers baked flat) and stored until the next source
|
|
499
|
+
* change (prebuilt/dev-store.ts).
|
|
500
|
+
*
|
|
501
|
+
* Throws the BuildTimeContextError when the component read request
|
|
502
|
+
* context: `pnpm build` would fail on it, so dev fails too. Null on any
|
|
503
|
+
* other capture failure — the live render that follows reproduces the
|
|
504
|
+
* error, deny(), or redirect() with its normal semantics.
|
|
505
|
+
*/
|
|
506
|
+
async function resolveDevSeed(
|
|
507
|
+
registration: PrebuiltRegistration,
|
|
508
|
+
props: Record<string, unknown>,
|
|
509
|
+
keyParams: CoercedParams,
|
|
510
|
+
cacheKey: string
|
|
511
|
+
): Promise<Seed | null> {
|
|
512
|
+
const { id, options } = registration;
|
|
513
|
+
const stored = getDevSeed(id, cacheKey);
|
|
514
|
+
if (stored) return { payload: stored.bytes, capturedAt: stored.capturedAt };
|
|
515
|
+
|
|
516
|
+
const tags = resolveTags(options, props);
|
|
517
|
+
const oKey = overlayKey(id, cacheKey);
|
|
518
|
+
// The epoch scopes the flight: a request after a source change (which
|
|
519
|
+
// invalidates everything) never joins a capture of the old code.
|
|
520
|
+
const sfKey = `prebuilt-dev:${id}:${cacheKey}\0${lastInvalidationEpochFor(oKey, tags)}`;
|
|
521
|
+
try {
|
|
522
|
+
return await componentSingleflight.do(sfKey, async (signal) => {
|
|
523
|
+
const startEpoch = currentInvalidationEpoch();
|
|
524
|
+
const capturedAt = Date.now();
|
|
525
|
+
const { renderFlight } = requireRscFunctions();
|
|
526
|
+
// Outside the request's React.cache scope, like every stored capture
|
|
527
|
+
// (TIM-1529).
|
|
528
|
+
const outcome = await runOutsideReactCacheScope(() =>
|
|
529
|
+
renderEntry(registration, props, keyParams, getCaptureTimeoutMs(), false, renderFlight)
|
|
530
|
+
);
|
|
531
|
+
if (outcome.failure instanceof BuildTimeContextError) throw outcome.failure;
|
|
532
|
+
if (outcome.bytes === null) return null;
|
|
533
|
+
// Smoke-revive before storing, as the build does: bytes that cannot
|
|
534
|
+
// be decoded would fail every later request until the next save.
|
|
535
|
+
if ((await revivePayload(id, outcome.bytes, 'not storing the dev capture')) === null) {
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
// A save (or revalidateTag) while this rendered: the bytes may come
|
|
539
|
+
// from the old code, so this request gets them but the store does not.
|
|
540
|
+
if (!signal.aborted && !wasInvalidatedSince(startEpoch, oKey, tags)) {
|
|
541
|
+
setDevSeed(id, cacheKey, { bytes: outcome.bytes, tags, capturedAt });
|
|
542
|
+
warnNestingClamps({ id, options, tags }, outcome.nested, warnedNestingPairs, (m) =>
|
|
543
|
+
console.warn(m)
|
|
544
|
+
);
|
|
545
|
+
if (!devLoggedIds.has(id)) {
|
|
546
|
+
devLoggedIds.add(id);
|
|
547
|
+
console.log(
|
|
548
|
+
`[timber] cache.component "${id}": prerendered in dev — served from memory until ` +
|
|
549
|
+
`a file changes. A hard reload (Cache-Control: no-cache) renders it again.`
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return { payload: outcome.bytes, capturedAt };
|
|
554
|
+
});
|
|
555
|
+
} catch (error) {
|
|
556
|
+
if (error instanceof BuildTimeContextError) throw error;
|
|
557
|
+
console.error(`[timber] cache.component dev capture failed for "${id}":`, error);
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
524
562
|
/**
|
|
525
|
-
* Try to serve this render from the prebuilt cache: overlay →
|
|
563
|
+
* Try to serve this render from the prebuilt cache: overlay → seed →
|
|
526
564
|
* live render. Handles ISR (SWR, tombstones, re-renders) per design/45.
|
|
527
565
|
*
|
|
528
566
|
* Null on any miss — the caller renders live.
|
|
529
567
|
*/
|
|
530
568
|
async function tryRevivePayload(
|
|
531
|
-
|
|
532
|
-
options: PrebuiltComponentOptions,
|
|
569
|
+
registration: PrebuiltRegistration,
|
|
533
570
|
props: Record<string, unknown>,
|
|
534
571
|
keyPropsOverride?: Record<string, unknown>
|
|
535
572
|
): Promise<{ element: unknown } | null> {
|
|
573
|
+
// The wrapper's own registration: re-renders run the component through
|
|
574
|
+
// the wrapper's closure, never a registry lookup.
|
|
575
|
+
const { id, options, component } = registration;
|
|
536
576
|
const hasSource = hasPrebuiltPayloadSource();
|
|
577
|
+
const devStore = isDevPrebuiltStoreActive();
|
|
537
578
|
const hasRuntime = hasRuntimeLifetime(options);
|
|
538
|
-
if (!hasSource && !hasRuntime) return null;
|
|
579
|
+
if (!hasSource && !devStore && !hasRuntime) return null;
|
|
539
580
|
|
|
540
581
|
const store = requestContextAls.getStore();
|
|
541
582
|
if (!store) return null;
|
|
@@ -570,25 +611,32 @@ async function tryRevivePayload(
|
|
|
570
611
|
? 'failing the render (fallbackOnMissingSegmentParams: false)'
|
|
571
612
|
: 'rendering dynamically';
|
|
572
613
|
|
|
573
|
-
|
|
574
|
-
|
|
614
|
+
// Dev only: a hard reload discards this entry first, so the lookups
|
|
615
|
+
// below miss and it renders again — a prerender entry under the
|
|
616
|
+
// synthetic store, exactly as on its first request (prebuilt/dev-store.ts
|
|
617
|
+
// `isHardReload`).
|
|
618
|
+
if (devStore && isHardReload(store.originalHeaders)) {
|
|
619
|
+
await discardDevEntry(id, cacheKey, overlayKey(id, cacheKey));
|
|
620
|
+
}
|
|
575
621
|
|
|
576
622
|
// ─── Step 1: Check overlay (CacheHandler) ─────────────────────────
|
|
623
|
+
let overlayUnreadable = false;
|
|
577
624
|
if (hasRuntime) {
|
|
578
625
|
const overlayResult = await lookupOverlay(id, cacheKey);
|
|
579
626
|
if (overlayResult) {
|
|
580
627
|
const overlayHasSeed = overlayResult.record?.s ?? false;
|
|
581
628
|
if (overlayResult.kind === 'tombstone') {
|
|
582
|
-
|
|
583
|
-
return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
584
|
-
}
|
|
585
|
-
return null;
|
|
629
|
+
return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
586
630
|
}
|
|
631
|
+
// Unreadable is decided after the seed lookup: the seed says whether
|
|
632
|
+
// this key was ever enumerated (a strict miss must still throw), but
|
|
633
|
+
// its bytes can't be served — the overlay may hold its tombstone.
|
|
634
|
+
overlayUnreadable = overlayResult.kind === 'unreadable';
|
|
587
635
|
if (overlayResult.kind === 'fresh' && overlayResult.payload) {
|
|
588
636
|
return await revivePayload(id, overlayResult.payload, outcome);
|
|
589
637
|
}
|
|
590
638
|
if (overlayResult.kind === 'stale' && overlayResult.payload) {
|
|
591
|
-
if (options.staleWhileRevalidate
|
|
639
|
+
if (options.staleWhileRevalidate) {
|
|
592
640
|
backgroundRerender(
|
|
593
641
|
id,
|
|
594
642
|
component,
|
|
@@ -600,72 +648,70 @@ async function tryRevivePayload(
|
|
|
600
648
|
);
|
|
601
649
|
return await revivePayload(id, overlayResult.payload, outcome);
|
|
602
650
|
}
|
|
603
|
-
|
|
604
|
-
|
|
651
|
+
return await inlineRerender(
|
|
652
|
+
id,
|
|
653
|
+
component,
|
|
654
|
+
props,
|
|
655
|
+
cacheKey,
|
|
656
|
+
options,
|
|
657
|
+
overlayHasSeed,
|
|
658
|
+
outcome
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// ─── Step 2: Check the seed (build artifact, or the dev store) ────
|
|
665
|
+
const seed = devStore
|
|
666
|
+
? options.prerender
|
|
667
|
+
? await resolveDevSeed(registration, props, keyParams, cacheKey)
|
|
668
|
+
: null
|
|
669
|
+
: hasSource
|
|
670
|
+
? await lookupArtifactSeed(id, cacheKey, options.ttl !== undefined)
|
|
671
|
+
: null;
|
|
672
|
+
if (seed !== null && overlayUnreadable) {
|
|
673
|
+
// Render, as for a tombstone (design/06 §Store failures).
|
|
674
|
+
return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
675
|
+
}
|
|
676
|
+
if (seed !== null) {
|
|
677
|
+
// Check seed freshness when the component has a TTL.
|
|
678
|
+
if (options.ttl !== undefined) {
|
|
679
|
+
const seedAge = (Date.now() - seed.capturedAt) / 1000;
|
|
680
|
+
if (seedAge > options.ttl) {
|
|
681
|
+
// Stale seed
|
|
682
|
+
if (options.staleWhileRevalidate) {
|
|
683
|
+
backgroundRerender(
|
|
605
684
|
id,
|
|
606
685
|
component,
|
|
607
686
|
props,
|
|
608
687
|
cacheKey,
|
|
609
688
|
options,
|
|
610
|
-
|
|
611
|
-
|
|
689
|
+
true,
|
|
690
|
+
snapshotRequestContext(store)
|
|
612
691
|
);
|
|
692
|
+
return await revivePayload(id, seed.payload, outcome);
|
|
613
693
|
}
|
|
614
|
-
return
|
|
694
|
+
return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
615
695
|
}
|
|
616
696
|
}
|
|
697
|
+
// Fresh seed (or no TTL — immutable until redeploy)
|
|
698
|
+
return await revivePayload(id, seed.payload, outcome);
|
|
617
699
|
}
|
|
618
700
|
|
|
619
|
-
//
|
|
620
|
-
if (hasSource) {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
const buildTs = entry?.buildTimestamp ?? 0;
|
|
627
|
-
const seedAge = (Date.now() - buildTs) / 1000;
|
|
628
|
-
if (seedAge > options.ttl) {
|
|
629
|
-
// Stale seed
|
|
630
|
-
if (options.staleWhileRevalidate && component) {
|
|
631
|
-
backgroundRerender(
|
|
632
|
-
id,
|
|
633
|
-
component,
|
|
634
|
-
props,
|
|
635
|
-
cacheKey,
|
|
636
|
-
options,
|
|
637
|
-
true,
|
|
638
|
-
snapshotRequestContext(store)
|
|
639
|
-
);
|
|
640
|
-
return await revivePayload(id, artifactPayload, outcome);
|
|
641
|
-
}
|
|
642
|
-
if (component) {
|
|
643
|
-
return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
644
|
-
}
|
|
645
|
-
// No component in registry — can't re-render; fall through to
|
|
646
|
-
// live render via the wrapper (design/45 step 3).
|
|
647
|
-
return null;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
// Fresh seed (or no TTL — immutable until redeploy)
|
|
651
|
-
return await revivePayload(id, artifactPayload, outcome);
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
// Manifest miss
|
|
655
|
-
if (options.prerender) {
|
|
656
|
-
console.warn(
|
|
657
|
-
`[timber] cache.component cache miss: "${id}" with params ${JSON.stringify(
|
|
658
|
-
store.segmentParams ?? {}
|
|
659
|
-
)} — ${outcome}`
|
|
660
|
-
);
|
|
661
|
-
}
|
|
701
|
+
// Manifest miss
|
|
702
|
+
if (hasSource && options.prerender) {
|
|
703
|
+
console.warn(
|
|
704
|
+
`[timber] cache.component cache miss: "${id}" with params ${JSON.stringify(
|
|
705
|
+
store.segmentParams ?? {}
|
|
706
|
+
)} — ${outcome}`
|
|
707
|
+
);
|
|
662
708
|
}
|
|
663
709
|
|
|
664
710
|
// ─── Step 3: Full miss with runtime lifetime — inline re-render ───
|
|
665
711
|
// Skip when fallbackOnMissingSegmentParams is false — that option means
|
|
666
712
|
// "only prebuilt content", so an unenumerated miss must throw (the
|
|
667
713
|
// wrapper handles the throw after we return null).
|
|
668
|
-
if (hasRuntime &&
|
|
714
|
+
if (hasRuntime && options.fallbackOnMissingSegmentParams !== false) {
|
|
669
715
|
return await inlineRerender(id, component, props, cacheKey, options, false, outcome);
|
|
670
716
|
}
|
|
671
717
|
|
|
@@ -707,7 +753,19 @@ export function __prebuilt<C extends ServerComponent>(
|
|
|
707
753
|
if (resolution.kind === 'disabled') {
|
|
708
754
|
options = { ...options, slots: undefined };
|
|
709
755
|
}
|
|
710
|
-
|
|
756
|
+
const registration: PrebuiltRegistration = { id, component, options };
|
|
757
|
+
if (isDevPrebuiltStoreActive()) {
|
|
758
|
+
// Dev: a second registration of an ID means its module re-evaluated,
|
|
759
|
+
// so some code in this subtree changed. Clear rather than trust that
|
|
760
|
+
// the watcher event already did (it may land after this request
|
|
761
|
+
// rendered). Dev keeps only the ID: nothing walks the registry there,
|
|
762
|
+
// and an edited call site gets a new ID, so holding registrations
|
|
763
|
+
// would pin every superseded component and its module for the session.
|
|
764
|
+
if (devRegisteredIds.has(id)) clearDevPrebuiltStore();
|
|
765
|
+
devRegisteredIds.add(id);
|
|
766
|
+
} else {
|
|
767
|
+
registry.set(id, registration);
|
|
768
|
+
}
|
|
711
769
|
|
|
712
770
|
const wrapper = async (props: Parameters<C>[0]) => {
|
|
713
771
|
// Report this render to the enclosing capture, if any — cycle
|
|
@@ -723,10 +781,16 @@ export function __prebuilt<C extends ServerComponent>(
|
|
|
723
781
|
// spuriously fail the outer entry (codex P2 on PR #836).
|
|
724
782
|
return createElement(component as RenderableComponent, props as Record<string, unknown>);
|
|
725
783
|
}
|
|
784
|
+
// Dev without HMR: nothing could invalidate a cached entry, so render
|
|
785
|
+
// live, as dev did before it cached (no fallbackOnMissingSegmentParams
|
|
786
|
+
// throw either: there is no build to have missed).
|
|
787
|
+
if (isDevPrebuiltCacheBypassed()) {
|
|
788
|
+
return createElement(component as RenderableComponent, props as Record<string, unknown>);
|
|
789
|
+
}
|
|
726
790
|
|
|
727
791
|
const revived = slots
|
|
728
|
-
? await tryReviveSlotShell(
|
|
729
|
-
: await tryRevivePayload(
|
|
792
|
+
? await tryReviveSlotShell(registration, slots, props as Record<string, unknown>)
|
|
793
|
+
: await tryRevivePayload(registration, props as Record<string, unknown>);
|
|
730
794
|
if (revived !== null) {
|
|
731
795
|
return revived.element;
|
|
732
796
|
}
|
|
@@ -761,50 +825,3 @@ export function getPrebuiltRegistration(id: string): PrebuiltRegistration | unde
|
|
|
761
825
|
export function getPrebuiltRegistry(): ReadonlyMap<string, PrebuiltRegistration> {
|
|
762
826
|
return registry;
|
|
763
827
|
}
|
|
764
|
-
|
|
765
|
-
/**
|
|
766
|
-
* Dev-mode wrapper injected by the timber-prebuilt transform: a no-op that
|
|
767
|
-
* renders the component dynamically on every request, logging once per
|
|
768
|
-
* component on first render so the production behavior difference is visible.
|
|
769
|
-
* See design/44 §Dev Mode.
|
|
770
|
-
*/
|
|
771
|
-
export function __prebuiltDev<C extends ServerComponent>(
|
|
772
|
-
name: string,
|
|
773
|
-
component: C,
|
|
774
|
-
options: PrebuiltComponentOptions = {}
|
|
775
|
-
): C {
|
|
776
|
-
// Dev/prod parity for slot components: in production a slot component
|
|
777
|
-
// ALWAYS receives a SlotOutlet element for each declared slot (never the
|
|
778
|
-
// live children), so a component that introspects a slot prop would
|
|
779
|
-
// behave differently between dev and prod if dev passed children
|
|
780
|
-
// through. Dev renders the same tree shape — outlets in the props,
|
|
781
|
-
// live values via SlotsProvider — just without any caching. The same
|
|
782
|
-
// validation applies (including the lifetime requirement): slots are
|
|
783
|
-
// active in dev exactly when they would be active in production.
|
|
784
|
-
const resolution = resolveSlotNames(name, options);
|
|
785
|
-
const slots = resolution.kind === 'active' ? resolution.slots : null;
|
|
786
|
-
let logged = false;
|
|
787
|
-
const wrapper = (props: Parameters<C>[0]) => {
|
|
788
|
-
if (!logged) {
|
|
789
|
-
logged = true;
|
|
790
|
-
console.log(`[timber] cache.component: "${name}" — rendering dynamically (dev mode)`);
|
|
791
|
-
}
|
|
792
|
-
if (slots) {
|
|
793
|
-
const render = prepareSlotRender(props as Record<string, unknown>, slots);
|
|
794
|
-
// Substitute outlets only when PRODUCTION would: top-level props
|
|
795
|
-
// splittable AND the data props keyable. Unkeyable inputs render
|
|
796
|
-
// live with the original props there, so dev must too (parity —
|
|
797
|
-
// codex P2 on PR #890).
|
|
798
|
-
if (render !== null && isSlotRenderKeyable(render.dataProps)) {
|
|
799
|
-
return wrapInSlotsProvider(
|
|
800
|
-
createElement(component as RenderableComponent, render.shellProps),
|
|
801
|
-
render.slotValues
|
|
802
|
-
);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
// Element, not a direct call — same dispatcher reasoning as the
|
|
806
|
-
// production wrapper's live fallback.
|
|
807
|
-
return createElement(component as RenderableComponent, props as Record<string, unknown>);
|
|
808
|
-
};
|
|
809
|
-
return wrapper as C;
|
|
810
|
-
}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* Design doc: 02-rendering-pipeline.md §"Streaming Constraints"
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import { onAbortUntil } from './abort-scope.ts';
|
|
12
|
+
|
|
11
13
|
/** `renderTimeoutMs` when timber.config.ts leaves it unset. */
|
|
12
14
|
export const DEFAULT_RENDER_TIMEOUT_MS = 30_000;
|
|
13
15
|
|
|
@@ -76,30 +78,23 @@ export function createRenderTimeout(timeoutMs: number, parentSignal?: AbortSigna
|
|
|
76
78
|
const reason = new RenderTimeoutError(timeoutMs, 'RSC stream read timed out');
|
|
77
79
|
|
|
78
80
|
const timer = setTimeout(() => controller.abort(reason), timeoutMs);
|
|
81
|
+
const scope = new AbortController();
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
// The parent listener lasts until cancel() (server/abort-scope.ts).
|
|
84
|
+
onAbortUntil(
|
|
85
|
+
parentSignal,
|
|
86
|
+
() => {
|
|
84
87
|
clearTimeout(timer);
|
|
85
|
-
controller.abort(parentSignal
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
controller.abort(parentSignal.reason);
|
|
90
|
-
};
|
|
91
|
-
parentSignal.addEventListener('abort', onParentAbort, { once: true });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
88
|
+
controller.abort(parentSignal?.reason);
|
|
89
|
+
},
|
|
90
|
+
scope.signal
|
|
91
|
+
);
|
|
94
92
|
|
|
95
93
|
return {
|
|
96
94
|
signal: controller.signal,
|
|
97
95
|
cancel: () => {
|
|
98
96
|
clearTimeout(timer);
|
|
99
|
-
|
|
100
|
-
parentSignal.removeEventListener('abort', onParentAbort);
|
|
101
|
-
onParentAbort = null;
|
|
102
|
-
}
|
|
97
|
+
scope.abort();
|
|
103
98
|
},
|
|
104
99
|
};
|
|
105
100
|
}
|
|
@@ -112,7 +112,9 @@ export function buildActionDispatcher(
|
|
|
112
112
|
// as a GET — the rerender with the action's form state, the throw with
|
|
113
113
|
// its error, which the route renders in place of its page so the
|
|
114
114
|
// nearest error page answers (SSR has no error boundaries, so that page
|
|
115
|
-
// comes from the shell-failure path)
|
|
115
|
+
// comes from the shell-failure path). `reenter` enters after proxy.ts,
|
|
116
|
+
// which already ran for this POST: the GET is the POST's answer, not a
|
|
117
|
+
// second request (TIM-1445). Middleware and access.ts run on it.
|
|
116
118
|
// - Same URL (so route matching lands on the same page)
|
|
117
119
|
// - Cookie header DROPPED entirely. The post-action RYW state is
|
|
118
120
|
// handed over as a parsed `Map<string, string>` and becomes the
|
|
@@ -58,6 +58,11 @@ import { renderFallbackError as renderFallback } from '../fallback-error.ts';
|
|
|
58
58
|
import { loadInstrumentation } from '../instrumentation.ts';
|
|
59
59
|
import { createDenyFallbackRenderer } from './deny-fallback.ts';
|
|
60
60
|
import { DenySignal } from '../primitives.ts';
|
|
61
|
+
import {
|
|
62
|
+
PREBUILT_DEV_CLEAR_EVENT,
|
|
63
|
+
clearDevPrebuiltStore,
|
|
64
|
+
setDevPrebuiltStoreMode,
|
|
65
|
+
} from '../prebuilt/dev-store.ts';
|
|
61
66
|
import { renderRoute } from './render-route.ts';
|
|
62
67
|
import { isDebug, isDevMode, setDebugFromConfig } from '../debug.ts';
|
|
63
68
|
import { capturePrebuiltPayloads } from '../prebuilt-builder.ts';
|
|
@@ -114,16 +119,21 @@ async function createRequestHandler(manifest: typeof routeManifest, runtimeConfi
|
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
// Wire the CDN purge handler so revalidateTag triggers CDN purge (TIM-1166).
|
|
117
|
-
|
|
122
|
+
// Applied on every entry run, absent included: in dev the store outlives
|
|
123
|
+
// an edit that removes the handler.
|
|
124
|
+
const { applyConfiguredCdnPurgeHandler } = await import('../../cdn/purge-store.ts');
|
|
125
|
+
const userCdnPurge = (await loadCdnPurgeHandler()) as
|
|
126
|
+
| Parameters<typeof applyConfiguredCdnPurgeHandler>[0]
|
|
127
|
+
| null;
|
|
118
128
|
if (userCdnPurge) {
|
|
119
|
-
|
|
120
|
-
setCdnPurgeHandler(userCdnPurge as Parameters<typeof setCdnPurgeHandler>[0]);
|
|
129
|
+
applyConfiguredCdnPurgeHandler(userCdnPurge);
|
|
121
130
|
} else if (typeof process !== 'undefined' && process.env?.TIMBER_RUNTIME === 'cloudflare') {
|
|
122
131
|
// Auto-wire Workers Cache purge on Cloudflare — no API token needed,
|
|
123
132
|
// available on all plans via ctx.cache.purge({ tags }) (TIM-1170).
|
|
124
133
|
const { WorkersCachePurge } = await import('../../cdn/workers-cache-purge.ts');
|
|
125
|
-
|
|
126
|
-
|
|
134
|
+
applyConfiguredCdnPurgeHandler(new WorkersCachePurge());
|
|
135
|
+
} else {
|
|
136
|
+
applyConfiguredCdnPurgeHandler(undefined);
|
|
127
137
|
}
|
|
128
138
|
|
|
129
139
|
// Wire the prebuilt payload source so cache.component wrappers can look
|
|
@@ -131,9 +141,20 @@ async function createRequestHandler(manifest: typeof routeManifest, runtimeConfi
|
|
|
131
141
|
// platform-aware: Node/Nitro reads from disk; Cloudflare reads from
|
|
132
142
|
// static assets via globalThis.__TIMBER_PREBUILT_SOURCE__ (set by the
|
|
133
143
|
// generated _worker.js before this module loads).
|
|
134
|
-
// In dev mode there are no prebuilt artifacts — source stays null and
|
|
135
|
-
//
|
|
136
|
-
|
|
144
|
+
// In dev mode there are no prebuilt artifacts — source stays null and the
|
|
145
|
+
// in-memory dev store stands in for them: prerender entries are captured
|
|
146
|
+
// on first request and cleared on every dev-server watcher event, which
|
|
147
|
+
// the timber-dev-server plugin forwards here (TIM-1588). Without HMR
|
|
148
|
+
// (`server.hmr: false`) no event would ever clear it, so dev bypasses
|
|
149
|
+
// cache.component caching entirely and every wrapper renders live.
|
|
150
|
+
if (isDevMode()) {
|
|
151
|
+
if (import.meta.hot) {
|
|
152
|
+
setDevPrebuiltStoreMode('active');
|
|
153
|
+
import.meta.hot.on(PREBUILT_DEV_CLEAR_EVENT, clearDevPrebuiltStore);
|
|
154
|
+
} else {
|
|
155
|
+
setDevPrebuiltStoreMode('bypass');
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
137
158
|
const platformSource = (globalThis as Record<string, unknown>).__TIMBER_PREBUILT_SOURCE__ as
|
|
138
159
|
| import('../prebuilt/payload-source.ts').PrebuiltPayloadSource
|
|
139
160
|
| undefined;
|
|
@@ -511,11 +532,12 @@ await loadInstrumentation(loadUserInstrumentation);
|
|
|
511
532
|
|
|
512
533
|
// Wire the cache handler — prebuilt components may call timber.cache
|
|
513
534
|
// during capture and must see the configured store, not the fallback.
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
535
|
+
// Applied on every entry run, absent included: in dev the store outlives an
|
|
536
|
+
// edit that removes the handler from timber.cache.ts.
|
|
537
|
+
const { applyConfiguredCacheHandler } = await import('../../cache/handler-store.ts');
|
|
538
|
+
applyConfiguredCacheHandler(
|
|
539
|
+
((await loadCacheHandler()) ?? null) as Parameters<typeof applyConfiguredCacheHandler>[0]
|
|
540
|
+
);
|
|
519
541
|
|
|
520
542
|
// In capture mode the plugin only calls __timber_capturePrebuilt — skip
|
|
521
543
|
// the remaining production startup (CDN purge, OTEL, route matchers)
|
|
@@ -529,3 +551,15 @@ if (!isCaptureMode) {
|
|
|
529
551
|
}
|
|
530
552
|
|
|
531
553
|
export default _handler!;
|
|
554
|
+
|
|
555
|
+
// A server-module edit propagates to this boundary, so the module runner
|
|
556
|
+
// re-executes only the edited module and its importers up to here (the dev
|
|
557
|
+
// middleware re-imports this entry per request). Without a boundary every
|
|
558
|
+
// edit is a full program reload: the runner re-evaluates everything,
|
|
559
|
+
// node_modules included, and React's dev Flight server leaks each discarded
|
|
560
|
+
// copy through the async hook and console patches it installs at module
|
|
561
|
+
// load — the dev server grew ~110 MB per edit until it ran out of heap.
|
|
562
|
+
// This is the boundary @vitejs/plugin-rsc documents for the RSC entry.
|
|
563
|
+
if (import.meta.hot) {
|
|
564
|
+
import.meta.hot.accept();
|
|
565
|
+
}
|