@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
package/dist/server/internal.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { r as
|
|
1
|
+
import { c as drainWithDeadline, d as onAbortUntil, i as withResponseInit, n as discardResponseBody, o as concatBytes, r as nodeBodyOps, u as wrapResponseWithStreamTiming } from "../_chunks/node-response-bF0bKoig.js";
|
|
2
|
+
import { r as RenderTimeoutError, t as DEFAULT_RENDER_TIMEOUT_MS } from "../_chunks/render-timeout-Ln_u7fX-.js";
|
|
2
3
|
import { n as isRscContentType, r as isRscRequest } from "../_chunks/rsc-media-type-DDc7duTD.js";
|
|
3
4
|
import { i as getMetadataRouteServePath, n as classifyMetadataRoute, r as getMetadataRouteAutoLink, t as METADATA_ROUTE_CONVENTIONS } from "../_chunks/metadata-routes-B3XJNyIH.js";
|
|
4
5
|
import { i as canonicalize, r as canonicalRequestPath } from "../_chunks/canonicalize-BAWkWiKK.js";
|
|
6
|
+
import { a as discardDevEntry, c as isDevPrebuiltCacheBypassed, d as setDevSeed, f as currentInvalidationEpoch, h as wasInvalidatedSince, l as isDevPrebuiltStoreActive, n as clearDevPrebuiltStore, o as getDevSeed, p as lastInvalidationEpochFor, u as isHardReload } from "../_chunks/dev-store-BOa304m_.js";
|
|
5
7
|
import { n as classifyUrlSegment, r as effectiveUrlSegment } from "../_chunks/segment-classify-C539Pa2O.js";
|
|
6
8
|
import { t as computeSegmentTreePaths } from "../_chunks/segment-keys-D5hu1hz4.js";
|
|
7
9
|
import { i as requestContextAls, n as prebuiltCaptureAls, o as timingAls, t as earlyHintsSenderAls } from "../_chunks/als-registry-BZqHCtq-.js";
|
|
8
|
-
import { C as
|
|
10
|
+
import { A as getOtelTraceId, C as isDenySignal, F as setSpanAttribute, I as withSpan, M as getTraceId, N as replaceTraceId, P as runWithTraceId, S as isControlFlowSignal, T as isDebug, _ as logWaitUntilUnsupported, c as logProxyError, d as logRequestReceived, f as logRouteError, g as logWaitUntilRejected, h as logSwrRefetchFailed, i as logCsrfRejected, k as generateTraceId, l as logRenderError, m as logSlowRequest, n as logCacheMiss, o as logMiddlewareError, p as logRouteSetupError, s as logMiddlewareShortCircuit, t as getLogger, u as logRequestCompleted, v as setLogger, w as isRedirectSignal, y as swallow } from "../_chunks/logger-CI_hThfy.js";
|
|
9
11
|
import { i as collectRouteModulepreloads, n as collectRouteCss, r as collectRouteFonts } from "../_chunks/build-manifest-DWppEdLB.js";
|
|
10
12
|
import { i as isRscCacheKeyShape, n as RSC_KEY_PARAM, r as appVisibleSearch, s as rscCacheKey, t as RSC_KEY_HEADERS } from "../_chunks/rsc-cache-key-ClUiXQnK.js";
|
|
11
|
-
import { C as setMutableCookieContext, S as setMatchedSegmentPath, T as runOutsideReactCacheScope, b as markResponseFlushed, f as getCookie, g as getHeader, h as applyRequestHeaderOverlay, i as coerce, m as getSetCookieHeaders, o as DenySignal, s as RedirectSignal, t as executeAction, v as getSearchParams, w as setSegmentParams, x as runWithRequestContext, y as getSegmentParams } from "../_chunks/actions-
|
|
12
|
-
import { a as
|
|
13
|
+
import { C as setMutableCookieContext, S as setMatchedSegmentPath, T as runOutsideReactCacheScope, b as markResponseFlushed, f as getCookie, g as getHeader, h as applyRequestHeaderOverlay, i as coerce, m as getSetCookieHeaders, o as DenySignal, s as RedirectSignal, t as executeAction, v as getSearchParams, w as setSegmentParams, x as runWithRequestContext, y as getSegmentParams } from "../_chunks/actions-vBHr2vqd.js";
|
|
14
|
+
import { a as hasPrebuiltPayloadSource, c as setPrebuiltPayloadSource, h as getWaitUntil, i as storeOverlayEntry, l as applyReloadHeaders, n as lookupOverlay, o as isParamIndependent, r as overlayKey, s as lookupArtifactSeed, u as checkVersionSkew } from "../_chunks/cache-api-DdcDLpBj.js";
|
|
13
15
|
import { n as createSingleflight } from "../_chunks/singleflight-BeVMMKi0.js";
|
|
14
|
-
import {
|
|
15
|
-
import { n as toBracketKey } from "../_chunks/resolve-schema-CBR6Lm4i.js";
|
|
16
|
+
import { n as toBracketKey } from "../_chunks/resolve-schema-CkAInout.js";
|
|
16
17
|
import { t as normalizeParamValue } from "../_chunks/param-value-C8TNYchQ.js";
|
|
17
18
|
import { l as TIMBER_ERROR_HEADER, t as StatusPageMarker } from "../_chunks/status-page-marker-BRX9Ib-d.js";
|
|
19
|
+
import { t as createGlobalContext } from "../_chunks/global-context-B9PFncvb.js";
|
|
18
20
|
import { createHash } from "node:crypto";
|
|
19
21
|
import { readFile } from "node:fs/promises";
|
|
20
|
-
import
|
|
22
|
+
import { createElement, useContext } from "react";
|
|
21
23
|
//#region src/server/render-utils.ts
|
|
22
24
|
/**
|
|
23
25
|
* Check if an error is an abort error (connection closed by client).
|
|
@@ -119,7 +121,17 @@ function getServerTimingHeader() {
|
|
|
119
121
|
*
|
|
120
122
|
* See design/17-logging.md §"instrumentation.ts — The Entry Point"
|
|
121
123
|
*/
|
|
122
|
-
|
|
124
|
+
/**
|
|
125
|
+
* The loader the current hooks came from. One app passes one loader
|
|
126
|
+
* (`virtual:timber-instrumentation`), so a second call with it is a no-op.
|
|
127
|
+
* In dev a new loader means instrumentation.ts changed: the RSC entry is an
|
|
128
|
+
* HMR boundary (design/21 §HMR Wiring), so editing instrumentation.ts
|
|
129
|
+
* re-executes the virtual loader module and the entry, while this module
|
|
130
|
+
* keeps its state. The new module then replaces the old one's hooks.
|
|
131
|
+
*/
|
|
132
|
+
var _loadedFrom = null;
|
|
133
|
+
/** The framework logger before any instrumentation module replaced it. */
|
|
134
|
+
var _loggerBeforeLoad = null;
|
|
123
135
|
var _onRequestError = null;
|
|
124
136
|
/**
|
|
125
137
|
* Load and initialize the user's instrumentation.ts module.
|
|
@@ -132,8 +144,13 @@ var _onRequestError = null;
|
|
|
132
144
|
* Returns null if no instrumentation.ts exists.
|
|
133
145
|
*/
|
|
134
146
|
async function loadInstrumentation(loader) {
|
|
135
|
-
if (
|
|
136
|
-
|
|
147
|
+
if (_loadedFrom === loader) return;
|
|
148
|
+
if (_loadedFrom === null) _loggerBeforeLoad = getLogger();
|
|
149
|
+
else {
|
|
150
|
+
_onRequestError = null;
|
|
151
|
+
setLogger(_loggerBeforeLoad);
|
|
152
|
+
}
|
|
153
|
+
_loadedFrom = loader;
|
|
137
154
|
let mod;
|
|
138
155
|
try {
|
|
139
156
|
mod = await loader();
|
|
@@ -148,6 +165,9 @@ async function loadInstrumentation(loader) {
|
|
|
148
165
|
await mod.register();
|
|
149
166
|
} catch (error) {
|
|
150
167
|
console.error("[timber] instrumentation.ts register() threw:", error);
|
|
168
|
+
_onRequestError = null;
|
|
169
|
+
if (_loggerBeforeLoad) setLogger(_loggerBeforeLoad);
|
|
170
|
+
_loadedFrom = null;
|
|
151
171
|
throw error;
|
|
152
172
|
}
|
|
153
173
|
}
|
|
@@ -745,14 +765,14 @@ async function runBackgroundFlight(signal, work, log) {
|
|
|
745
765
|
const request = requestContextAls.getStore()?.request;
|
|
746
766
|
if (request && isReportableError(error)) fireInBackground(callHook(error, request, "render"));
|
|
747
767
|
};
|
|
748
|
-
const
|
|
749
|
-
signal
|
|
768
|
+
const settled = new AbortController();
|
|
769
|
+
onAbortUntil(signal, () => failed(signal.reason), settled.signal);
|
|
750
770
|
try {
|
|
751
771
|
await work();
|
|
752
772
|
} catch (error) {
|
|
753
773
|
if (!signal.aborted) failed(error);
|
|
754
774
|
} finally {
|
|
755
|
-
|
|
775
|
+
settled.abort();
|
|
756
776
|
}
|
|
757
777
|
}
|
|
758
778
|
function reportedPhase(source, apiRoute) {
|
|
@@ -1916,7 +1936,7 @@ function createPipeline(config) {
|
|
|
1916
1936
|
const slowRequestMs = config.slowRequestMs ?? 3e3;
|
|
1917
1937
|
const serverTiming = config.serverTiming ?? "total";
|
|
1918
1938
|
let activeRequests = 0;
|
|
1919
|
-
|
|
1939
|
+
return async (req) => {
|
|
1920
1940
|
const url = new URL(req.url);
|
|
1921
1941
|
const method = req.method;
|
|
1922
1942
|
const path = url.pathname;
|
|
@@ -1962,7 +1982,8 @@ function createPipeline(config) {
|
|
|
1962
1982
|
const redirect = canonicalRedirect(req, canonicalPath, stripTrailingSlash, config.matchRoute);
|
|
1963
1983
|
if (redirect) return redirect;
|
|
1964
1984
|
if (config.dispatchAction) {
|
|
1965
|
-
const
|
|
1985
|
+
const reenter = (rerenderReq, reentry) => runWithRequestContext(rerenderReq, () => handleRequest(config, rerenderReq, rerenderReq.method, canonicalPath, true), reentry);
|
|
1986
|
+
const actionResult = await config.dispatchAction(canonicalReq, canonicalPath, reenter);
|
|
1966
1987
|
if (actionResult) return actionResult;
|
|
1967
1988
|
}
|
|
1968
1989
|
return handleRequest(config, canonicalReq, method, canonicalPath, true);
|
|
@@ -2025,14 +2046,9 @@ function createPipeline(config) {
|
|
|
2025
2046
|
};
|
|
2026
2047
|
return serverTiming === "detailed" ? runWithTimingCollector(runRequest) : runRequest();
|
|
2027
2048
|
};
|
|
2028
|
-
return runWithRequestContext(req, inRequestContext
|
|
2029
|
-
cookies: reentry?.cookies,
|
|
2030
|
-
formState: reentry?.formState,
|
|
2031
|
-
actionError: reentry?.actionError
|
|
2032
|
-
});
|
|
2049
|
+
return runWithRequestContext(req, inRequestContext);
|
|
2033
2050
|
});
|
|
2034
2051
|
};
|
|
2035
|
-
return pipelineFn;
|
|
2036
2052
|
}
|
|
2037
2053
|
//#endregion
|
|
2038
2054
|
//#region src/server/early-hints.ts
|
|
@@ -3706,6 +3722,42 @@ function computeComponentCacheKey(props, params) {
|
|
|
3706
3722
|
}
|
|
3707
3723
|
return createHash("sha256").update(canonical).digest("hex").slice(0, 16);
|
|
3708
3724
|
}
|
|
3725
|
+
/**
|
|
3726
|
+
* Resolve the params the cache key may faithfully hash, or null if this
|
|
3727
|
+
* render is unkeyable.
|
|
3728
|
+
*
|
|
3729
|
+
* A wrapper rendered inside a parallel slot reads params merged with that
|
|
3730
|
+
* slot's overrides (`getSegmentParams`: `{...segmentParams, ...slotParams}`)
|
|
3731
|
+
* — but the cache key hashes only the route-level params, and the wrapper
|
|
3732
|
+
* cannot know which slot it renders under. The route params are usable
|
|
3733
|
+
* only when every slot's merged view canonicalizes identically to them;
|
|
3734
|
+
* otherwise two renders with the same key could see different effective
|
|
3735
|
+
* inputs and a hit could serve the WRONG cached subtree — so the render
|
|
3736
|
+
* goes live: slower, never wrong. (Build-time capture doesn't model slot
|
|
3737
|
+
* params either, so a divergent request could never have a faithful
|
|
3738
|
+
* entry. Codex review on PR #835; revisit with segment-path-scoped keys
|
|
3739
|
+
* if slot-scoped prebuilt is ever needed.)
|
|
3740
|
+
*
|
|
3741
|
+
* Comparison happens through `tryCanonicalize` — the same single
|
|
3742
|
+
* definition of value equality the cache key uses — so anything it
|
|
3743
|
+
* cannot represent faithfully (bigint-coerced codec params, accessors,
|
|
3744
|
+
* aliases, …) is unkeyable here too, and this guard can never throw.
|
|
3745
|
+
*/
|
|
3746
|
+
function resolveKeyParams(store) {
|
|
3747
|
+
const main = store.segmentParams ?? {};
|
|
3748
|
+
const slots = store.slotParams;
|
|
3749
|
+
if (!slots || Object.keys(slots).length === 0) return main;
|
|
3750
|
+
const mainCanonical = tryCanonicalize({ ...main });
|
|
3751
|
+
if (mainCanonical === null) return null;
|
|
3752
|
+
for (const slotParams of Object.values(slots)) {
|
|
3753
|
+
const merged = tryCanonicalize({
|
|
3754
|
+
...main,
|
|
3755
|
+
...slotParams
|
|
3756
|
+
});
|
|
3757
|
+
if (merged === null || merged !== mainCanonical) return null;
|
|
3758
|
+
}
|
|
3759
|
+
return main;
|
|
3760
|
+
}
|
|
3709
3761
|
//#endregion
|
|
3710
3762
|
//#region src/client/slot-context.ts
|
|
3711
3763
|
/**
|
|
@@ -3735,17 +3787,7 @@ function computeComponentCacheKey(props, params) {
|
|
|
3735
3787
|
*
|
|
3736
3788
|
* See design/45-cache-lifetimes.md §Slot Components.
|
|
3737
3789
|
*/
|
|
3738
|
-
var
|
|
3739
|
-
function getOrCreateContext() {
|
|
3740
|
-
const existing = globalThis[CTX_KEY];
|
|
3741
|
-
if (existing !== void 0) return existing;
|
|
3742
|
-
if (typeof React.createContext === "function") {
|
|
3743
|
-
const ctx = React.createContext(null);
|
|
3744
|
-
globalThis[CTX_KEY] = ctx;
|
|
3745
|
-
return ctx;
|
|
3746
|
-
}
|
|
3747
|
-
}
|
|
3748
|
-
var SlotContext = getOrCreateContext();
|
|
3790
|
+
var SlotContext = createGlobalContext(Symbol.for("__timber_slot_ctx"), null);
|
|
3749
3791
|
//#endregion
|
|
3750
3792
|
//#region src/client/slot-outlet.tsx
|
|
3751
3793
|
/**
|
|
@@ -3891,6 +3933,37 @@ function warnNestingClamps(outer, nested, warnedPairs, log) {
|
|
|
3891
3933
|
}
|
|
3892
3934
|
return count;
|
|
3893
3935
|
}
|
|
3936
|
+
//#endregion
|
|
3937
|
+
//#region src/server/prebuilt/slots.ts
|
|
3938
|
+
/**
|
|
3939
|
+
* Slot-component helpers for cache.component (TIM-1173).
|
|
3940
|
+
*
|
|
3941
|
+
* A `slots: ['children', ...]` declaration caches the component's output
|
|
3942
|
+
* as a shell with a stable <SlotOutlet slot={name} /> client-reference
|
|
3943
|
+
* hole per declared slot prop; live slot content composes in per instance
|
|
3944
|
+
* at request time via SlotsProvider/SlotContext. This generalizes the
|
|
3945
|
+
* TIM-1181 layout mechanism to explicitly declared, named slots on any
|
|
3946
|
+
* cached component. Layouts use the same mechanism with a `children` slot.
|
|
3947
|
+
*
|
|
3948
|
+
* The `__prebuilt` wrapper builds its slot render from these helpers, in
|
|
3949
|
+
* dev and production alike. See design/45-cache-lifetimes.md §Slot
|
|
3950
|
+
* Components.
|
|
3951
|
+
*/
|
|
3952
|
+
/**
|
|
3953
|
+
* Framework-internal slot name for layout children. Uses a prefix that
|
|
3954
|
+
* cannot collide with user-declared slot names (which are React prop
|
|
3955
|
+
* names). Layout children flow through SlotsProvider/SlotOutlet with
|
|
3956
|
+
* this key instead of the bare "children" key, so a cached component
|
|
3957
|
+
* with `slots: ['children']` inside a layout never shadows the layout's
|
|
3958
|
+
* own children delivery.
|
|
3959
|
+
*
|
|
3960
|
+
* Defined here (a server module) rather than in `client/slot-context.ts`
|
|
3961
|
+
* (`'use client'`) because RSC's client-reference proxying would replace
|
|
3962
|
+
* the string value with a proxy object in the server environment. The
|
|
3963
|
+
* client-side SlotOutlet receives this value via props, so it doesn't
|
|
3964
|
+
* need the constant. See TIM-1191.
|
|
3965
|
+
*/
|
|
3966
|
+
var LAYOUT_CHILDREN_SLOT = "\0timber:children";
|
|
3894
3967
|
/**
|
|
3895
3968
|
* Is this value the framework-injected layout children slot outlet
|
|
3896
3969
|
* (`<SlotOutlet slot={LAYOUT_CHILDREN_SLOT} />`)? Layout components
|
|
@@ -3948,9 +4021,8 @@ function isDenseStringArray(value) {
|
|
|
3948
4021
|
}
|
|
3949
4022
|
}
|
|
3950
4023
|
/**
|
|
3951
|
-
* Validate the `slots` option.
|
|
3952
|
-
*
|
|
3953
|
-
* active in production, so the tree shape a component sees never
|
|
4024
|
+
* Validate the `slots` option. The `__prebuilt` wrapper gates on this in
|
|
4025
|
+
* dev and production alike, so the tree shape a component sees never
|
|
3954
4026
|
* diverges between the two.
|
|
3955
4027
|
*/
|
|
3956
4028
|
function resolveSlotNames(id, options) {
|
|
@@ -4197,7 +4269,7 @@ function noteWrapperRender(innerId, options, props) {
|
|
|
4197
4269
|
}
|
|
4198
4270
|
//#endregion
|
|
4199
4271
|
//#region src/server/flight-source.ts
|
|
4200
|
-
var nodeFlight = typeof process !== "undefined" && process.release?.name === "node" && !(typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") ? await import("../_chunks/flight-source-node-
|
|
4272
|
+
var nodeFlight = typeof process !== "undefined" && process.release?.name === "node" && !(typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") ? await import("../_chunks/flight-source-node-BdHUOUqg.js") : null;
|
|
4201
4273
|
/** The Node helpers, which a `kind: 'node'` source can only exist alongside. */
|
|
4202
4274
|
function requireNodeFlight() {
|
|
4203
4275
|
if (!nodeFlight) throw new Error("[timber] a Node Flight source reached a runtime without node:stream");
|
|
@@ -4258,6 +4330,133 @@ async function collectFlightBytes(source, timeoutMs, label) {
|
|
|
4258
4330
|
return concatBytes(chunks.map(flightChunkBytes));
|
|
4259
4331
|
}
|
|
4260
4332
|
//#endregion
|
|
4333
|
+
//#region src/server/prebuilt/synthetic-store.ts
|
|
4334
|
+
/**
|
|
4335
|
+
* Thrown when a prerendered component touches per-request context at
|
|
4336
|
+
* build time. The capture pass treats this as a HARD build error —
|
|
4337
|
+
* it indicates a design mistake, not transient bad data (design/44
|
|
4338
|
+
* §Build-Phase Error Handling).
|
|
4339
|
+
*/
|
|
4340
|
+
var BuildTimeContextError = class extends Error {
|
|
4341
|
+
/** The per-request API that was called (e.g. "cookies()"). */
|
|
4342
|
+
api;
|
|
4343
|
+
constructor(componentId, api) {
|
|
4344
|
+
super(`[timber] cache.component "${componentId}": ${api} cannot be used in a prerendered component — there is no request at build time. Prerendered components may read segment params and timber.cache data only. Remove the ${api} call, or drop { prerender: true } and render this component per-request. (design/44-render-at-build-time.md §Param Injection)`);
|
|
4345
|
+
this.name = "BuildTimeContextError";
|
|
4346
|
+
this.api = api;
|
|
4347
|
+
}
|
|
4348
|
+
};
|
|
4349
|
+
/**
|
|
4350
|
+
* Create the synthetic per-combo store. `segmentParams` must already be
|
|
4351
|
+
* coerced through the route's codecs — cache-key parity with request time
|
|
4352
|
+
* depends on hashing the exact record `coerceSegmentParams` produces.
|
|
4353
|
+
*/
|
|
4354
|
+
function createBuildTimeStore(componentId, segmentParams) {
|
|
4355
|
+
const violations = [];
|
|
4356
|
+
const handle = {
|
|
4357
|
+
store: null,
|
|
4358
|
+
violations,
|
|
4359
|
+
segmentParamsRead: false
|
|
4360
|
+
};
|
|
4361
|
+
const store = {
|
|
4362
|
+
request: null,
|
|
4363
|
+
headers: new Headers(),
|
|
4364
|
+
originalHeaders: new Headers(),
|
|
4365
|
+
cookieHeader: "",
|
|
4366
|
+
searchParams: new URLSearchParams(),
|
|
4367
|
+
searchString: "",
|
|
4368
|
+
segmentParams,
|
|
4369
|
+
cookieJar: /* @__PURE__ */ new Map(),
|
|
4370
|
+
flushed: false,
|
|
4371
|
+
mutableContext: false
|
|
4372
|
+
};
|
|
4373
|
+
const violate = (api) => {
|
|
4374
|
+
const error = new BuildTimeContextError(componentId, api);
|
|
4375
|
+
violations.push(error);
|
|
4376
|
+
throw error;
|
|
4377
|
+
};
|
|
4378
|
+
Object.defineProperties(store, {
|
|
4379
|
+
headers: { get: () => violate("headers()") },
|
|
4380
|
+
parsedCookies: { get: () => violate("cookies()") },
|
|
4381
|
+
searchParams: { get: () => violate("searchParams") },
|
|
4382
|
+
mutableContext: { get: () => violate("cookies()") },
|
|
4383
|
+
segmentParams: {
|
|
4384
|
+
get: () => {
|
|
4385
|
+
handle.segmentParamsRead = true;
|
|
4386
|
+
return segmentParams;
|
|
4387
|
+
},
|
|
4388
|
+
enumerable: true
|
|
4389
|
+
}
|
|
4390
|
+
});
|
|
4391
|
+
handle.store = store;
|
|
4392
|
+
return handle;
|
|
4393
|
+
}
|
|
4394
|
+
//#endregion
|
|
4395
|
+
//#region src/server/prebuilt/capture-render.ts
|
|
4396
|
+
/**
|
|
4397
|
+
* One build-time capture entry: render a registered component in isolation
|
|
4398
|
+
* under the synthetic build store and drain its flight payload under a
|
|
4399
|
+
* deadline. Run by the post-build capture pass (server/prebuilt-builder.ts)
|
|
4400
|
+
* and, in dev, by the first request for a prerender entry
|
|
4401
|
+
* (server/prebuilt-runtime.ts, TIM-1588) — which is why the flight renderer
|
|
4402
|
+
* is a parameter: the request-time runtime renders through the functions
|
|
4403
|
+
* the RSC entry injected.
|
|
4404
|
+
*/
|
|
4405
|
+
/**
|
|
4406
|
+
* Render one (component, props, coerced-params) entry in isolation and drain
|
|
4407
|
+
* its flight payload. Any `onError` during serialization fails the entry —
|
|
4408
|
+
* a payload with an embedded error row would replay that error on every
|
|
4409
|
+
* future request, so only fully clean renders are captured.
|
|
4410
|
+
*/
|
|
4411
|
+
async function renderEntry(registration, props, coercedParams, timeoutMs, isLayout, renderFlight) {
|
|
4412
|
+
const storeHandle = createBuildTimeStore(registration.id, coercedParams);
|
|
4413
|
+
const { store, violations } = storeHandle;
|
|
4414
|
+
let failure = null;
|
|
4415
|
+
const capture = createCaptureScope(registration.id, registration.options, props);
|
|
4416
|
+
let bytes = null;
|
|
4417
|
+
let resolvedTags;
|
|
4418
|
+
try {
|
|
4419
|
+
const renderProps = isLayout && !("children" in props) ? {
|
|
4420
|
+
...props,
|
|
4421
|
+
children: createElement(SlotOutlet, { slot: LAYOUT_CHILDREN_SLOT })
|
|
4422
|
+
} : props;
|
|
4423
|
+
bytes = await capture.run(() => requestContextAls.run(store, async () => {
|
|
4424
|
+
const drained = await collectFlightBytes(renderFlight(createElement(registration.component, renderProps), { onError(error) {
|
|
4425
|
+
failure ??= error ?? /* @__PURE__ */ new Error("unknown render error");
|
|
4426
|
+
return "timber-prebuilt-capture-error";
|
|
4427
|
+
} }), timeoutMs, "render");
|
|
4428
|
+
const tags = resolveTags(registration.options, props);
|
|
4429
|
+
resolvedTags = tags.length > 0 ? tags : void 0;
|
|
4430
|
+
return drained;
|
|
4431
|
+
}));
|
|
4432
|
+
} catch (error) {
|
|
4433
|
+
failure ??= error;
|
|
4434
|
+
}
|
|
4435
|
+
const nested = capture.nestedRenders();
|
|
4436
|
+
const { segmentParamsRead } = storeHandle;
|
|
4437
|
+
if (violations.length > 0) return {
|
|
4438
|
+
bytes: null,
|
|
4439
|
+
failure: violations[0],
|
|
4440
|
+
nested,
|
|
4441
|
+
resolvedTags,
|
|
4442
|
+
segmentParamsRead
|
|
4443
|
+
};
|
|
4444
|
+
if (failure !== null) return {
|
|
4445
|
+
bytes: null,
|
|
4446
|
+
failure,
|
|
4447
|
+
nested,
|
|
4448
|
+
resolvedTags,
|
|
4449
|
+
segmentParamsRead
|
|
4450
|
+
};
|
|
4451
|
+
return {
|
|
4452
|
+
bytes,
|
|
4453
|
+
failure: null,
|
|
4454
|
+
nested,
|
|
4455
|
+
resolvedTags,
|
|
4456
|
+
segmentParamsRead
|
|
4457
|
+
};
|
|
4458
|
+
}
|
|
4459
|
+
//#endregion
|
|
4261
4460
|
//#region src/server/prebuilt-runtime.ts
|
|
4262
4461
|
/**
|
|
4263
4462
|
* Prebuilt component runtime — registration target for the timber-prebuilt
|
|
@@ -4265,9 +4464,11 @@ async function collectFlightBytes(source, timeoutMs, label) {
|
|
|
4265
4464
|
* cache.component (TIM-1140).
|
|
4266
4465
|
*
|
|
4267
4466
|
* `cache.component(fn, opts)` call sites are rewritten at build time to
|
|
4268
|
-
* `__prebuilt(stableId, fn, opts)
|
|
4269
|
-
*
|
|
4270
|
-
*
|
|
4467
|
+
* `__prebuilt(stableId, fn, opts)`, in dev and production alike. It is
|
|
4468
|
+
* exported via #server-internal — framework plumbing, never called by user
|
|
4469
|
+
* code directly. In dev the build artifact is replaced by the in-memory dev
|
|
4470
|
+
* store (prebuilt/dev-store.ts): a prerender entry is captured on its first
|
|
4471
|
+
* request and served until a watched file changes (TIM-1588).
|
|
4271
4472
|
*
|
|
4272
4473
|
* Cache hits are served by FLIGHT REVIVAL: the cached `.flight` payload is
|
|
4273
4474
|
* decoded back into React elements inside the RSC environment with
|
|
@@ -4309,61 +4510,12 @@ var warnedNestingPairs = /* @__PURE__ */ new Set();
|
|
|
4309
4510
|
/**
|
|
4310
4511
|
* Server-side component registry, keyed by stable component ID. Populated at
|
|
4311
4512
|
* module load time by `__prebuilt` calls; consumed by the post-build capture
|
|
4312
|
-
* pass (TIM-1119). Never serialized — component functions are not
|
|
4513
|
+
* pass (TIM-1119). Not written in dev, where nothing walks it. Never serialized — component functions are not
|
|
4313
4514
|
* Flight-serializable.
|
|
4314
4515
|
*/
|
|
4315
4516
|
var registry = /* @__PURE__ */ new Map();
|
|
4316
|
-
/**
|
|
4317
|
-
|
|
4318
|
-
* render is unkeyable.
|
|
4319
|
-
*
|
|
4320
|
-
* A wrapper rendered inside a parallel slot reads params merged with that
|
|
4321
|
-
* slot's overrides (`getSegmentParams`: `{...segmentParams, ...slotParams}`)
|
|
4322
|
-
* — but the cache key hashes only the route-level params, and the wrapper
|
|
4323
|
-
* cannot know which slot it renders under. The route params are usable
|
|
4324
|
-
* only when every slot's merged view canonicalizes identically to them;
|
|
4325
|
-
* otherwise two renders with the same key could see different effective
|
|
4326
|
-
* inputs and a hit could serve the WRONG cached subtree — so the render
|
|
4327
|
-
* goes live: slower, never wrong. (Build-time capture doesn't model slot
|
|
4328
|
-
* params either, so a divergent request could never have a faithful
|
|
4329
|
-
* entry. Codex review on PR #835; revisit with segment-path-scoped keys
|
|
4330
|
-
* if slot-scoped prebuilt is ever needed.)
|
|
4331
|
-
*
|
|
4332
|
-
* Comparison happens through `tryCanonicalize` — the same single
|
|
4333
|
-
* definition of value equality the cache key uses — so anything it
|
|
4334
|
-
* cannot represent faithfully (bigint-coerced codec params, accessors,
|
|
4335
|
-
* aliases, …) is unkeyable here too, and this guard can never throw.
|
|
4336
|
-
*/
|
|
4337
|
-
function resolveKeyParams(store) {
|
|
4338
|
-
const main = store.segmentParams ?? {};
|
|
4339
|
-
const slots = store.slotParams;
|
|
4340
|
-
if (!slots || Object.keys(slots).length === 0) return main;
|
|
4341
|
-
const mainCanonical = tryCanonicalize({ ...main });
|
|
4342
|
-
if (mainCanonical === null) return null;
|
|
4343
|
-
for (const slotParams of Object.values(slots)) {
|
|
4344
|
-
const merged = tryCanonicalize({
|
|
4345
|
-
...main,
|
|
4346
|
-
...slotParams
|
|
4347
|
-
});
|
|
4348
|
-
if (merged === null || merged !== mainCanonical) return null;
|
|
4349
|
-
}
|
|
4350
|
-
return main;
|
|
4351
|
-
}
|
|
4352
|
-
/**
|
|
4353
|
-
* Mirror the production cache-key decision for a slot render, with no
|
|
4354
|
-
* cache IO — used by the dev wrapper so slot substitution happens in dev
|
|
4355
|
-
* exactly when production would serve the cache path rather than the
|
|
4356
|
-
* live fallback (dev/prod parity, codex P2 on PR #890): requires an ALS
|
|
4357
|
-
* store, keyable params (slot-param divergence unkeys), and keyable data
|
|
4358
|
-
* props (after the children slot outlet strip).
|
|
4359
|
-
*/
|
|
4360
|
-
function isSlotRenderKeyable(dataProps) {
|
|
4361
|
-
const store = requestContextAls.getStore();
|
|
4362
|
-
if (!store) return false;
|
|
4363
|
-
const keyParams = resolveKeyParams(store);
|
|
4364
|
-
if (keyParams === null) return false;
|
|
4365
|
-
return computeComponentCacheKey(withoutChildrenOutlet(dataProps), keyParams) !== null;
|
|
4366
|
-
}
|
|
4517
|
+
/** Dev: IDs registered so far, to detect a module re-evaluating (no functions held). */
|
|
4518
|
+
var devRegisteredIds = /* @__PURE__ */ new Set();
|
|
4367
4519
|
/** Wrap payload bytes as a single-chunk ReadableStream for the decoder. */
|
|
4368
4520
|
function bytesToStream(bytes) {
|
|
4369
4521
|
return new ReadableStream({ start(controller) {
|
|
@@ -4379,11 +4531,11 @@ function bytesToStream(bytes) {
|
|
|
4379
4531
|
*
|
|
4380
4532
|
* Null on any miss — the caller renders live with the original props.
|
|
4381
4533
|
*/
|
|
4382
|
-
async function tryReviveSlotShell(
|
|
4534
|
+
async function tryReviveSlotShell(registration, slots, props) {
|
|
4383
4535
|
const render = prepareSlotRender(props, slots);
|
|
4384
4536
|
if (render === null) return null;
|
|
4385
4537
|
const { shellProps, dataProps, slotValues } = render;
|
|
4386
|
-
const revived = await tryRevivePayload(
|
|
4538
|
+
const revived = await tryRevivePayload(registration, shellProps, dataProps);
|
|
4387
4539
|
if (revived === null) return null;
|
|
4388
4540
|
return { element: wrapInSlotsProvider(revived.element, slotValues) };
|
|
4389
4541
|
}
|
|
@@ -4444,13 +4596,22 @@ async function captureComponentPayload(id, component, props, options) {
|
|
|
4444
4596
|
* warning follows the store: a capture that is discarded (aborted,
|
|
4445
4597
|
* invalidated mid-render, failed store) holds no clamped copy, and must
|
|
4446
4598
|
* not spend the pair's one warning.
|
|
4599
|
+
*
|
|
4600
|
+
* A failed store is swallowed, like a failed `cache.data` write (TIM-1046):
|
|
4601
|
+
* the captured payload is valid and still answers the request. Thrown, it
|
|
4602
|
+
* would discard the capture and render the component a second time.
|
|
4447
4603
|
*/
|
|
4448
4604
|
async function storeCapturedEntry(id, cacheKey, captured, options, tags, hasSeed) {
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4605
|
+
try {
|
|
4606
|
+
await storeOverlayEntry(id, cacheKey, captured.bytes, {
|
|
4607
|
+
ttl: options.ttl,
|
|
4608
|
+
tags,
|
|
4609
|
+
hasSeed
|
|
4610
|
+
});
|
|
4611
|
+
} catch (err) {
|
|
4612
|
+
swallow(err, `cache.component overlay store failed for "${id}"`);
|
|
4613
|
+
return;
|
|
4614
|
+
}
|
|
4454
4615
|
warnNestingClamps({
|
|
4455
4616
|
id,
|
|
4456
4617
|
options,
|
|
@@ -4518,16 +4679,77 @@ function backgroundRerender(id, component, props, cacheKey, options, hasSeed, sn
|
|
|
4518
4679
|
console.warn("[timber] cache.component SWR background re-render has no waitUntil — the re-render may be killed when the handler returns on serverless platforms. Ensure the adapter wires runWithWaitUntil().");
|
|
4519
4680
|
}
|
|
4520
4681
|
}
|
|
4682
|
+
/** Components already announced by the one-time dev log. */
|
|
4683
|
+
var devLoggedIds = /* @__PURE__ */ new Set();
|
|
4684
|
+
/**
|
|
4685
|
+
* Dev: the seed for a prerender entry — the stored capture, or a new one
|
|
4686
|
+
* rendered exactly as the build would render it (synthetic store, isolated
|
|
4687
|
+
* render, nested wrappers baked flat) and stored until the next source
|
|
4688
|
+
* change (prebuilt/dev-store.ts).
|
|
4689
|
+
*
|
|
4690
|
+
* Throws the BuildTimeContextError when the component read request
|
|
4691
|
+
* context: `pnpm build` would fail on it, so dev fails too. Null on any
|
|
4692
|
+
* other capture failure — the live render that follows reproduces the
|
|
4693
|
+
* error, deny(), or redirect() with its normal semantics.
|
|
4694
|
+
*/
|
|
4695
|
+
async function resolveDevSeed(registration, props, keyParams, cacheKey) {
|
|
4696
|
+
const { id, options } = registration;
|
|
4697
|
+
const stored = getDevSeed(id, cacheKey);
|
|
4698
|
+
if (stored) return {
|
|
4699
|
+
payload: stored.bytes,
|
|
4700
|
+
capturedAt: stored.capturedAt
|
|
4701
|
+
};
|
|
4702
|
+
const tags = resolveTags(options, props);
|
|
4703
|
+
const oKey = overlayKey(id, cacheKey);
|
|
4704
|
+
const sfKey = `prebuilt-dev:${id}:${cacheKey}\0${lastInvalidationEpochFor(oKey, tags)}`;
|
|
4705
|
+
try {
|
|
4706
|
+
return await componentSingleflight.do(sfKey, async (signal) => {
|
|
4707
|
+
const startEpoch = currentInvalidationEpoch();
|
|
4708
|
+
const capturedAt = Date.now();
|
|
4709
|
+
const { renderFlight } = requireRscFunctions();
|
|
4710
|
+
const outcome = await runOutsideReactCacheScope(() => renderEntry(registration, props, keyParams, getCaptureTimeoutMs(), false, renderFlight));
|
|
4711
|
+
if (outcome.failure instanceof BuildTimeContextError) throw outcome.failure;
|
|
4712
|
+
if (outcome.bytes === null) return null;
|
|
4713
|
+
if (await revivePayload(id, outcome.bytes, "not storing the dev capture") === null) return null;
|
|
4714
|
+
if (!signal.aborted && !wasInvalidatedSince(startEpoch, oKey, tags)) {
|
|
4715
|
+
setDevSeed(id, cacheKey, {
|
|
4716
|
+
bytes: outcome.bytes,
|
|
4717
|
+
tags,
|
|
4718
|
+
capturedAt
|
|
4719
|
+
});
|
|
4720
|
+
warnNestingClamps({
|
|
4721
|
+
id,
|
|
4722
|
+
options,
|
|
4723
|
+
tags
|
|
4724
|
+
}, outcome.nested, warnedNestingPairs, (m) => console.warn(m));
|
|
4725
|
+
if (!devLoggedIds.has(id)) {
|
|
4726
|
+
devLoggedIds.add(id);
|
|
4727
|
+
console.log(`[timber] cache.component "${id}": prerendered in dev — served from memory until a file changes. A hard reload (Cache-Control: no-cache) renders it again.`);
|
|
4728
|
+
}
|
|
4729
|
+
}
|
|
4730
|
+
return {
|
|
4731
|
+
payload: outcome.bytes,
|
|
4732
|
+
capturedAt
|
|
4733
|
+
};
|
|
4734
|
+
});
|
|
4735
|
+
} catch (error) {
|
|
4736
|
+
if (error instanceof BuildTimeContextError) throw error;
|
|
4737
|
+
console.error(`[timber] cache.component dev capture failed for "${id}":`, error);
|
|
4738
|
+
return null;
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4521
4741
|
/**
|
|
4522
|
-
* Try to serve this render from the prebuilt cache: overlay →
|
|
4742
|
+
* Try to serve this render from the prebuilt cache: overlay → seed →
|
|
4523
4743
|
* live render. Handles ISR (SWR, tombstones, re-renders) per design/45.
|
|
4524
4744
|
*
|
|
4525
4745
|
* Null on any miss — the caller renders live.
|
|
4526
4746
|
*/
|
|
4527
|
-
async function tryRevivePayload(
|
|
4747
|
+
async function tryRevivePayload(registration, props, keyPropsOverride) {
|
|
4748
|
+
const { id, options, component } = registration;
|
|
4528
4749
|
const hasSource = hasPrebuiltPayloadSource();
|
|
4750
|
+
const devStore = isDevPrebuiltStoreActive();
|
|
4529
4751
|
const hasRuntime = hasRuntimeLifetime(options);
|
|
4530
|
-
if (!hasSource && !hasRuntime) return null;
|
|
4752
|
+
if (!hasSource && !devStore && !hasRuntime) return null;
|
|
4531
4753
|
const store = requestContextAls.getStore();
|
|
4532
4754
|
if (!store) return null;
|
|
4533
4755
|
const keyParams = (options.prerender ? await isParamIndependent(id) : false) ? {} : resolveKeyParams(store);
|
|
@@ -4535,45 +4757,40 @@ async function tryRevivePayload(id, options, props, keyPropsOverride) {
|
|
|
4535
4757
|
const cacheKey = computeComponentCacheKey(withoutChildrenOutlet(keyPropsOverride ?? props ?? {}), keyParams);
|
|
4536
4758
|
if (cacheKey === null) return null;
|
|
4537
4759
|
const outcome = options.fallbackOnMissingSegmentParams === false ? "failing the render (fallbackOnMissingSegmentParams: false)" : "rendering dynamically";
|
|
4538
|
-
|
|
4760
|
+
if (devStore && isHardReload(store.originalHeaders)) await discardDevEntry(id, cacheKey, overlayKey(id, cacheKey));
|
|
4761
|
+
let overlayUnreadable = false;
|
|
4539
4762
|
if (hasRuntime) {
|
|
4540
4763
|
const overlayResult = await lookupOverlay(id, cacheKey);
|
|
4541
4764
|
if (overlayResult) {
|
|
4542
4765
|
const overlayHasSeed = overlayResult.record?.s ?? false;
|
|
4543
|
-
if (overlayResult.kind === "tombstone")
|
|
4544
|
-
|
|
4545
|
-
return null;
|
|
4546
|
-
}
|
|
4766
|
+
if (overlayResult.kind === "tombstone") return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
4767
|
+
overlayUnreadable = overlayResult.kind === "unreadable";
|
|
4547
4768
|
if (overlayResult.kind === "fresh" && overlayResult.payload) return await revivePayload(id, overlayResult.payload, outcome);
|
|
4548
4769
|
if (overlayResult.kind === "stale" && overlayResult.payload) {
|
|
4549
|
-
if (options.staleWhileRevalidate
|
|
4770
|
+
if (options.staleWhileRevalidate) {
|
|
4550
4771
|
backgroundRerender(id, component, props, cacheKey, options, overlayHasSeed, snapshotRequestContext(store));
|
|
4551
4772
|
return await revivePayload(id, overlayResult.payload, outcome);
|
|
4552
4773
|
}
|
|
4553
|
-
|
|
4554
|
-
return null;
|
|
4774
|
+
return await inlineRerender(id, component, props, cacheKey, options, overlayHasSeed, outcome);
|
|
4555
4775
|
}
|
|
4556
4776
|
}
|
|
4557
4777
|
}
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
if (
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
return await revivePayload(id, artifactPayload, outcome);
|
|
4567
|
-
}
|
|
4568
|
-
if (component) return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
4569
|
-
return null;
|
|
4778
|
+
const seed = devStore ? options.prerender ? await resolveDevSeed(registration, props, keyParams, cacheKey) : null : hasSource ? await lookupArtifactSeed(id, cacheKey, options.ttl !== void 0) : null;
|
|
4779
|
+
if (seed !== null && overlayUnreadable) return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
4780
|
+
if (seed !== null) {
|
|
4781
|
+
if (options.ttl !== void 0) {
|
|
4782
|
+
if ((Date.now() - seed.capturedAt) / 1e3 > options.ttl) {
|
|
4783
|
+
if (options.staleWhileRevalidate) {
|
|
4784
|
+
backgroundRerender(id, component, props, cacheKey, options, true, snapshotRequestContext(store));
|
|
4785
|
+
return await revivePayload(id, seed.payload, outcome);
|
|
4570
4786
|
}
|
|
4787
|
+
return await inlineRerender(id, component, props, cacheKey, options, true, outcome);
|
|
4571
4788
|
}
|
|
4572
|
-
return await revivePayload(id, artifactPayload, outcome);
|
|
4573
4789
|
}
|
|
4574
|
-
|
|
4790
|
+
return await revivePayload(id, seed.payload, outcome);
|
|
4575
4791
|
}
|
|
4576
|
-
if (
|
|
4792
|
+
if (hasSource && options.prerender) console.warn(`[timber] cache.component cache miss: "${id}" with params ${JSON.stringify(store.segmentParams ?? {})} — ${outcome}`);
|
|
4793
|
+
if (hasRuntime && options.fallbackOnMissingSegmentParams !== false) return await inlineRerender(id, component, props, cacheKey, options, false, outcome);
|
|
4577
4794
|
return null;
|
|
4578
4795
|
}
|
|
4579
4796
|
/**
|
|
@@ -4596,15 +4813,20 @@ function __prebuilt(id, component, options = {}) {
|
|
|
4596
4813
|
...options,
|
|
4597
4814
|
slots: void 0
|
|
4598
4815
|
};
|
|
4599
|
-
|
|
4816
|
+
const registration = {
|
|
4600
4817
|
id,
|
|
4601
4818
|
component,
|
|
4602
4819
|
options
|
|
4603
|
-
}
|
|
4820
|
+
};
|
|
4821
|
+
if (isDevPrebuiltStoreActive()) {
|
|
4822
|
+
if (devRegisteredIds.has(id)) clearDevPrebuiltStore();
|
|
4823
|
+
devRegisteredIds.add(id);
|
|
4824
|
+
} else registry.set(id, registration);
|
|
4604
4825
|
const wrapper = async (props) => {
|
|
4605
4826
|
noteWrapperRender(id, options, props);
|
|
4606
4827
|
if (isCaptureActive()) return createElement(component, props);
|
|
4607
|
-
|
|
4828
|
+
if (isDevPrebuiltCacheBypassed()) return createElement(component, props);
|
|
4829
|
+
const revived = slots ? await tryReviveSlotShell(registration, slots, props) : await tryRevivePayload(registration, props);
|
|
4608
4830
|
if (revived !== null) return revived.element;
|
|
4609
4831
|
if (options.fallbackOnMissingSegmentParams === false) throw new Error(`[timber] cache.component "${id}": no prebuilt payload for the current params and fallbackOnMissingSegmentParams is false`);
|
|
4610
4832
|
return createElement(component, props);
|
|
@@ -4620,30 +4842,7 @@ function getPrebuiltRegistration(id) {
|
|
|
4620
4842
|
function getPrebuiltRegistry() {
|
|
4621
4843
|
return registry;
|
|
4622
4844
|
}
|
|
4623
|
-
/**
|
|
4624
|
-
* Dev-mode wrapper injected by the timber-prebuilt transform: a no-op that
|
|
4625
|
-
* renders the component dynamically on every request, logging once per
|
|
4626
|
-
* component on first render so the production behavior difference is visible.
|
|
4627
|
-
* See design/44 §Dev Mode.
|
|
4628
|
-
*/
|
|
4629
|
-
function __prebuiltDev(name, component, options = {}) {
|
|
4630
|
-
const resolution = resolveSlotNames(name, options);
|
|
4631
|
-
const slots = resolution.kind === "active" ? resolution.slots : null;
|
|
4632
|
-
let logged = false;
|
|
4633
|
-
const wrapper = (props) => {
|
|
4634
|
-
if (!logged) {
|
|
4635
|
-
logged = true;
|
|
4636
|
-
console.log(`[timber] cache.component: "${name}" — rendering dynamically (dev mode)`);
|
|
4637
|
-
}
|
|
4638
|
-
if (slots) {
|
|
4639
|
-
const render = prepareSlotRender(props, slots);
|
|
4640
|
-
if (render !== null && isSlotRenderKeyable(render.dataProps)) return wrapInSlotsProvider(createElement(component, render.shellProps), render.slotValues);
|
|
4641
|
-
}
|
|
4642
|
-
return createElement(component, props);
|
|
4643
|
-
};
|
|
4644
|
-
return wrapper;
|
|
4645
|
-
}
|
|
4646
4845
|
//#endregion
|
|
4647
|
-
export { AccessGate, DEFAULT_LIMITS, DenySignal, METADATA_ROUTE_CONVENTIONS, RedirectSignal, RenderTimeoutError, SlotAccessGate, __prebuilt,
|
|
4846
|
+
export { AccessGate, DEFAULT_LIMITS, DenySignal, METADATA_ROUTE_CONVENTIONS, RedirectSignal, RenderTimeoutError, SlotAccessGate, __prebuilt, callOnRequestError, canonicalize, classifyMetadataRoute, coerce, collectEarlyHintHeaders, computeComponentCacheKey, createPipeline, enforceBodyLimits, executeAction, formatLinkHeader, generateTraceId, getCookie, getHeader, getLogger, getMetadataRouteAutoLink, getMetadataRouteServePath, getPrebuiltRegistration, getPrebuiltRegistry, getSearchParams, getSegmentParams, getSetCookieHeaders, handleRouteRequest, hasOnRequestError, hasPrebuiltPayloadSource, loadInstrumentation, logCacheMiss, logMiddlewareError, logMiddlewareShortCircuit, logProxyError, logRenderError, logRequestCompleted, logRequestReceived, logSlowRequest, logSwrRefetchFailed, logWaitUntilRejected, logWaitUntilUnsupported, markResponseFlushed, parseBodySize, renderMetadataToElements, replaceTraceId, resolveAllowedMethods, resolveMetadata, resolveMetadataUrls, resolveSlotDenied, resolveStatusFile, resolveTitle, runMiddleware, runProxy, runWithEarlyHintsSender, runWithRequestContext, runWithTraceId, sendEarlyHints103, setLogger, setMutableCookieContext, setPrebuiltPayloadSource, setSegmentParams };
|
|
4648
4847
|
|
|
4649
4848
|
//# sourceMappingURL=internal.js.map
|