@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.
Files changed (236) hide show
  1. package/dist/_chunks/{actions-BwkmAYXq.js → actions-vBHr2vqd.js} +3 -3
  2. package/dist/_chunks/{actions-BwkmAYXq.js.map → actions-vBHr2vqd.js.map} +1 -1
  3. package/dist/_chunks/{cache-api-LA3sBpUS.js → cache-api-DdcDLpBj.js} +72 -145
  4. package/dist/_chunks/cache-api-DdcDLpBj.js.map +1 -0
  5. package/dist/_chunks/chains-B8TCLved.js +1 -0
  6. package/dist/_chunks/{chains-e_Buf9vg.js → chains-BchW_AtW.js} +2 -2
  7. package/dist/_chunks/{chains-e_Buf9vg.js.map → chains-BchW_AtW.js.map} +1 -1
  8. package/dist/_chunks/{classify-2Yp3xJY1.js → classify-IqzMpxMs.js} +2 -2
  9. package/dist/_chunks/{classify-2Yp3xJY1.js.map → classify-IqzMpxMs.js.map} +1 -1
  10. package/dist/_chunks/{cli-check-DDwCkeDY.js → cli-check-DQne_YhU.js} +3 -3
  11. package/dist/_chunks/{cli-check-DDwCkeDY.js.map → cli-check-DQne_YhU.js.map} +1 -1
  12. package/dist/_chunks/{cli-schema-sync-BdIebmk3.js → cli-schema-sync-BS-RFGE2.js} +2 -2
  13. package/dist/_chunks/{cli-schema-sync-BdIebmk3.js.map → cli-schema-sync-BS-RFGE2.js.map} +1 -1
  14. package/dist/_chunks/{cli-schema-sync-CLNfXQDK.js → cli-schema-sync-v872sHms.js} +1 -1
  15. package/dist/_chunks/{client-dep-entries-BOkpKjj1.js → client-dep-entries-BJyP9SIu.js} +2 -2
  16. package/dist/_chunks/{client-dep-entries-BOkpKjj1.js.map → client-dep-entries-BJyP9SIu.js.map} +1 -1
  17. package/dist/_chunks/{convention-lint-ByKJ6aqD.js → convention-lint-VwzrtjIt.js} +3 -3
  18. package/dist/_chunks/{convention-lint-ByKJ6aqD.js.map → convention-lint-VwzrtjIt.js.map} +1 -1
  19. package/dist/_chunks/{dev-server-DnODXuNM.js → dev-server-BNr5drEO.js} +57 -8
  20. package/dist/_chunks/dev-server-BNr5drEO.js.map +1 -0
  21. package/dist/_chunks/dev-server-CUg7Mqh_.js +1 -0
  22. package/dist/_chunks/dev-store-BOa304m_.js +283 -0
  23. package/dist/_chunks/dev-store-BOa304m_.js.map +1 -0
  24. package/dist/_chunks/{error-boundary-xxxLtXt6.js → error-boundary-Bc8QPZuq.js} +71 -21
  25. package/dist/_chunks/error-boundary-Bc8QPZuq.js.map +1 -0
  26. package/dist/_chunks/{flight-source-node-0dE-t3kq.js → flight-source-node-BdHUOUqg.js} +6 -7
  27. package/dist/_chunks/flight-source-node-BdHUOUqg.js.map +1 -0
  28. package/dist/_chunks/global-context-B9PFncvb.js +48 -0
  29. package/dist/_chunks/global-context-B9PFncvb.js.map +1 -0
  30. package/dist/_chunks/{json-lossy-check-C8zBY2uZ.js → json-lossy-check-C3Sht92C.js} +2 -2
  31. package/dist/_chunks/{json-lossy-check-C8zBY2uZ.js.map → json-lossy-check-C3Sht92C.js.map} +1 -1
  32. package/dist/_chunks/{live-graph-tSWrv8eH.js → live-graph-DEu_GWbc.js} +4 -4
  33. package/dist/_chunks/{live-graph-tSWrv8eH.js.map → live-graph-DEu_GWbc.js.map} +1 -1
  34. package/dist/_chunks/{logger-CbLdcy-W.js → logger-CI_hThfy.js} +10 -2
  35. package/dist/_chunks/{logger-CbLdcy-W.js.map → logger-CI_hThfy.js.map} +1 -1
  36. package/dist/_chunks/{node-response-Dibufw_b.js → node-response-bF0bKoig.js} +49 -3
  37. package/dist/_chunks/node-response-bF0bKoig.js.map +1 -0
  38. package/dist/_chunks/{poison-scan-C4FgMxFl.js → poison-scan-DTWIfNgD.js} +2 -2
  39. package/dist/_chunks/{poison-scan-C4FgMxFl.js.map → poison-scan-DTWIfNgD.js.map} +1 -1
  40. package/dist/_chunks/{purge-store-Byr8XOjU.js → purge-store-WZaxu-3m.js} +2 -2
  41. package/dist/_chunks/purge-store-WZaxu-3m.js.map +1 -0
  42. package/dist/_chunks/{render-timeout-DOf_BBcO.js → render-timeout-Ln_u7fX-.js} +19 -11
  43. package/dist/_chunks/render-timeout-Ln_u7fX-.js.map +1 -0
  44. package/dist/_chunks/{resolve-schema-CBR6Lm4i.js → resolve-schema-CkAInout.js} +2 -2
  45. package/dist/_chunks/{resolve-schema-CBR6Lm4i.js.map → resolve-schema-CkAInout.js.map} +1 -1
  46. package/dist/_chunks/{scanner-Cb3fSjAC.js → scanner-C8fdKvKG.js} +2 -2
  47. package/dist/_chunks/{scanner-Cb3fSjAC.js.map → scanner-C8fdKvKG.js.map} +1 -1
  48. package/dist/_chunks/{schema-bridge-C83xa9lT.js → schema-bridge-DpOmvZlI.js} +60 -23
  49. package/dist/_chunks/schema-bridge-DpOmvZlI.js.map +1 -0
  50. package/dist/_chunks/{segment-context-xtPUGfdq.js → segment-context-D3DNxKFq.js} +4 -8
  51. package/dist/_chunks/segment-context-D3DNxKFq.js.map +1 -0
  52. package/dist/_chunks/{sizeof-QPE5nd3u.js → sizeof-CO3dk0V1.js} +2 -2
  53. package/dist/_chunks/{sizeof-QPE5nd3u.js.map → sizeof-CO3dk0V1.js.map} +1 -1
  54. package/dist/_chunks/{walkers-qu8TpiLh.js → walkers-BqzxnwGC.js} +3 -3
  55. package/dist/_chunks/{walkers-qu8TpiLh.js.map → walkers-BqzxnwGC.js.map} +1 -1
  56. package/dist/adapters/cloudflare-kv-cache.js +1 -1
  57. package/dist/analyze/crawl-entry.js +3 -3
  58. package/dist/analyze/graph-command.js +2 -2
  59. package/dist/cache/cache-api.d.ts.map +1 -1
  60. package/dist/cache/guarded-read.d.ts +29 -0
  61. package/dist/cache/guarded-read.d.ts.map +1 -0
  62. package/dist/cache/handler-store.d.ts +13 -1
  63. package/dist/cache/handler-store.d.ts.map +1 -1
  64. package/dist/cache/index.js +3 -2
  65. package/dist/cache/invalidation-epoch.d.ts +7 -0
  66. package/dist/cache/invalidation-epoch.d.ts.map +1 -1
  67. package/dist/cache/stores/memory.js +1 -1
  68. package/dist/cache/timber-cache.d.ts.map +1 -1
  69. package/dist/cdn/index.js +1 -1
  70. package/dist/cdn/purge-store.d.ts +10 -1
  71. package/dist/cdn/purge-store.d.ts.map +1 -1
  72. package/dist/cli.js +3 -3
  73. package/dist/client/browser-entry/router-init.d.ts.map +1 -1
  74. package/dist/client/error-boundary.js +1 -1
  75. package/dist/client/global-context.d.ts +21 -1
  76. package/dist/client/global-context.d.ts.map +1 -1
  77. package/dist/client/index.js +9 -27
  78. package/dist/client/index.js.map +1 -1
  79. package/dist/client/internal.js +38 -65
  80. package/dist/client/internal.js.map +1 -1
  81. package/dist/client/link.d.ts.map +1 -1
  82. package/dist/client/navigation-context.d.ts.map +1 -1
  83. package/dist/client/navigation-transition.d.ts +68 -14
  84. package/dist/client/navigation-transition.d.ts.map +1 -1
  85. package/dist/client/params-context.d.ts.map +1 -1
  86. package/dist/client/router-effects.d.ts +35 -31
  87. package/dist/client/router-effects.d.ts.map +1 -1
  88. package/dist/client/router-pipeline.d.ts +2 -6
  89. package/dist/client/router-pipeline.d.ts.map +1 -1
  90. package/dist/client/router-types.d.ts +10 -30
  91. package/dist/client/router-types.d.ts.map +1 -1
  92. package/dist/client/router.d.ts.map +1 -1
  93. package/dist/client/slot-context.d.ts +2 -2
  94. package/dist/client/slot-context.d.ts.map +1 -1
  95. package/dist/codec.js +1 -1
  96. package/dist/cookies/index.js +1 -1
  97. package/dist/dev-tools/logs.d.ts +2 -2
  98. package/dist/dev-tools/logs.d.ts.map +1 -1
  99. package/dist/index.js +149 -56
  100. package/dist/index.js.map +1 -1
  101. package/dist/params/index.js +1 -1
  102. package/dist/plugins/dev-server.d.ts +1 -1
  103. package/dist/plugins/dev-server.d.ts.map +1 -1
  104. package/dist/plugins/dev-store-clear.d.ts +28 -0
  105. package/dist/plugins/dev-store-clear.d.ts.map +1 -0
  106. package/dist/plugins/entries.d.ts +5 -0
  107. package/dist/plugins/entries.d.ts.map +1 -1
  108. package/dist/plugins/orphaned-modules.d.ts +57 -0
  109. package/dist/plugins/orphaned-modules.d.ts.map +1 -0
  110. package/dist/plugins/prebuilt.d.ts +6 -6
  111. package/dist/plugins/prerender-sugar.d.ts.map +1 -1
  112. package/dist/plugins/routing.d.ts +1 -1
  113. package/dist/plugins/routing.d.ts.map +1 -1
  114. package/dist/routing/index.js +2 -2
  115. package/dist/rsc-runtime/dev-reference-cache.d.ts +47 -0
  116. package/dist/rsc-runtime/dev-reference-cache.d.ts.map +1 -0
  117. package/dist/rsc-runtime/rsc.d.ts +0 -15
  118. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  119. package/dist/rsc-runtime/ssr.d.ts +0 -11
  120. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  121. package/dist/schema-bridge.d.ts +28 -19
  122. package/dist/schema-bridge.d.ts.map +1 -1
  123. package/dist/search-params/define.d.ts +1 -1
  124. package/dist/search-params/define.d.ts.map +1 -1
  125. package/dist/search-params/index.js +7 -8
  126. package/dist/search-params/index.js.map +1 -1
  127. package/dist/search-params/wrappers.d.ts +3 -3
  128. package/dist/server/abort-scope.d.ts +27 -0
  129. package/dist/server/abort-scope.d.ts.map +1 -0
  130. package/dist/server/flight-source-node.d.ts.map +1 -1
  131. package/dist/server/index.js +2 -2
  132. package/dist/server/instrumentation.d.ts +2 -1
  133. package/dist/server/instrumentation.d.ts.map +1 -1
  134. package/dist/server/internal.d.ts +1 -1
  135. package/dist/server/internal.d.ts.map +1 -1
  136. package/dist/server/internal.js +350 -151
  137. package/dist/server/internal.js.map +1 -1
  138. package/dist/server/logger.d.ts +9 -0
  139. package/dist/server/logger.d.ts.map +1 -1
  140. package/dist/server/pipeline-helpers.d.ts.map +1 -1
  141. package/dist/server/pipeline.d.ts +10 -7
  142. package/dist/server/pipeline.d.ts.map +1 -1
  143. package/dist/server/prebuilt/cache-key.d.ts +26 -0
  144. package/dist/server/prebuilt/cache-key.d.ts.map +1 -1
  145. package/dist/server/prebuilt/capture-render.d.ts +9 -4
  146. package/dist/server/prebuilt/capture-render.d.ts.map +1 -1
  147. package/dist/server/prebuilt/capture-routes.d.ts +1 -1
  148. package/dist/server/prebuilt/dev-store.d.ts +103 -0
  149. package/dist/server/prebuilt/dev-store.d.ts.map +1 -0
  150. package/dist/server/prebuilt/overlay.d.ts +14 -3
  151. package/dist/server/prebuilt/overlay.d.ts.map +1 -1
  152. package/dist/server/prebuilt/payload-source.d.ts +8 -0
  153. package/dist/server/prebuilt/payload-source.d.ts.map +1 -1
  154. package/dist/server/prebuilt/slots.d.ts +5 -6
  155. package/dist/server/prebuilt/slots.d.ts.map +1 -1
  156. package/dist/server/prebuilt-builder.d.ts.map +1 -1
  157. package/dist/server/prebuilt-runtime.d.ts +5 -10
  158. package/dist/server/prebuilt-runtime.d.ts.map +1 -1
  159. package/dist/server/render-timeout.d.ts.map +1 -1
  160. package/dist/server/rsc-entry/action-dispatcher.d.ts.map +1 -1
  161. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  162. package/dist/server/ssr-render.d.ts.map +1 -1
  163. package/docs/api/32-api-cache.mdx +2 -0
  164. package/docs/api/33-api-search-params.mdx +3 -1
  165. package/docs/learn/06-typed-params.mdx +2 -2
  166. package/docs/learn/10-caching.mdx +12 -0
  167. package/docs/learn/11-middleware.mdx +2 -0
  168. package/package.json +1 -1
  169. package/src/cache/cache-api.ts +7 -1
  170. package/src/cache/guarded-read.ts +44 -0
  171. package/src/cache/handler-store.ts +38 -1
  172. package/src/cache/invalidation-epoch.ts +18 -6
  173. package/src/cache/timber-cache.ts +9 -3
  174. package/src/cdn/purge-store.ts +29 -1
  175. package/src/client/browser-entry/action-dispatch.ts +5 -5
  176. package/src/client/browser-entry/router-init.ts +2 -4
  177. package/src/client/global-context.ts +42 -14
  178. package/src/client/link.tsx +14 -18
  179. package/src/client/navigation-context.ts +4 -11
  180. package/src/client/navigation-transition.ts +86 -33
  181. package/src/client/params-context.ts +5 -17
  182. package/src/client/router-effects.ts +70 -45
  183. package/src/client/router-lifecycle.ts +1 -1
  184. package/src/client/router-pipeline.ts +52 -65
  185. package/src/client/router-types.ts +11 -31
  186. package/src/client/router.ts +98 -104
  187. package/src/client/segment-update-context.ts +1 -1
  188. package/src/client/slot-content-cache-context.ts +1 -1
  189. package/src/client/slot-context.ts +6 -17
  190. package/src/dev-tools/logs.ts +76 -50
  191. package/src/plugins/dev-server.ts +58 -9
  192. package/src/plugins/dev-store-clear.ts +47 -0
  193. package/src/plugins/entries.ts +6 -0
  194. package/src/plugins/orphaned-modules.ts +78 -0
  195. package/src/plugins/prebuilt.ts +17 -17
  196. package/src/plugins/prerender-sugar.ts +38 -6
  197. package/src/plugins/routing.ts +23 -1
  198. package/src/rsc-runtime/dev-reference-cache.ts +115 -0
  199. package/src/rsc-runtime/rsc.ts +10 -0
  200. package/src/rsc-runtime/ssr.ts +10 -0
  201. package/src/rsc-runtime/vendor-types.d.ts +8 -0
  202. package/src/schema-bridge.ts +93 -38
  203. package/src/search-params/define.ts +5 -6
  204. package/src/search-params/wrappers.ts +3 -3
  205. package/src/server/abort-scope.ts +49 -0
  206. package/src/server/action-handler.ts +18 -2
  207. package/src/server/flight-source-node.ts +5 -4
  208. package/src/server/instrumentation.ts +32 -8
  209. package/src/server/internal.ts +1 -6
  210. package/src/server/logger.ts +9 -0
  211. package/src/server/pipeline-helpers.ts +5 -3
  212. package/src/server/pipeline.ts +31 -20
  213. package/src/server/prebuilt/cache-key.ts +41 -0
  214. package/src/server/prebuilt/capture-render.ts +10 -6
  215. package/src/server/prebuilt/capture-routes.ts +1 -1
  216. package/src/server/prebuilt/dev-store.ts +173 -0
  217. package/src/server/prebuilt/overlay.ts +21 -5
  218. package/src/server/prebuilt/payload-source.ts +19 -0
  219. package/src/server/prebuilt/slots.ts +5 -6
  220. package/src/server/prebuilt-builder.ts +3 -2
  221. package/src/server/prebuilt-runtime.ts +194 -177
  222. package/src/server/render-timeout.ts +12 -17
  223. package/src/server/rsc-entry/action-dispatcher.ts +3 -1
  224. package/src/server/rsc-entry/index.ts +47 -13
  225. package/src/server/ssr-render.ts +9 -11
  226. package/dist/_chunks/cache-api-LA3sBpUS.js.map +0 -1
  227. package/dist/_chunks/chains-CDK1AWZQ.js +0 -1
  228. package/dist/_chunks/dev-server-DkytOEG2.js +0 -1
  229. package/dist/_chunks/dev-server-DnODXuNM.js.map +0 -1
  230. package/dist/_chunks/error-boundary-xxxLtXt6.js.map +0 -1
  231. package/dist/_chunks/flight-source-node-0dE-t3kq.js.map +0 -1
  232. package/dist/_chunks/node-response-Dibufw_b.js.map +0 -1
  233. package/dist/_chunks/purge-store-Byr8XOjU.js.map +0 -1
  234. package/dist/_chunks/render-timeout-DOf_BBcO.js.map +0 -1
  235. package/dist/_chunks/schema-bridge-C83xa9lT.js.map +0 -1
  236. package/dist/_chunks/segment-context-xtPUGfdq.js.map +0 -1
@@ -0,0 +1,283 @@
1
+ //#region src/cache/handler-store.ts
2
+ var handler = null;
3
+ var explicitlyConfigured = false;
4
+ /** Replace the active cache handler. */
5
+ function setCacheHandler(h) {
6
+ handler = h;
7
+ explicitlyConfigured = true;
8
+ }
9
+ /** Whether the handler was explicitly configured (vs the default in-memory fallback). */
10
+ function isCacheHandlerConfigured() {
11
+ return explicitlyConfigured;
12
+ }
13
+ /**
14
+ * Get the active cache handler. Creates a default MemoryCacheHandler on
15
+ * first access if none has been set via setCacheHandler().
16
+ */
17
+ function getCacheHandler() {
18
+ if (!handler) handler = createDefaultHandler();
19
+ return handler;
20
+ }
21
+ function createDefaultHandler() {
22
+ const store = /* @__PURE__ */ new Map();
23
+ const maxEntries = 1e3;
24
+ return {
25
+ async get(key) {
26
+ const entry = store.get(key);
27
+ if (!entry) return null;
28
+ store.delete(key);
29
+ store.set(key, entry);
30
+ const stale = Date.now() > entry.expiresAt;
31
+ return {
32
+ value: entry.value,
33
+ stale
34
+ };
35
+ },
36
+ async set(key, value, opts) {
37
+ if (store.has(key)) store.delete(key);
38
+ while (store.size >= maxEntries) {
39
+ const oldest = store.keys().next().value;
40
+ if (oldest !== void 0) store.delete(oldest);
41
+ else break;
42
+ }
43
+ store.set(key, {
44
+ value,
45
+ expiresAt: Date.now() + opts.ttl * 1e3,
46
+ tags: opts.tags
47
+ });
48
+ },
49
+ async invalidate(opts) {
50
+ if (opts.key) store.delete(opts.key);
51
+ if (opts.tag) {
52
+ for (const [key, entry] of store) if (entry.tags.includes(opts.tag)) store.delete(key);
53
+ }
54
+ }
55
+ };
56
+ }
57
+ //#endregion
58
+ //#region src/cache/invalidation-epoch.ts
59
+ /**
60
+ * Per-process invalidation epoch tracking for timber.cache (TIM-1028).
61
+ *
62
+ * handler.set for a cache miss runs after `fn()` resolves. An explicit
63
+ * `cache.invalidate({ tag })` / `revalidateTag` that lands while fn is in
64
+ * flight would otherwise be silently undone — the just-invalidated value
65
+ * re-stored as fresh for the full TTL, resurrecting pre-mutation data.
66
+ *
67
+ * Every invalidation bumps a monotonic epoch and records it against the
68
+ * invalidated key/tag. Before storing a result, the cache wrapper checks
69
+ * whether its key or any of its tags were invalidated after fn started and
70
+ * skips the write if so. Skipping is always safe: the only cost is one
71
+ * extra cache miss on the next call.
72
+ *
73
+ * Scope: per-process, like the singleflight map. An invalidation issued by
74
+ * another instance against a shared handler (Redis/KV) during fn flight is
75
+ * not observable here — closing that window fully would require store-level
76
+ * versioning, which no CacheHandler backend offers.
77
+ */
78
+ var epoch = 0;
79
+ /**
80
+ * Last-invalidated epoch per `key:<k>` / `tag:<t>` entry. Insertion order is
81
+ * epoch order (entries are re-inserted on update), so the oldest entry is
82
+ * always first — pruning evicts lowest epochs.
83
+ */
84
+ var lastInvalidated = /* @__PURE__ */ new Map();
85
+ /**
86
+ * Bound on tracked entries so high-cardinality tag invalidation (e.g.
87
+ * per-user tags) cannot grow this map without limit.
88
+ */
89
+ var MAX_TRACKED_ENTRIES = 1e4;
90
+ /**
91
+ * Every execution that started at or before this epoch counts as
92
+ * invalidated. Raised by eviction (history was truncated, so we can no
93
+ * longer prove an execution wasn't invalidated) and by
94
+ * `recordInvalidationOfAll()`.
95
+ */
96
+ var invalidatedEpochFloor = 0;
97
+ /** The current epoch. Capture before running fn(), pass to wasInvalidatedSince. */
98
+ function currentInvalidationEpoch() {
99
+ return epoch;
100
+ }
101
+ /**
102
+ * Record an invalidation. Call BEFORE handler.invalidate() so an execution
103
+ * whose set-check races the invalidation errs toward skipping the write.
104
+ */
105
+ function recordInvalidation(opts) {
106
+ epoch++;
107
+ if (opts.key) track(`key:${opts.key}`);
108
+ if (opts.tag) track(`tag:${opts.tag}`);
109
+ }
110
+ /**
111
+ * Record an invalidation of every key and tag at once. The dev server
112
+ * calls this on a source change (server/prebuilt/dev-store.ts): any cached
113
+ * render in flight may have loaded the pre-change code, so none of them may
114
+ * store, and a caller arriving after the change must not join their flight.
115
+ */
116
+ function recordInvalidationOfAll() {
117
+ epoch++;
118
+ invalidatedEpochFloor = epoch;
119
+ }
120
+ function track(entry) {
121
+ lastInvalidated.delete(entry);
122
+ lastInvalidated.set(entry, epoch);
123
+ while (lastInvalidated.size > MAX_TRACKED_ENTRIES) {
124
+ const oldest = lastInvalidated.entries().next().value;
125
+ if (oldest === void 0) break;
126
+ invalidatedEpochFloor = Math.max(invalidatedEpochFloor, oldest[1]);
127
+ lastInvalidated.delete(oldest[0]);
128
+ }
129
+ }
130
+ /**
131
+ * Whether the key or any tag was invalidated after `startEpoch` (the epoch
132
+ * captured when fn started executing).
133
+ */
134
+ function wasInvalidatedSince(startEpoch, key, tags) {
135
+ return lastInvalidationEpochFor(key, tags) > startEpoch;
136
+ }
137
+ /**
138
+ * The highest epoch at which the key or any of the tags was invalidated
139
+ * (0 if never). Used to scope the singleflight key: callers arriving after
140
+ * an invalidation must not coalesce onto a flight that started before it —
141
+ * they would receive the pre-invalidation result the invalidation was
142
+ * issued to discard.
143
+ */
144
+ function lastInvalidationEpochFor(key, tags) {
145
+ let last = invalidatedEpochFloor;
146
+ const keyEpoch = lastInvalidated.get(`key:${key}`);
147
+ if (keyEpoch !== void 0 && keyEpoch > last) last = keyEpoch;
148
+ for (const tag of tags) {
149
+ const tagEpoch = lastInvalidated.get(`tag:${tag}`);
150
+ if (tagEpoch !== void 0 && tagEpoch > last) last = tagEpoch;
151
+ }
152
+ return last;
153
+ }
154
+ //#endregion
155
+ //#region src/server/prebuilt/dev-store.ts
156
+ /**
157
+ * Dev-mode store for cache.component output (TIM-1588, design/44 §Dev Mode).
158
+ *
159
+ * In production a `prerender` entry is captured at build time and frozen
160
+ * until the next deploy. Dev has no build step, so this in-memory store
161
+ * stands in for the build artifact: a prerender-tier render is captured on
162
+ * its first request (under the synthetic build store, so request-context
163
+ * reads fail exactly as `pnpm build` would) and served from here after
164
+ * that. Runtime-tier entries (`ttl`/`tags`) keep using the cache-handler
165
+ * overlay; in dev their keys carry this store's namespace (`overlayKey`).
166
+ *
167
+ * Invalidation is deliberately coarse: ANY dev-server watcher event clears
168
+ * everything. The dev-server plugin sends `PREBUILT_DEV_CLEAR_EVENT` to the
169
+ * RSC environment and the RSC entry calls `clearDevPrebuiltStore()`. There
170
+ * is no per-component dependency tracking — the module graph misses files
171
+ * read with `fs`, and one re-render per save is what dev used to pay on
172
+ * every request. A clear does three things:
173
+ *
174
+ * 1. drops every seed;
175
+ * 2. bumps the generation, which namespaces dev overlay keys, so
176
+ * runtime-tier entries stored before the save become unreachable;
177
+ * 3. records an invalidation of everything (`recordInvalidationOfAll`),
178
+ * so a capture already in flight — which may have loaded the
179
+ * pre-save code — is not stored, and a request arriving after the
180
+ * save does not join that flight (the TIM-1028 guard every capture
181
+ * path already runs).
182
+ *
183
+ * Inactive outside dev: production never enables it. Dev enables it only
184
+ * when HMR is on — with `server.hmr: false` Vite delivers no watcher events
185
+ * to plugins and nothing would clear the store, so dev bypasses caching
186
+ * entirely instead (`DevPrebuiltStoreMode`).
187
+ */
188
+ /** Custom HMR event the dev-server plugin sends to the RSC environment. */
189
+ var PREBUILT_DEV_CLEAR_EVENT = "timber:prebuilt-dev-clear";
190
+ var mode = "off";
191
+ var generation = 0;
192
+ var seeds = /* @__PURE__ */ new Map();
193
+ /**
194
+ * Distinguishes this process's overlay keys from a previous dev session's,
195
+ * in case the configured cache handler outlives the process (Redis in dev).
196
+ * Created on first use, never at module load: production imports this
197
+ * module too, and Workers reject random-value generation in global scope.
198
+ * Global `crypto`, not node:crypto, because dev may run the RSC environment
199
+ * in workerd.
200
+ */
201
+ var processToken = null;
202
+ function seedKey(componentId, cacheKey) {
203
+ return `${componentId}:${cacheKey}`;
204
+ }
205
+ function isDevPrebuiltStoreActive() {
206
+ return mode === "active";
207
+ }
208
+ /** Dev without HMR: every cache.component wrapper renders live. */
209
+ function isDevPrebuiltCacheBypassed() {
210
+ return mode === "bypass";
211
+ }
212
+ /**
213
+ * Namespace for overlay keys while the dev store is active, in place of the
214
+ * deployment ID (which is null in dev). Changes on every clear. Null when
215
+ * inactive.
216
+ */
217
+ function devOverlayNamespace() {
218
+ if (mode !== "active") return null;
219
+ processToken ??= crypto.randomUUID().slice(0, 8);
220
+ return `dev-${processToken}-${generation}`;
221
+ }
222
+ /**
223
+ * The key a `cache.data` entry is stored under: the logical key, prefixed in
224
+ * dev with the namespace above. So a save makes every data entry stored
225
+ * before it unreachable, whatever the handler. A data function's ID comes
226
+ * from its call site, so editing a helper it calls, or a file it reads,
227
+ * would otherwise keep serving the old result to every component captured
228
+ * after the save. Invalidation epochs and singleflight stay on the logical
229
+ * key; only the handler sees the prefix.
230
+ */
231
+ function devDataCacheKey(key) {
232
+ const namespace = devOverlayNamespace();
233
+ return namespace === null ? key : `${namespace}\u0000${key}`;
234
+ }
235
+ function getDevSeed(componentId, cacheKey) {
236
+ return seeds.get(seedKey(componentId, cacheKey));
237
+ }
238
+ /**
239
+ * Store a captured seed. The caller has already checked that no clear (or
240
+ * tag invalidation) happened while it was capturing.
241
+ */
242
+ function setDevSeed(componentId, cacheKey, seed) {
243
+ seeds.set(seedKey(componentId, cacheKey), seed);
244
+ }
245
+ /** Drop everything — called on every dev-server watcher event. */
246
+ function clearDevPrebuiltStore() {
247
+ seeds.clear();
248
+ generation++;
249
+ recordInvalidationOfAll();
250
+ }
251
+ /**
252
+ * A hard reload: discard one entry — its seed and its overlay record — so
253
+ * the request renders it again. Recorded as an invalidation of its key
254
+ * first, so a capture of it already in flight (which may have read the old
255
+ * external data) neither stores nor is joined by this request.
256
+ */
257
+ async function discardDevEntry(componentId, cacheKey, overlayKey) {
258
+ recordInvalidation({ key: overlayKey });
259
+ seeds.delete(seedKey(componentId, cacheKey));
260
+ await getCacheHandler().invalidate({ key: overlayKey });
261
+ }
262
+ /**
263
+ * `revalidateTag` in dev: drop the seeds carrying the tag. This is the dev
264
+ * counterpart of writing a tombstone over a build seed (design/45 §ISR
265
+ * mechanics) — the next request misses and captures again.
266
+ */
267
+ function invalidateDevSeedsByTag(tag) {
268
+ for (const [key, seed] of seeds) if (seed.tags.includes(tag)) seeds.delete(key);
269
+ }
270
+ /**
271
+ * Whether the request asks to skip caches — a browser hard reload, or any
272
+ * request while DevTools "Disable cache" is on, sends `Cache-Control:
273
+ * no-cache`. Dev only: the escape hatch for components that read external
274
+ * data (a CMS, a database) while it is being edited. Production never
275
+ * honors it — a client must not be able to force cache.component re-renders.
276
+ */
277
+ function isHardReload(headers) {
278
+ return /(?:^|,)\s*no-cache\s*(?:,|$)/i.test(headers.get("cache-control") ?? "");
279
+ }
280
+ //#endregion
281
+ export { isCacheHandlerConfigured as _, discardDevEntry as a, isDevPrebuiltCacheBypassed as c, setDevSeed as d, currentInvalidationEpoch as f, getCacheHandler as g, wasInvalidatedSince as h, devOverlayNamespace as i, isDevPrebuiltStoreActive as l, recordInvalidation as m, clearDevPrebuiltStore as n, getDevSeed as o, lastInvalidationEpochFor as p, devDataCacheKey as r, invalidateDevSeedsByTag as s, PREBUILT_DEV_CLEAR_EVENT as t, isHardReload as u, setCacheHandler as v };
282
+
283
+ //# sourceMappingURL=dev-store-BOa304m_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-store-BOa304m_.js","names":[],"sources":["../../src/cache/handler-store.ts","../../src/cache/invalidation-epoch.ts","../../src/server/prebuilt/dev-store.ts"],"sourcesContent":["/**\n * Module-level cache handler singleton.\n *\n * Lazily initialized to MemoryCacheHandler on first access. The framework\n * replaces this at boot from timber.config.ts via setCacheHandler().\n *\n * This module avoids importing from ./index to prevent circular dependencies.\n */\n\n// Inline the interface to avoid circular import with index.ts\ninterface CacheHandlerLike {\n get(key: string): Promise<{ value: unknown; stale: boolean } | null>;\n set(key: string, value: unknown, opts: { ttl: number; tags: string[] }): Promise<void>;\n invalidate(opts: { key?: string; tag?: string }): Promise<void>;\n}\n\nlet handler: CacheHandlerLike | null = null;\n\nlet explicitlyConfigured = false;\n\n/** Whether `handler` came from timber.cache.ts (applyConfiguredCacheHandler). */\nlet fromCacheConfig = false;\n\n/** The handler last installed by a direct setCacheHandler() call, if any. */\nlet directHandler: CacheHandlerLike | null = null;\n\n/** Replace the active cache handler. */\nexport function setCacheHandler(h: CacheHandlerLike): void {\n handler = h;\n explicitlyConfigured = true;\n fromCacheConfig = false;\n directHandler = h;\n}\n\n/**\n * Apply the handler timber.cache.ts exports, or `null` when it exports none.\n * Called on every run of the RSC entry. In dev the entry re-runs after an\n * edit while this module keeps its state (design/21 §HMR Wiring), so a\n * handler removed from timber.cache.ts must be dropped here, not kept\n * serving. A handler installed by a direct setCacheHandler() call (from\n * register(), say) is left in place when the file exports none, and comes\n * back when a configured handler that replaced it is removed.\n */\nexport function applyConfiguredCacheHandler(h: CacheHandlerLike | null): void {\n if (h) {\n handler = h;\n explicitlyConfigured = true;\n fromCacheConfig = true;\n } else if (fromCacheConfig) {\n handler = directHandler;\n explicitlyConfigured = directHandler !== null;\n fromCacheConfig = false;\n }\n}\n\n/** @internal — reset for tests only. */\nexport function _resetCacheHandler(): void {\n handler = null;\n explicitlyConfigured = false;\n fromCacheConfig = false;\n directHandler = null;\n}\n\n/** Whether the handler was explicitly configured (vs the default in-memory fallback). */\nexport function isCacheHandlerConfigured(): boolean {\n return explicitlyConfigured;\n}\n\n/**\n * Get the active cache handler. Creates a default MemoryCacheHandler on\n * first access if none has been set via setCacheHandler().\n */\nexport function getCacheHandler(): CacheHandlerLike {\n if (!handler) {\n // Inline a minimal LRU cache to avoid circular dep with index.ts.\n // In production, the framework always calls setCacheHandler() at boot.\n handler = createDefaultHandler();\n }\n return handler;\n}\n\nfunction createDefaultHandler(): CacheHandlerLike {\n const store = new Map<string, { value: unknown; expiresAt: number; tags: string[] }>();\n const maxEntries = 1000;\n\n return {\n async get(key) {\n const entry = store.get(key);\n if (!entry) return null;\n store.delete(key);\n store.set(key, entry);\n const stale = Date.now() > entry.expiresAt;\n return { value: entry.value, stale };\n },\n async set(key, value, opts) {\n if (store.has(key)) store.delete(key);\n while (store.size >= maxEntries) {\n const oldest = store.keys().next().value;\n if (oldest !== undefined) store.delete(oldest);\n else break;\n }\n store.set(key, { value, expiresAt: Date.now() + opts.ttl * 1000, tags: opts.tags });\n },\n async invalidate(opts) {\n if (opts.key) store.delete(opts.key);\n if (opts.tag) {\n for (const [key, entry] of store) {\n if (entry.tags.includes(opts.tag)) store.delete(key);\n }\n }\n },\n };\n}\n","/**\n * Per-process invalidation epoch tracking for timber.cache (TIM-1028).\n *\n * handler.set for a cache miss runs after `fn()` resolves. An explicit\n * `cache.invalidate({ tag })` / `revalidateTag` that lands while fn is in\n * flight would otherwise be silently undone — the just-invalidated value\n * re-stored as fresh for the full TTL, resurrecting pre-mutation data.\n *\n * Every invalidation bumps a monotonic epoch and records it against the\n * invalidated key/tag. Before storing a result, the cache wrapper checks\n * whether its key or any of its tags were invalidated after fn started and\n * skips the write if so. Skipping is always safe: the only cost is one\n * extra cache miss on the next call.\n *\n * Scope: per-process, like the singleflight map. An invalidation issued by\n * another instance against a shared handler (Redis/KV) during fn flight is\n * not observable here — closing that window fully would require store-level\n * versioning, which no CacheHandler backend offers.\n */\n\nlet epoch = 0;\n\n/**\n * Last-invalidated epoch per `key:<k>` / `tag:<t>` entry. Insertion order is\n * epoch order (entries are re-inserted on update), so the oldest entry is\n * always first — pruning evicts lowest epochs.\n */\nconst lastInvalidated = new Map<string, number>();\n\n/**\n * Bound on tracked entries so high-cardinality tag invalidation (e.g.\n * per-user tags) cannot grow this map without limit.\n */\nconst MAX_TRACKED_ENTRIES = 10_000;\n\n/**\n * Every execution that started at or before this epoch counts as\n * invalidated. Raised by eviction (history was truncated, so we can no\n * longer prove an execution wasn't invalidated) and by\n * `recordInvalidationOfAll()`.\n */\nlet invalidatedEpochFloor = 0;\n\n/** The current epoch. Capture before running fn(), pass to wasInvalidatedSince. */\nexport function currentInvalidationEpoch(): number {\n return epoch;\n}\n\n/**\n * Record an invalidation. Call BEFORE handler.invalidate() so an execution\n * whose set-check races the invalidation errs toward skipping the write.\n */\nexport function recordInvalidation(opts: { key?: string; tag?: string }): void {\n epoch++;\n if (opts.key) track(`key:${opts.key}`);\n if (opts.tag) track(`tag:${opts.tag}`);\n}\n\n/**\n * Record an invalidation of every key and tag at once. The dev server\n * calls this on a source change (server/prebuilt/dev-store.ts): any cached\n * render in flight may have loaded the pre-change code, so none of them may\n * store, and a caller arriving after the change must not join their flight.\n */\nexport function recordInvalidationOfAll(): void {\n epoch++;\n invalidatedEpochFloor = epoch;\n}\n\nfunction track(entry: string): void {\n lastInvalidated.delete(entry);\n lastInvalidated.set(entry, epoch);\n while (lastInvalidated.size > MAX_TRACKED_ENTRIES) {\n const oldest = lastInvalidated.entries().next().value;\n if (oldest === undefined) break;\n invalidatedEpochFloor = Math.max(invalidatedEpochFloor, oldest[1]);\n lastInvalidated.delete(oldest[0]);\n }\n}\n\n/**\n * Whether the key or any tag was invalidated after `startEpoch` (the epoch\n * captured when fn started executing).\n */\nexport function wasInvalidatedSince(startEpoch: number, key: string, tags: string[]): boolean {\n return lastInvalidationEpochFor(key, tags) > startEpoch;\n}\n\n/**\n * The highest epoch at which the key or any of the tags was invalidated\n * (0 if never). Used to scope the singleflight key: callers arriving after\n * an invalidation must not coalesce onto a flight that started before it —\n * they would receive the pre-invalidation result the invalidation was\n * issued to discard.\n */\nexport function lastInvalidationEpochFor(key: string, tags: string[]): number {\n let last = invalidatedEpochFloor;\n const keyEpoch = lastInvalidated.get(`key:${key}`);\n if (keyEpoch !== undefined && keyEpoch > last) last = keyEpoch;\n for (const tag of tags) {\n const tagEpoch = lastInvalidated.get(`tag:${tag}`);\n if (tagEpoch !== undefined && tagEpoch > last) last = tagEpoch;\n }\n return last;\n}\n","/**\n * Dev-mode store for cache.component output (TIM-1588, design/44 §Dev Mode).\n *\n * In production a `prerender` entry is captured at build time and frozen\n * until the next deploy. Dev has no build step, so this in-memory store\n * stands in for the build artifact: a prerender-tier render is captured on\n * its first request (under the synthetic build store, so request-context\n * reads fail exactly as `pnpm build` would) and served from here after\n * that. Runtime-tier entries (`ttl`/`tags`) keep using the cache-handler\n * overlay; in dev their keys carry this store's namespace (`overlayKey`).\n *\n * Invalidation is deliberately coarse: ANY dev-server watcher event clears\n * everything. The dev-server plugin sends `PREBUILT_DEV_CLEAR_EVENT` to the\n * RSC environment and the RSC entry calls `clearDevPrebuiltStore()`. There\n * is no per-component dependency tracking — the module graph misses files\n * read with `fs`, and one re-render per save is what dev used to pay on\n * every request. A clear does three things:\n *\n * 1. drops every seed;\n * 2. bumps the generation, which namespaces dev overlay keys, so\n * runtime-tier entries stored before the save become unreachable;\n * 3. records an invalidation of everything (`recordInvalidationOfAll`),\n * so a capture already in flight — which may have loaded the\n * pre-save code — is not stored, and a request arriving after the\n * save does not join that flight (the TIM-1028 guard every capture\n * path already runs).\n *\n * Inactive outside dev: production never enables it. Dev enables it only\n * when HMR is on — with `server.hmr: false` Vite delivers no watcher events\n * to plugins and nothing would clear the store, so dev bypasses caching\n * entirely instead (`DevPrebuiltStoreMode`).\n */\n\nimport { getCacheHandler } from '../../cache/handler-store.ts';\nimport { recordInvalidation, recordInvalidationOfAll } from '../../cache/invalidation-epoch.ts';\n\n/** Custom HMR event the dev-server plugin sends to the RSC environment. */\nexport const PREBUILT_DEV_CLEAR_EVENT = 'timber:prebuilt-dev-clear';\n\n/** One captured prerender-tier entry — the dev counterpart of a `.flight` seed. */\nexport interface DevSeed {\n bytes: Uint8Array;\n /** Resolved tags, so `revalidateTag` can drop an ISR seed. */\n tags: string[];\n /** Capture time; stands in for the manifest's buildTimestamp. */\n capturedAt: number;\n}\n\n/**\n * - `off`: production (and the default). Wrappers use the build artifact and\n * the overlay.\n * - `active`: dev with HMR. The dev store stands in for the build artifact.\n * - `bypass`: dev without HMR (`server.hmr: false`). No watcher event would\n * ever reach the store, so nothing is cached at all: every wrapper renders\n * live, runtime-tier ones included (the overlay would otherwise hold\n * entries a save never clears).\n */\nexport type DevPrebuiltStoreMode = 'off' | 'active' | 'bypass';\n\nlet mode: DevPrebuiltStoreMode = 'off';\nlet generation = 0;\nconst seeds = new Map<string, DevSeed>();\n\n/**\n * Distinguishes this process's overlay keys from a previous dev session's,\n * in case the configured cache handler outlives the process (Redis in dev).\n * Created on first use, never at module load: production imports this\n * module too, and Workers reject random-value generation in global scope.\n * Global `crypto`, not node:crypto, because dev may run the RSC environment\n * in workerd.\n */\nlet processToken: string | null = null;\n\nfunction seedKey(componentId: string, cacheKey: string): string {\n return `${componentId}:${cacheKey}`;\n}\n\n/** Set by the RSC entry in dev (and by tests). The store starts empty either way. */\nexport function setDevPrebuiltStoreMode(next: DevPrebuiltStoreMode): void {\n mode = next;\n seeds.clear();\n}\n\nexport function isDevPrebuiltStoreActive(): boolean {\n return mode === 'active';\n}\n\n/** Dev without HMR: every cache.component wrapper renders live. */\nexport function isDevPrebuiltCacheBypassed(): boolean {\n return mode === 'bypass';\n}\n\n/**\n * Namespace for overlay keys while the dev store is active, in place of the\n * deployment ID (which is null in dev). Changes on every clear. Null when\n * inactive.\n */\nexport function devOverlayNamespace(): string | null {\n if (mode !== 'active') return null;\n processToken ??= crypto.randomUUID().slice(0, 8);\n return `dev-${processToken}-${generation}`;\n}\n\n/**\n * The key a `cache.data` entry is stored under: the logical key, prefixed in\n * dev with the namespace above. So a save makes every data entry stored\n * before it unreachable, whatever the handler. A data function's ID comes\n * from its call site, so editing a helper it calls, or a file it reads,\n * would otherwise keep serving the old result to every component captured\n * after the save. Invalidation epochs and singleflight stay on the logical\n * key; only the handler sees the prefix.\n */\nexport function devDataCacheKey(key: string): string {\n const namespace = devOverlayNamespace();\n return namespace === null ? key : `${namespace}\\u0000${key}`;\n}\n\nexport function getDevSeed(componentId: string, cacheKey: string): DevSeed | undefined {\n return seeds.get(seedKey(componentId, cacheKey));\n}\n\n/**\n * Store a captured seed. The caller has already checked that no clear (or\n * tag invalidation) happened while it was capturing.\n */\nexport function setDevSeed(componentId: string, cacheKey: string, seed: DevSeed): void {\n seeds.set(seedKey(componentId, cacheKey), seed);\n}\n\n/** Drop everything — called on every dev-server watcher event. */\nexport function clearDevPrebuiltStore(): void {\n seeds.clear();\n generation++;\n recordInvalidationOfAll();\n}\n\n/**\n * A hard reload: discard one entry — its seed and its overlay record — so\n * the request renders it again. Recorded as an invalidation of its key\n * first, so a capture of it already in flight (which may have read the old\n * external data) neither stores nor is joined by this request.\n */\nexport async function discardDevEntry(\n componentId: string,\n cacheKey: string,\n overlayKey: string\n): Promise<void> {\n recordInvalidation({ key: overlayKey });\n seeds.delete(seedKey(componentId, cacheKey));\n await getCacheHandler().invalidate({ key: overlayKey });\n}\n\n/**\n * `revalidateTag` in dev: drop the seeds carrying the tag. This is the dev\n * counterpart of writing a tombstone over a build seed (design/45 §ISR\n * mechanics) — the next request misses and captures again.\n */\nexport function invalidateDevSeedsByTag(tag: string): void {\n for (const [key, seed] of seeds) {\n if (seed.tags.includes(tag)) seeds.delete(key);\n }\n}\n\n/**\n * Whether the request asks to skip caches — a browser hard reload, or any\n * request while DevTools \"Disable cache\" is on, sends `Cache-Control:\n * no-cache`. Dev only: the escape hatch for components that read external\n * data (a CMS, a database) while it is being edited. Production never\n * honors it — a client must not be able to force cache.component re-renders.\n */\nexport function isHardReload(headers: Headers): boolean {\n return /(?:^|,)\\s*no-cache\\s*(?:,|$)/i.test(headers.get('cache-control') ?? '');\n}\n"],"mappings":"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"}
@@ -625,6 +625,35 @@ function markStaleFromError(error) {
625
625
  return true;
626
626
  }
627
627
  //#endregion
628
+ //#region src/client/navigation-transition.ts
629
+ /** The outcome of a render that ended without committing. */
630
+ function abandonedOutcome(owner) {
631
+ return owner.outcome === "superseded" ? "superseded" : "failed";
632
+ }
633
+ /**
634
+ * Create a fresh RenderOwner. Exported so tests that call
635
+ * `navigateTransition` directly can construct one without a router.
636
+ */
637
+ function createRenderOwner(kind) {
638
+ let resolveDisplaced;
639
+ const displaced = new Promise((r) => {
640
+ resolveDisplaced = r;
641
+ });
642
+ const owner = {
643
+ kind,
644
+ fetchAbort: new AbortController(),
645
+ handedOff: false,
646
+ outcome: null,
647
+ displaced,
648
+ settle(outcome) {
649
+ if (owner.outcome === null) owner.outcome = outcome;
650
+ else if (outcome === "superseded" && owner.outcome === "committed") owner.outcome = "superseded";
651
+ if (outcome !== "committed") resolveDisplaced();
652
+ }
653
+ };
654
+ return owner;
655
+ }
656
+ //#endregion
628
657
  //#region src/client/router-skew.ts
629
658
  /**
630
659
  * Router Skew Recording — turning a rejection into "this bundle is superseded".
@@ -728,23 +757,42 @@ function createSpaExits({ currentOwner, supersede }) {
728
757
  leaveSpaSuperseding
729
758
  };
730
759
  }
731
- function holdCommit(onCommit) {
732
- if (!onCommit) return {
733
- transition: void 0,
734
- settle: void 0
735
- };
736
- let settled = false;
737
- const settle = (outcome) => {
738
- if (settled) return;
739
- settled = true;
740
- onCommit(outcome);
741
- };
742
- return {
743
- transition: (outcome) => {
744
- if (outcome !== "failed") settle(outcome);
760
+ /**
761
+ * Run a navigation as a {@link NavigationHandle}. `run` is the navigation:
762
+ * its promise is the handle's decode, and it reports its renders' other
763
+ * endings into the {@link NavigationEndings} it is given.
764
+ *
765
+ * A navigation that ends without reporting — superseded, or failed, before
766
+ * any render — settles them as it ends: `committed` as `'failed'` if it
767
+ * rejected (an outcome already reported wins), and `handedOff` either way,
768
+ * so neither waits on a render that will not come.
769
+ */
770
+ function runAsHandle(run) {
771
+ let handOff;
772
+ const handedOff = new Promise((resolve) => handOff = resolve);
773
+ let settle;
774
+ const committed = new Promise((resolve) => settle = resolve);
775
+ const decoded = run({
776
+ track(render) {
777
+ render.handedOff.then(handOff);
778
+ render.committed.then((outcome) => {
779
+ if (outcome !== "failed") settle(outcome);
780
+ });
781
+ },
782
+ adopt(hop) {
783
+ hop.handedOff.then(handOff);
784
+ hop.committed.then(settle);
745
785
  },
746
786
  settle
747
- };
787
+ }).then(handOff, (error) => {
788
+ settle("failed");
789
+ handOff();
790
+ throw error;
791
+ });
792
+ return Object.assign(decoded, {
793
+ handedOff,
794
+ committed
795
+ });
748
796
  }
749
797
  /**
750
798
  * The URL a redirect hop navigates to. A redirect target without a fragment
@@ -780,16 +828,18 @@ function redirectHopUrl(redirectUrl, requestedUrl) {
780
828
  * {@link SpaExits.leaveSpaIfOwned}.
781
829
  */
782
830
  function createNavigationRecovery({ currentOwner, leaveSpaIfOwned, navigate }) {
783
- return async function recoverFromNavigationError(error, owner, url, fromUrl, hop) {
831
+ return async function recoverFromNavigationError(error, owner, url, fromUrl, hop, endings) {
784
832
  if (error instanceof RedirectError) {
785
833
  if (currentOwner() !== owner) {
786
- hop.onCommit?.("superseded");
834
+ endings.settle("superseded");
787
835
  return true;
788
836
  }
789
- await navigate(redirectHopUrl(error.redirectUrl, url), hop);
837
+ const redirected = navigate(redirectHopUrl(error.redirectUrl, url), hop);
838
+ endings.adopt(redirected);
839
+ await redirected;
790
840
  return true;
791
841
  }
792
- hop.onCommit?.("failed");
842
+ endings.settle(abandonedOutcome(owner));
793
843
  if (error instanceof ServerErrorResponse || error instanceof NonRscResponse || recordSkew(error)) {
794
844
  await leaveSpaIfOwned(owner, url, fromUrl);
795
845
  return true;
@@ -1052,6 +1102,6 @@ function statusMatches(boundaryStatus, errorStatus) {
1052
1102
  return boundaryStatus === errorStatus;
1053
1103
  }
1054
1104
  //#endregion
1055
- export { createSpaExits as a, isClientStale as c, readPayloadTree as d, readPublishedParams as f, createScrollEffects as i, NonRscResponse as l, TimberErrorBoundary as n, holdCommit as o, createNavigationRecovery as r, recordSkew as s, DenyAncestryContext as t, fetchRscPayload as u };
1105
+ export { createSpaExits as a, createRenderOwner as c, fetchRscPayload as d, readPayloadTree as f, createScrollEffects as i, isClientStale as l, TimberErrorBoundary as n, runAsHandle as o, readPublishedParams as p, createNavigationRecovery as r, recordSkew as s, DenyAncestryContext as t, NonRscResponse as u };
1056
1106
 
1057
- //# sourceMappingURL=error-boundary-xxxLtXt6.js.map
1107
+ //# sourceMappingURL=error-boundary-Bc8QPZuq.js.map