@rangojs/router 0.0.0-experimental.20 → 0.0.0-experimental.204030a9

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 (293) hide show
  1. package/AGENTS.md +4 -0
  2. package/README.md +242 -55
  3. package/dist/bin/rango.js +277 -99
  4. package/dist/vite/index.js +2929 -1132
  5. package/dist/vite/index.js.bak +5448 -0
  6. package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  7. package/package.json +68 -21
  8. package/skills/breadcrumbs/SKILL.md +252 -0
  9. package/skills/bundle-analysis/SKILL.md +159 -0
  10. package/skills/cache-guide/SKILL.md +243 -21
  11. package/skills/caching/SKILL.md +159 -10
  12. package/skills/composability/SKILL.md +27 -2
  13. package/skills/document-cache/SKILL.md +78 -55
  14. package/skills/handler-use/SKILL.md +364 -0
  15. package/skills/hooks/SKILL.md +262 -51
  16. package/skills/host-router/SKILL.md +243 -0
  17. package/skills/i18n/SKILL.md +276 -0
  18. package/skills/intercept/SKILL.md +46 -4
  19. package/skills/layout/SKILL.md +28 -7
  20. package/skills/links/SKILL.md +249 -17
  21. package/skills/loader/SKILL.md +291 -31
  22. package/skills/middleware/SKILL.md +49 -12
  23. package/skills/migrate-nextjs/SKILL.md +562 -0
  24. package/skills/migrate-react-router/SKILL.md +769 -0
  25. package/skills/mime-routes/SKILL.md +27 -0
  26. package/skills/observability/SKILL.md +137 -0
  27. package/skills/parallel/SKILL.md +197 -6
  28. package/skills/prerender/SKILL.md +125 -102
  29. package/skills/rango/SKILL.md +242 -23
  30. package/skills/react-compiler/SKILL.md +168 -0
  31. package/skills/response-routes/SKILL.md +66 -9
  32. package/skills/route/SKILL.md +91 -8
  33. package/skills/router-setup/SKILL.md +98 -8
  34. package/skills/server-actions/SKILL.md +751 -0
  35. package/skills/streams-and-websockets/SKILL.md +283 -0
  36. package/skills/testing/SKILL.md +511 -188
  37. package/skills/typesafety/SKILL.md +354 -50
  38. package/skills/use-cache/SKILL.md +34 -5
  39. package/skills/view-transitions/SKILL.md +294 -0
  40. package/src/__augment-tests__/augment.ts +81 -0
  41. package/src/__augment-tests__/augmented.check.ts +117 -0
  42. package/src/__internal.ts +92 -0
  43. package/src/browser/action-coordinator.ts +53 -36
  44. package/src/browser/app-shell.ts +52 -0
  45. package/src/browser/app-version.ts +14 -0
  46. package/src/browser/event-controller.ts +91 -70
  47. package/src/browser/history-state.ts +21 -0
  48. package/src/browser/index.ts +3 -3
  49. package/src/browser/link-interceptor.ts +4 -0
  50. package/src/browser/navigation-bridge.ts +183 -18
  51. package/src/browser/navigation-client.ts +187 -57
  52. package/src/browser/navigation-store.ts +75 -17
  53. package/src/browser/navigation-transaction.ts +21 -37
  54. package/src/browser/partial-update.ts +143 -40
  55. package/src/browser/prefetch/cache.ts +275 -28
  56. package/src/browser/prefetch/fetch.ts +191 -46
  57. package/src/browser/prefetch/policy.ts +6 -0
  58. package/src/browser/prefetch/queue.ts +123 -20
  59. package/src/browser/prefetch/resource-ready.ts +77 -0
  60. package/src/browser/rango-state.ts +53 -13
  61. package/src/browser/react/Link.tsx +98 -14
  62. package/src/browser/react/NavigationProvider.tsx +110 -33
  63. package/src/browser/react/context.ts +7 -2
  64. package/src/browser/react/filter-segment-order.ts +51 -7
  65. package/src/browser/react/index.ts +3 -0
  66. package/src/browser/react/location-state-shared.ts +175 -4
  67. package/src/browser/react/location-state.ts +39 -13
  68. package/src/browser/react/use-handle.ts +23 -64
  69. package/src/browser/react/use-navigation.ts +22 -2
  70. package/src/browser/react/use-params.ts +20 -8
  71. package/src/browser/react/use-reverse.ts +106 -0
  72. package/src/browser/react/use-router.ts +43 -10
  73. package/src/browser/react/use-segments.ts +11 -8
  74. package/src/browser/response-adapter.ts +25 -0
  75. package/src/browser/rsc-router.tsx +200 -75
  76. package/src/browser/scroll-restoration.ts +46 -39
  77. package/src/browser/segment-reconciler.ts +36 -9
  78. package/src/browser/segment-structure-assert.ts +2 -2
  79. package/src/browser/server-action-bridge.ts +31 -36
  80. package/src/browser/types.ts +81 -5
  81. package/src/build/collect-fallback-refs.ts +107 -0
  82. package/src/build/generate-manifest.ts +65 -40
  83. package/src/build/generate-route-types.ts +5 -0
  84. package/src/build/index.ts +2 -0
  85. package/src/build/route-trie.ts +69 -26
  86. package/src/build/route-types/codegen.ts +4 -4
  87. package/src/build/route-types/include-resolution.ts +9 -2
  88. package/src/build/route-types/per-module-writer.ts +7 -4
  89. package/src/build/route-types/router-processing.ts +278 -88
  90. package/src/build/route-types/scan-filter.ts +9 -2
  91. package/src/build/route-types/source-scan.ts +118 -0
  92. package/src/build/runtime-discovery.ts +9 -20
  93. package/src/cache/cache-runtime.ts +15 -11
  94. package/src/cache/cache-scope.ts +76 -49
  95. package/src/cache/cf/cf-cache-store.ts +501 -18
  96. package/src/cache/cf/index.ts +5 -1
  97. package/src/cache/document-cache.ts +17 -7
  98. package/src/cache/index.ts +1 -0
  99. package/src/cache/taint.ts +55 -0
  100. package/src/client.rsc.tsx +5 -1
  101. package/src/client.tsx +95 -284
  102. package/src/context-var.ts +72 -2
  103. package/src/debug.ts +2 -2
  104. package/src/decode-loader-results.ts +36 -0
  105. package/src/errors.ts +30 -1
  106. package/src/handle.ts +65 -12
  107. package/src/handles/breadcrumbs.ts +66 -0
  108. package/src/handles/index.ts +1 -0
  109. package/src/host/index.ts +2 -5
  110. package/src/host/router.ts +129 -57
  111. package/src/host/types.ts +31 -2
  112. package/src/host/utils.ts +1 -1
  113. package/src/href-client.ts +140 -20
  114. package/src/index.rsc.ts +15 -40
  115. package/src/index.ts +92 -76
  116. package/src/loader-store.ts +500 -0
  117. package/src/loader.rsc.ts +2 -5
  118. package/src/loader.ts +3 -10
  119. package/src/missing-id-error.ts +68 -0
  120. package/src/outlet-context.ts +1 -1
  121. package/src/prerender/store.ts +57 -15
  122. package/src/prerender.ts +141 -80
  123. package/src/response-utils.ts +37 -0
  124. package/src/reverse.ts +65 -15
  125. package/src/route-content-wrapper.tsx +6 -28
  126. package/src/route-definition/dsl-helpers.ts +435 -260
  127. package/src/route-definition/helper-factories.ts +29 -139
  128. package/src/route-definition/helpers-types.ts +110 -34
  129. package/src/route-definition/index.ts +3 -3
  130. package/src/route-definition/redirect.ts +11 -3
  131. package/src/route-definition/resolve-handler-use.ts +155 -0
  132. package/src/route-definition/use-item-types.ts +32 -0
  133. package/src/route-map-builder.ts +7 -1
  134. package/src/route-types.ts +37 -41
  135. package/src/router/basename.ts +14 -0
  136. package/src/router/content-negotiation.ts +113 -1
  137. package/src/router/error-handling.ts +1 -1
  138. package/src/router/find-match.ts +4 -2
  139. package/src/router/handler-context.ts +105 -39
  140. package/src/router/intercept-resolution.ts +15 -22
  141. package/src/router/lazy-includes.ts +12 -9
  142. package/src/router/loader-resolution.ts +175 -23
  143. package/src/router/logging.ts +5 -2
  144. package/src/router/manifest.ts +31 -16
  145. package/src/router/match-api.ts +129 -193
  146. package/src/router/match-handlers.ts +63 -20
  147. package/src/router/match-middleware/background-revalidation.ts +30 -2
  148. package/src/router/match-middleware/cache-lookup.ts +136 -106
  149. package/src/router/match-middleware/cache-store.ts +54 -10
  150. package/src/router/match-middleware/intercept-resolution.ts +9 -7
  151. package/src/router/match-middleware/segment-resolution.ts +61 -5
  152. package/src/router/match-result.ts +124 -18
  153. package/src/router/metrics.ts +239 -14
  154. package/src/router/middleware-types.ts +61 -31
  155. package/src/router/middleware.ts +226 -124
  156. package/src/router/navigation-snapshot.ts +182 -0
  157. package/src/router/pattern-matching.ts +118 -19
  158. package/src/router/prerender-match.ts +114 -10
  159. package/src/router/preview-match.ts +32 -102
  160. package/src/router/request-classification.ts +286 -0
  161. package/src/router/revalidation.ts +85 -9
  162. package/src/router/route-snapshot.ts +245 -0
  163. package/src/router/router-context.ts +6 -1
  164. package/src/router/router-interfaces.ts +91 -29
  165. package/src/router/router-options.ts +89 -19
  166. package/src/router/router-registry.ts +2 -5
  167. package/src/router/segment-resolution/fresh.ts +240 -23
  168. package/src/router/segment-resolution/helpers.ts +30 -25
  169. package/src/router/segment-resolution/loader-cache.ts +1 -0
  170. package/src/router/segment-resolution/revalidation.ts +483 -289
  171. package/src/router/segment-resolution/view-transition-default.ts +36 -0
  172. package/src/router/segment-wrappers.ts +2 -0
  173. package/src/router/substitute-pattern-params.ts +56 -0
  174. package/src/router/telemetry.ts +99 -0
  175. package/src/router/trie-matching.ts +38 -15
  176. package/src/router/types.ts +9 -0
  177. package/src/router/url-params.ts +49 -0
  178. package/src/router.ts +120 -32
  179. package/src/rsc/handler-context.ts +2 -2
  180. package/src/rsc/handler.ts +524 -370
  181. package/src/rsc/helpers.ts +91 -43
  182. package/src/rsc/index.ts +1 -21
  183. package/src/rsc/loader-fetch.ts +23 -3
  184. package/src/rsc/manifest-init.ts +5 -1
  185. package/src/rsc/origin-guard.ts +28 -10
  186. package/src/rsc/progressive-enhancement.ts +39 -10
  187. package/src/rsc/response-route-handler.ts +46 -53
  188. package/src/rsc/rsc-rendering.ts +69 -89
  189. package/src/rsc/runtime-warnings.ts +9 -10
  190. package/src/rsc/server-action.ts +39 -47
  191. package/src/rsc/ssr-setup.ts +144 -0
  192. package/src/rsc/types.ts +19 -3
  193. package/src/search-params.ts +20 -17
  194. package/src/segment-content-promise.ts +67 -0
  195. package/src/segment-loader-promise.ts +122 -0
  196. package/src/segment-system.tsx +219 -67
  197. package/src/serialize.ts +243 -0
  198. package/src/server/context.ts +285 -63
  199. package/src/server/cookie-store.ts +28 -4
  200. package/src/server/handle-store.ts +19 -0
  201. package/src/server/loader-registry.ts +9 -8
  202. package/src/server/request-context.ts +228 -65
  203. package/src/server.ts +6 -0
  204. package/src/ssr/index.tsx +9 -1
  205. package/src/static-handler.ts +19 -7
  206. package/src/testing/cache-status.ts +166 -0
  207. package/src/testing/collect-handle.ts +63 -0
  208. package/src/testing/dispatch.ts +440 -0
  209. package/src/testing/dom.entry.ts +22 -0
  210. package/src/testing/e2e/fixture.ts +154 -0
  211. package/src/testing/e2e/index.ts +149 -0
  212. package/src/testing/e2e/matchers.ts +51 -0
  213. package/src/testing/e2e/page-helpers.ts +272 -0
  214. package/src/testing/e2e/parity.ts +306 -0
  215. package/src/testing/e2e/server.ts +183 -0
  216. package/src/testing/flight-matchers.ts +104 -0
  217. package/src/testing/flight-runtime.d.ts +21 -0
  218. package/src/testing/flight.entry.ts +22 -0
  219. package/src/testing/flight.ts +182 -0
  220. package/src/testing/generated-routes.ts +223 -0
  221. package/src/testing/index.ts +98 -0
  222. package/src/testing/internal/context.ts +151 -0
  223. package/src/testing/render-route.tsx +536 -0
  224. package/src/testing/run-loader.ts +296 -0
  225. package/src/testing/run-middleware.ts +170 -0
  226. package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
  227. package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
  228. package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
  229. package/src/testing/vitest-stubs/version.ts +5 -0
  230. package/src/testing/vitest.ts +112 -0
  231. package/src/theme/index.ts +4 -13
  232. package/src/types/cache-types.ts +4 -4
  233. package/src/types/global-namespace.ts +39 -26
  234. package/src/types/handler-context.ts +197 -79
  235. package/src/types/index.ts +1 -0
  236. package/src/types/loader-types.ts +41 -15
  237. package/src/types/request-scope.ts +126 -0
  238. package/src/types/route-config.ts +17 -8
  239. package/src/types/route-entry.ts +19 -1
  240. package/src/types/segments.ts +37 -6
  241. package/src/urls/include-helper.ts +34 -67
  242. package/src/urls/index.ts +0 -3
  243. package/src/urls/path-helper-types.ts +50 -9
  244. package/src/urls/path-helper.ts +63 -63
  245. package/src/urls/pattern-types.ts +48 -19
  246. package/src/urls/response-types.ts +25 -22
  247. package/src/urls/type-extraction.ts +26 -116
  248. package/src/urls/urls-function.ts +1 -5
  249. package/src/use-loader.tsx +487 -44
  250. package/src/vite/debug.ts +185 -0
  251. package/src/vite/discovery/bundle-postprocess.ts +63 -91
  252. package/src/vite/discovery/discover-routers.ts +106 -53
  253. package/src/vite/discovery/discovery-errors.ts +194 -0
  254. package/src/vite/discovery/gate-state.ts +171 -0
  255. package/src/vite/discovery/prerender-collection.ts +222 -107
  256. package/src/vite/discovery/route-types-writer.ts +40 -84
  257. package/src/vite/discovery/self-gen-tracking.ts +27 -1
  258. package/src/vite/discovery/state.ts +50 -13
  259. package/src/vite/discovery/virtual-module-codegen.ts +13 -23
  260. package/src/vite/index.ts +10 -3
  261. package/src/vite/plugin-types.ts +111 -72
  262. package/src/vite/plugins/cjs-to-esm.ts +8 -7
  263. package/src/vite/plugins/client-ref-dedup.ts +16 -0
  264. package/src/vite/plugins/client-ref-hashing.ts +28 -5
  265. package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
  266. package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  267. package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
  268. package/src/vite/plugins/expose-action-id.ts +55 -33
  269. package/src/vite/plugins/expose-id-utils.ts +24 -8
  270. package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
  271. package/src/vite/plugins/expose-ids/handler-transform.ts +12 -35
  272. package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
  273. package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
  274. package/src/vite/plugins/expose-internal-ids.ts +544 -317
  275. package/src/vite/plugins/performance-tracks.ts +92 -0
  276. package/src/vite/plugins/refresh-cmd.ts +127 -0
  277. package/src/vite/plugins/use-cache-transform.ts +65 -50
  278. package/src/vite/plugins/version-injector.ts +39 -23
  279. package/src/vite/plugins/version-plugin.ts +72 -3
  280. package/src/vite/plugins/virtual-entries.ts +2 -2
  281. package/src/vite/rango.ts +265 -226
  282. package/src/vite/router-discovery.ts +924 -137
  283. package/src/vite/utils/ast-handler-extract.ts +15 -15
  284. package/src/vite/utils/banner.ts +4 -4
  285. package/src/vite/utils/bundle-analysis.ts +4 -2
  286. package/src/vite/utils/client-chunks.ts +190 -0
  287. package/src/vite/utils/forward-user-plugins.ts +193 -0
  288. package/src/vite/utils/manifest-utils.ts +21 -5
  289. package/src/vite/utils/package-resolution.ts +41 -1
  290. package/src/vite/utils/prerender-utils.ts +98 -5
  291. package/src/vite/utils/shared-utils.ts +109 -27
  292. package/src/browser/action-response-classifier.ts +0 -99
  293. package/src/route-definition/route-function.ts +0 -119
@@ -10,7 +10,11 @@ import type { ReactNode } from "react";
10
10
  import { invariant } from "../../errors";
11
11
  import { revalidate } from "../loader-resolution.js";
12
12
  import { evaluateRevalidation } from "../revalidation.js";
13
- import type { EntryData } from "../../server/context";
13
+ import {
14
+ getParallelEntries,
15
+ getParallelSlotEntries,
16
+ type EntryData,
17
+ } from "../../server/context";
14
18
  import type {
15
19
  HandlerContext,
16
20
  InternalHandlerContext,
@@ -35,8 +39,14 @@ import {
35
39
  resolveLayoutComponent,
36
40
  resolveWithErrorBoundary,
37
41
  } from "./helpers.js";
42
+ import { applyViewTransitionDefault } from "./view-transition-default.js";
38
43
  import { getRouterContext } from "../router-context.js";
39
44
  import { resolveSink, safeEmit } from "../telemetry.js";
45
+ import {
46
+ track,
47
+ RangoContext,
48
+ runInsideLoaderScope,
49
+ } from "../../server/context.js";
40
50
 
41
51
  // ---------------------------------------------------------------------------
42
52
  // Telemetry helpers
@@ -80,6 +90,27 @@ function observeStreamedHandler(
80
90
  });
81
91
  }
82
92
 
93
+ /**
94
+ * Trace a parallel slot that's being force-rendered on a full refetch (client
95
+ * has no cached state). User revalidate fns are bypassed in this case — see
96
+ * the call sites for the load-bearing rationale.
97
+ */
98
+ function traceFullRefetchedParallelSlot(
99
+ parallelId: string,
100
+ belongsToRoute: boolean,
101
+ ): void {
102
+ if (!isTraceActive()) return;
103
+ pushRevalidationTraceEntry({
104
+ segmentId: parallelId,
105
+ segmentType: "parallel",
106
+ belongsToRoute,
107
+ source: "parallel",
108
+ defaultShouldRevalidate: true,
109
+ finalShouldRevalidate: true,
110
+ reason: "full-refetch",
111
+ });
112
+ }
113
+
83
114
  // ---------------------------------------------------------------------------
84
115
  // Revalidation telemetry helper
85
116
  // ---------------------------------------------------------------------------
@@ -227,7 +258,9 @@ export async function resolveLoadersWithRevalidation<TEnv>(
227
258
  params: ctx.params,
228
259
  loaderId: loader.$$id,
229
260
  loaderData: deps.wrapLoaderPromise(
230
- resolveLoaderData(loaderEntry, ctx, ctx.pathname),
261
+ runInsideLoaderScope(() =>
262
+ resolveLoaderData(loaderEntry, ctx, ctx.pathname),
263
+ ),
231
264
  entry,
232
265
  segmentId,
233
266
  ctx.pathname,
@@ -257,26 +290,95 @@ export async function resolveLoadersOnlyWithRevalidation<TEnv>(
257
290
  ): Promise<{ segments: ResolvedSegment[]; matchedIds: string[] }> {
258
291
  const allLoaderSegments: ResolvedSegment[] = [];
259
292
  const allMatchedIds: string[] = [];
293
+ const seenIds = new Set<string>();
294
+
295
+ async function collectEntryLoaders(
296
+ entry: EntryData,
297
+ belongsToRoute: boolean,
298
+ shortCodeOverride?: string,
299
+ ): Promise<void> {
300
+ // Skip if all loaders from this entry have already been resolved
301
+ // via a parent (e.g., cache boundary wrapping a layout with shared loaders).
302
+ const loaderEntries = entry.loader ?? [];
303
+ const sc = shortCodeOverride ?? entry.shortCode;
304
+ const allAlreadySeen =
305
+ loaderEntries.length > 0 &&
306
+ loaderEntries.every((le, i) =>
307
+ seenIds.has(`${sc}D${i}.${le.loader.$$id}`),
308
+ );
309
+ if (!allAlreadySeen) {
310
+ const { segments, matchedIds } = await resolveLoadersWithRevalidation(
311
+ entry,
312
+ context,
313
+ belongsToRoute,
314
+ clientSegmentIds,
315
+ prevParams,
316
+ request,
317
+ prevUrl,
318
+ nextUrl,
319
+ routeKey,
320
+ deps,
321
+ actionContext,
322
+ shortCodeOverride,
323
+ stale,
324
+ );
325
+ for (const seg of segments) {
326
+ if (!seenIds.has(seg.id)) {
327
+ seenIds.add(seg.id);
328
+ allLoaderSegments.push(seg);
329
+ }
330
+ }
331
+ allMatchedIds.push(...matchedIds);
332
+ }
333
+
334
+ const seenParallelEntryIds = new Set<string>();
335
+ for (const parallelEntry of getParallelEntries(entry.parallel)) {
336
+ if (seenParallelEntryIds.has(parallelEntry.id)) continue;
337
+ seenParallelEntryIds.add(parallelEntry.id);
338
+ await collectEntryLoaders(parallelEntry, belongsToRoute, entry.shortCode);
339
+ }
340
+
341
+ const childBelongsToRoute = belongsToRoute || entry.type === "route";
342
+ for (const layoutEntry of entry.layout) {
343
+ await collectEntryLoaders(layoutEntry, childBelongsToRoute);
344
+ // Inherit route loaders for orphan layouts with parallels.
345
+ // Resolve directly — do NOT re-enter collectEntryLoaders with the
346
+ // route entry, as that would re-iterate route.layout and loop.
347
+ if (
348
+ entry.type === "route" &&
349
+ entry.loader &&
350
+ entry.loader.length > 0 &&
351
+ Object.keys(layoutEntry.parallel).length > 0
352
+ ) {
353
+ const inherited = await resolveLoadersWithRevalidation(
354
+ entry,
355
+ context,
356
+ childBelongsToRoute,
357
+ clientSegmentIds,
358
+ prevParams,
359
+ request,
360
+ prevUrl,
361
+ nextUrl,
362
+ routeKey,
363
+ deps,
364
+ actionContext,
365
+ layoutEntry.shortCode,
366
+ stale,
367
+ );
368
+ for (const seg of inherited.segments) {
369
+ if (!seenIds.has(seg.id)) {
370
+ seenIds.add(seg.id);
371
+ seg._inherited = true;
372
+ allLoaderSegments.push(seg);
373
+ }
374
+ }
375
+ allMatchedIds.push(...inherited.matchedIds);
376
+ }
377
+ }
378
+ }
260
379
 
261
380
  for (const entry of entries) {
262
- const belongsToRoute = entry.type === "route";
263
- const { segments, matchedIds } = await resolveLoadersWithRevalidation(
264
- entry,
265
- context,
266
- belongsToRoute,
267
- clientSegmentIds,
268
- prevParams,
269
- request,
270
- prevUrl,
271
- nextUrl,
272
- routeKey,
273
- deps,
274
- actionContext,
275
- undefined, // shortCodeOverride
276
- stale,
277
- );
278
- allLoaderSegments.push(...segments);
279
- allMatchedIds.push(...matchedIds);
381
+ await collectEntryLoaders(entry, entry.type === "route");
280
382
  }
281
383
 
282
384
  return { segments: allLoaderSegments, matchedIds: allMatchedIds };
@@ -300,22 +402,20 @@ export function buildEntryRevalidateMap(
300
402
  map.set(entry.shortCode, { entry, revalidate: entry.revalidate });
301
403
 
302
404
  if (entry.type !== "parallel") {
303
- for (const parallelEntry of entry.parallel) {
304
- if (parallelEntry.type === "parallel") {
305
- const slots = Object.keys(parallelEntry.handler) as `@${string}`[];
306
- for (const slot of slots) {
307
- const parallelId = `${parallelEntry.shortCode}.${slot}`;
308
- map.set(parallelId, {
309
- entry: parallelEntry,
310
- revalidate: parallelEntry.revalidate,
311
- });
312
- }
313
- }
405
+ for (const { slot, entry: parallelEntry } of getParallelSlotEntries(
406
+ entry.parallel,
407
+ )) {
408
+ const parallelParentShortCode = parentShortCode ?? entry.shortCode;
409
+ const parallelId = `${parallelParentShortCode}.${slot}`;
410
+ map.set(parallelId, {
411
+ entry: parallelEntry,
412
+ revalidate: parallelEntry.revalidate,
413
+ });
314
414
  }
315
415
  }
316
416
 
317
417
  for (const layoutEntry of entry.layout) {
318
- processEntry(layoutEntry);
418
+ processEntry(layoutEntry, entry.shortCode);
319
419
  }
320
420
  }
321
421
 
@@ -347,7 +447,10 @@ export async function resolveParallelSegmentsWithRevalidation<TEnv>(
347
447
  const segments: ResolvedSegment[] = [];
348
448
  const matchedIds: string[] = [];
349
449
 
350
- for (const parallelEntry of entry.parallel) {
450
+ const resolvedParallelEntries = new Set<string>();
451
+ for (const { slot, entry: parallelEntry } of getParallelSlotEntries(
452
+ entry.parallel,
453
+ )) {
351
454
  invariant(
352
455
  parallelEntry.type === "parallel",
353
456
  `Expected parallel entry, got: ${parallelEntry.type}`,
@@ -358,108 +461,106 @@ export async function resolveParallelSegmentsWithRevalidation<TEnv>(
358
461
  | ((ctx: HandlerContext<any, TEnv>) => ReactNode | Promise<ReactNode>)
359
462
  | ReactNode
360
463
  >;
361
-
362
- for (const [slot, handler] of Object.entries(slots)) {
363
- const parallelId = `${entry.shortCode}.${slot}`;
364
-
365
- const isFullRefetch = clientSegmentIds.size === 0;
366
- // When the parent layout is new (not in client's segment set),
367
- // all its parallel children must be resolved and tracked.
368
- // Without this, navigating to a new layout with parallels
369
- // (e.g., BlogLayout with @sidebar) from a different route
370
- // would silently drop those parallel segments.
371
- const isNewParent = !clientSegmentIds.has(entry.shortCode);
372
- if (
373
- isFullRefetch ||
374
- clientSegmentIds.has(parallelId) ||
375
- belongsToRoute ||
376
- isNewParent
377
- ) {
378
- matchedIds.push(parallelId);
464
+ // In production, static handler bodies are evicted and the slot value
465
+ // may be undefined. The static store holds the pre-rendered component.
466
+ // We defer the handler check until after tryStaticSlot.
467
+ const handler = slots[slot];
468
+
469
+ const parallelId = `${entry.shortCode}.${slot}`;
470
+
471
+ const isFullRefetch = clientSegmentIds.size === 0;
472
+ const isNewParent = !clientSegmentIds.has(entry.shortCode);
473
+ // Always announce the slot in matchedIds — it's unconditionally appended
474
+ // to `segments` below, and a segment present in segments but missing from
475
+ // matched lets the client prune it (then it's missing from clientSegmentIds
476
+ // on the next request, perpetuating the staleness).
477
+ matchedIds.push(parallelId);
478
+
479
+ let shouldResolve: boolean;
480
+ if (isFullRefetch) {
481
+ // Client has nothing cached — slot MUST render. User revalidate fns are
482
+ // bypassed here because returning false would leave the segment blank
483
+ // with no client-side fallback.
484
+ traceFullRefetchedParallelSlot(parallelId, belongsToRoute);
485
+ shouldResolve = true;
486
+ } else {
487
+ // For non-empty client sets, consult user revalidate fns. When the slot
488
+ // is unknown to the client, override the type-derived default so the
489
+ // soft chain seeds with the right "new segment" / "parent-chain" value.
490
+ let defaultOverride: { value: boolean; reason: string } | undefined;
491
+ if (!clientSegmentIds.has(parallelId)) {
492
+ const value = belongsToRoute || isNewParent;
493
+ defaultOverride = {
494
+ value,
495
+ reason: value ? "new-segment" : "skip-parent-chain",
496
+ };
379
497
  }
380
498
 
381
- const shouldResolve = await (async () => {
382
- if (isFullRefetch) {
383
- if (isTraceActive()) {
384
- pushRevalidationTraceEntry({
385
- segmentId: parallelId,
386
- segmentType: "parallel",
387
- belongsToRoute,
388
- source: "parallel",
389
- defaultShouldRevalidate: true,
390
- finalShouldRevalidate: true,
391
- reason: "full-refetch",
392
- });
393
- }
394
- return true;
395
- }
396
- if (!clientSegmentIds.has(parallelId)) {
397
- const result = belongsToRoute || isNewParent;
398
- if (isTraceActive()) {
399
- pushRevalidationTraceEntry({
400
- segmentId: parallelId,
401
- segmentType: "parallel",
402
- belongsToRoute,
403
- source: "parallel",
404
- defaultShouldRevalidate: result,
405
- finalShouldRevalidate: result,
406
- reason: result ? "new-segment" : "skip-parent-chain",
407
- });
408
- }
409
- return result;
410
- }
411
-
412
- const dummySegment: ResolvedSegment = {
413
- id: parallelId,
414
- namespace: parallelEntry.id,
415
- type: "parallel",
416
- index: 0,
417
- component: null as any,
418
- params,
419
- slot,
420
- belongsToRoute,
421
- parallelName: `${parallelEntry.id}.${slot}`,
422
- ...(parallelEntry.mountPath
423
- ? { mountPath: parallelEntry.mountPath }
424
- : {}),
425
- };
499
+ const dummySegment: ResolvedSegment = {
500
+ id: parallelId,
501
+ namespace: parallelEntry.id,
502
+ type: "parallel",
503
+ index: 0,
504
+ component: null as any,
505
+ params,
506
+ slot,
507
+ belongsToRoute,
508
+ parallelName: `${parallelEntry.id}.${slot}`,
509
+ ...(parallelEntry.mountPath
510
+ ? { mountPath: parallelEntry.mountPath }
511
+ : {}),
512
+ };
426
513
 
427
- return await evaluateRevalidation({
428
- segment: dummySegment,
429
- prevParams,
430
- getPrevSegment: null,
431
- request,
432
- prevUrl,
433
- nextUrl,
434
- revalidations: parallelEntry.revalidate.map((fn, i) => ({
435
- name: `revalidate${i}`,
436
- fn,
437
- })),
438
- routeKey,
439
- context,
440
- actionContext,
441
- stale,
442
- traceSource: "parallel",
443
- });
444
- })();
445
- emitRevalidationDecision(
446
- parallelId,
447
- context.pathname,
514
+ shouldResolve = await evaluateRevalidation({
515
+ segment: dummySegment,
516
+ prevParams,
517
+ getPrevSegment: null,
518
+ request,
519
+ prevUrl,
520
+ nextUrl,
521
+ revalidations: parallelEntry.revalidate.map((fn, i) => ({
522
+ name: `revalidate${i}`,
523
+ fn,
524
+ })),
448
525
  routeKey,
449
- shouldResolve,
450
- );
526
+ context,
527
+ actionContext,
528
+ stale,
529
+ traceSource: "parallel",
530
+ defaultOverride,
531
+ });
532
+ }
533
+ emitRevalidationDecision(
534
+ parallelId,
535
+ context.pathname,
536
+ routeKey,
537
+ shouldResolve,
538
+ );
451
539
 
452
- let component: ReactNode | undefined;
453
- if (shouldResolve) {
454
- component = await tryStaticSlot(parallelEntry, slot, parallelId);
455
- }
456
- if (component === undefined) {
457
- const hasLoadingFallback =
458
- parallelEntry.loading !== undefined &&
459
- parallelEntry.loading !== false;
460
- if (!shouldResolve) {
461
- component = null;
462
- } else if (hasLoadingFallback) {
540
+ let component: ReactNode | undefined;
541
+ let handlerRan = false;
542
+ if (shouldResolve) {
543
+ component = await tryStaticSlot(parallelEntry, slot, parallelId);
544
+ // tryStaticSlot returning a value means the static cache supplied the
545
+ // component — handler did NOT run. handlerRan stays false.
546
+ }
547
+ if (component === undefined) {
548
+ const hasLoadingFallback =
549
+ parallelEntry.loading !== undefined && parallelEntry.loading !== false;
550
+ if (!shouldResolve) {
551
+ component = null;
552
+ } else if (handler === undefined) {
553
+ // Handler evicted (production static slot) but static lookup missed.
554
+ // Nothing to render — use null so the client keeps its cached version.
555
+ component = null;
556
+ } else {
557
+ // Slot-keyed pushes — slot owns its own bucket, parent layout owns
558
+ // its own. On slot-only revalidations the partial merge updates only
559
+ // the slot's bucket; the parent's bucket stays intact.
560
+ (context as InternalHandlerContext<any, TEnv>)._currentSegmentId =
561
+ parallelId;
562
+ handlerRan = true;
563
+ if (hasLoadingFallback) {
463
564
  const result =
464
565
  typeof handler === "function" ? handler(context) : handler;
465
566
  if (result instanceof Promise) {
@@ -484,44 +585,51 @@ export async function resolveParallelSegmentsWithRevalidation<TEnv>(
484
585
  typeof handler === "function" ? await handler(context) : handler;
485
586
  }
486
587
  }
487
-
488
- segments.push({
489
- id: parallelId,
490
- namespace: parallelEntry.id,
491
- type: "parallel",
492
- index: 0,
493
- component,
494
- loading: parallelEntry.loading === false ? null : parallelEntry.loading,
495
- transition: parallelEntry.transition,
496
- params,
497
- slot,
498
- belongsToRoute,
499
- parallelName: `${parallelEntry.id}.${slot}`,
500
- ...(parallelEntry.mountPath
501
- ? { mountPath: parallelEntry.mountPath }
502
- : {}),
503
- });
504
588
  }
505
589
 
506
- if (!parallelEntry.loading) {
507
- const loaderResult = await resolveLoadersWithRevalidation(
508
- parallelEntry,
509
- context,
510
- belongsToRoute,
511
- clientSegmentIds,
512
- prevParams,
513
- request,
514
- prevUrl,
515
- nextUrl,
516
- routeKey,
517
- deps,
518
- actionContext,
519
- entry.shortCode,
520
- stale,
521
- );
522
- segments.push(...loaderResult.segments);
523
- matchedIds.push(...loaderResult.matchedIds);
590
+ segments.push({
591
+ id: parallelId,
592
+ namespace: parallelEntry.id,
593
+ type: "parallel",
594
+ index: 0,
595
+ component,
596
+ loading: parallelEntry.loading === false ? null : parallelEntry.loading,
597
+ transition: applyViewTransitionDefault(
598
+ parallelEntry.transition,
599
+ deps.viewTransitionDefault,
600
+ ),
601
+ params,
602
+ slot,
603
+ _handlerRan: handlerRan,
604
+ belongsToRoute,
605
+ parallelName: `${parallelEntry.id}.${slot}`,
606
+ ...(parallelEntry.mountPath
607
+ ? { mountPath: parallelEntry.mountPath }
608
+ : {}),
609
+ });
610
+
611
+ if (resolvedParallelEntries.has(parallelEntry.id)) {
612
+ continue;
524
613
  }
614
+
615
+ const loaderResult = await resolveLoadersWithRevalidation(
616
+ parallelEntry,
617
+ context,
618
+ belongsToRoute,
619
+ clientSegmentIds,
620
+ prevParams,
621
+ request,
622
+ prevUrl,
623
+ nextUrl,
624
+ routeKey,
625
+ deps,
626
+ actionContext,
627
+ entry.shortCode,
628
+ stale,
629
+ );
630
+ segments.push(...loaderResult.segments);
631
+ matchedIds.push(...loaderResult.matchedIds);
632
+ resolvedParallelEntries.add(parallelEntry.id);
525
633
  }
526
634
 
527
635
  return { segments, matchedIds };
@@ -547,6 +655,7 @@ export async function resolveEntryHandlerWithRevalidation<TEnv>(
547
655
  ): Promise<{ segment: ResolvedSegment; matchedId: string }> {
548
656
  const matchedId = entry.shortCode;
549
657
 
658
+ let handlerRan = false;
550
659
  const component = await revalidate(
551
660
  async () => {
552
661
  const hasSegment = clientSegmentIds.has(entry.shortCode);
@@ -607,6 +716,8 @@ export async function resolveEntryHandlerWithRevalidation<TEnv>(
607
716
  context,
608
717
  actionContext,
609
718
  stale,
719
+ traceSource:
720
+ entry.type === "route" ? "route-handler" : "layout-handler",
610
721
  });
611
722
  emitRevalidationDecision(
612
723
  entry.shortCode,
@@ -621,20 +732,37 @@ export async function resolveEntryHandlerWithRevalidation<TEnv>(
621
732
  return shouldRevalidate;
622
733
  },
623
734
  async () => {
735
+ handlerRan = true;
736
+ const doneHandler = track(`handler:${entry.id}`, 2);
624
737
  (context as InternalHandlerContext<any, TEnv>)._currentSegmentId =
625
738
  entry.shortCode;
626
739
  if (entry.type === "layout" || entry.type === "cache") {
627
- return resolveLayoutComponent(entry, context);
740
+ const layoutComponent = await resolveLayoutComponent(entry, context);
741
+ doneHandler();
742
+ return layoutComponent;
628
743
  }
629
744
  const staticComponent = await tryStaticHandler(entry, entry.shortCode);
630
- if (staticComponent !== undefined) return staticComponent;
745
+ if (staticComponent !== undefined) {
746
+ doneHandler();
747
+ return staticComponent;
748
+ }
631
749
  const routeEntry = entry as Extract<EntryData, { type: "route" }>;
750
+ // For Passthrough routes at runtime, use the live handler instead of
751
+ // the build handler. At build time (context.build === true), always
752
+ // use the build handler from routeEntry.handler.
753
+ const handler =
754
+ !context.build && routeEntry.liveHandler
755
+ ? routeEntry.liveHandler
756
+ : routeEntry.handler;
632
757
  if (!routeEntry.loading) {
633
- return handleHandlerResult(await routeEntry.handler(context));
758
+ const result = handleHandlerResult(await handler(context));
759
+ doneHandler();
760
+ return result;
634
761
  }
635
762
  if (!actionContext) {
636
- const result = handleHandlerResult(routeEntry.handler(context));
763
+ const result = handleHandlerResult(handler(context));
637
764
  if (result instanceof Promise) {
765
+ result.finally(doneHandler).catch(() => {});
638
766
  const tracked = deps.trackHandler(result, {
639
767
  segmentId: entry.shortCode,
640
768
  segmentType: entry.type,
@@ -649,24 +777,27 @@ export async function resolveEntryHandlerWithRevalidation<TEnv>(
649
777
  );
650
778
  return { content: tracked };
651
779
  }
780
+ doneHandler();
652
781
  return { content: result };
653
782
  }
654
783
  debugLog("segment.action", "resolving action route with awaited value", {
655
784
  entryId: entry.id,
656
785
  });
786
+ const actionResult = handleHandlerResult(await handler(context));
787
+ doneHandler();
657
788
  return {
658
- content: Promise.resolve(
659
- handleHandlerResult(await routeEntry.handler(context)),
660
- ),
789
+ content: Promise.resolve(actionResult),
661
790
  };
662
791
  },
663
792
  () => null,
664
793
  );
665
794
 
795
+ // Normalize void handlers (undefined) to null so the reconciler's
796
+ // component === null checks work consistently for both void and explicit null.
666
797
  const resolvedComponent =
667
798
  component && typeof component === "object" && "content" in component
668
- ? (component as { content: ReactNode }).content
669
- : component;
799
+ ? ((component as { content: ReactNode }).content ?? null)
800
+ : (component ?? null);
670
801
 
671
802
  const segment: ResolvedSegment = {
672
803
  id: entry.shortCode,
@@ -676,13 +807,17 @@ export async function resolveEntryHandlerWithRevalidation<TEnv>(
676
807
  index: 0,
677
808
  component: resolvedComponent,
678
809
  loading: entry.loading === false ? null : entry.loading,
679
- transition: entry.transition,
810
+ transition: applyViewTransitionDefault(
811
+ entry.transition,
812
+ deps.viewTransitionDefault,
813
+ ),
680
814
  params,
681
815
  belongsToRoute,
682
816
  ...(entry.type === "layout" || entry.type === "cache"
683
817
  ? { layoutName: entry.id }
684
818
  : {}),
685
819
  ...(entry.mountPath ? { mountPath: entry.mountPath } : {}),
820
+ _handlerRan: handlerRan,
686
821
  };
687
822
 
688
823
  return { segment, matchedId };
@@ -763,11 +898,11 @@ export async function resolveSegmentWithRevalidation<TEnv>(
763
898
  prevUrl,
764
899
  nextUrl,
765
900
  routeKey,
766
- loaderPromises,
767
901
  true,
768
902
  deps,
769
903
  actionContext,
770
904
  stale,
905
+ entry,
771
906
  );
772
907
  segments.push(...orphanResult.segments);
773
908
  matchedIds.push(...orphanResult.matchedIds);
@@ -847,7 +982,6 @@ export async function resolveSegmentWithRevalidation<TEnv>(
847
982
  prevUrl,
848
983
  nextUrl,
849
984
  routeKey,
850
- loaderPromises,
851
985
  false,
852
986
  deps,
853
987
  actionContext,
@@ -874,11 +1008,12 @@ export async function resolveOrphanLayoutWithRevalidation<TEnv>(
874
1008
  prevUrl: URL,
875
1009
  nextUrl: URL,
876
1010
  routeKey: string,
877
- loaderPromises: Map<string, Promise<any>>,
878
1011
  belongsToRoute: boolean,
879
1012
  deps: SegmentResolutionDeps<TEnv>,
880
1013
  actionContext?: ActionContext,
881
1014
  stale?: boolean,
1015
+ /** Parent route entry — its loaders are inherited so parallel slots can access them. */
1016
+ parentRouteEntry?: EntryData,
882
1017
  ): Promise<SegmentRevalidationResult> {
883
1018
  invariant(
884
1019
  orphan.type === "layout" || orphan.type === "cache",
@@ -906,6 +1041,37 @@ export async function resolveOrphanLayoutWithRevalidation<TEnv>(
906
1041
  segments.push(...loaderResult.segments);
907
1042
  matchedIds.push(...loaderResult.matchedIds);
908
1043
 
1044
+ // Inherit parent route's loaders so parallel slots inside this layout
1045
+ // can access them via useLoader(). See resolveOrphanLayout in fresh.ts.
1046
+ if (
1047
+ parentRouteEntry &&
1048
+ parentRouteEntry.loader &&
1049
+ parentRouteEntry.loader.length > 0 &&
1050
+ Object.keys(orphan.parallel).length > 0
1051
+ ) {
1052
+ const inheritedResult = await resolveLoadersWithRevalidation(
1053
+ parentRouteEntry,
1054
+ context,
1055
+ belongsToRoute,
1056
+ clientSegmentIds,
1057
+ prevParams,
1058
+ request,
1059
+ prevUrl,
1060
+ nextUrl,
1061
+ routeKey,
1062
+ deps,
1063
+ actionContext,
1064
+ orphan.shortCode,
1065
+ stale,
1066
+ );
1067
+ // Tag as inherited so buildMatchResult can deduplicate when safe
1068
+ for (const s of inheritedResult.segments) {
1069
+ s._inherited = true;
1070
+ }
1071
+ segments.push(...inheritedResult.segments);
1072
+ matchedIds.push(...inheritedResult.matchedIds);
1073
+ }
1074
+
909
1075
  // Handler-first: resolve orphan layout handler before its parallels
910
1076
  // so ctx.set() values are visible to parallel children.
911
1077
  matchedIds.push(orphan.shortCode);
@@ -978,114 +1144,133 @@ export async function resolveOrphanLayoutWithRevalidation<TEnv>(
978
1144
  belongsToRoute,
979
1145
  layoutName: orphan.id,
980
1146
  loading: orphan.loading === false ? null : orphan.loading,
981
- transition: orphan.transition,
1147
+ transition: applyViewTransitionDefault(
1148
+ orphan.transition,
1149
+ deps.viewTransitionDefault,
1150
+ ),
982
1151
  ...(orphan.mountPath ? { mountPath: orphan.mountPath } : {}),
983
1152
  });
984
1153
 
985
- for (const parallelEntry of orphan.parallel) {
1154
+ const resolvedParallelEntries = new Set<string>();
1155
+ for (const { slot, entry: parallelEntry } of getParallelSlotEntries(
1156
+ orphan.parallel,
1157
+ )) {
986
1158
  invariant(
987
1159
  parallelEntry.type === "parallel",
988
1160
  `Expected parallel entry, got: ${parallelEntry.type}`,
989
1161
  );
990
1162
 
991
- const loaderResult = await resolveLoadersWithRevalidation(
992
- parallelEntry,
993
- context,
994
- belongsToRoute,
995
- clientSegmentIds,
996
- prevParams,
997
- request,
998
- prevUrl,
999
- nextUrl,
1000
- routeKey,
1001
- deps,
1002
- actionContext,
1003
- undefined,
1004
- stale,
1005
- );
1006
- segments.push(...loaderResult.segments);
1007
- matchedIds.push(...loaderResult.matchedIds);
1163
+ if (!resolvedParallelEntries.has(parallelEntry.id)) {
1164
+ // shortCodeOverride must match the parent layout, not the parallel entry.
1165
+ const loaderResult = await resolveLoadersWithRevalidation(
1166
+ parallelEntry,
1167
+ context,
1168
+ belongsToRoute,
1169
+ clientSegmentIds,
1170
+ prevParams,
1171
+ request,
1172
+ prevUrl,
1173
+ nextUrl,
1174
+ routeKey,
1175
+ deps,
1176
+ actionContext,
1177
+ orphan.shortCode,
1178
+ stale,
1179
+ );
1180
+ segments.push(...loaderResult.segments);
1181
+ matchedIds.push(...loaderResult.matchedIds);
1182
+ resolvedParallelEntries.add(parallelEntry.id);
1183
+ }
1008
1184
 
1009
1185
  const slots = parallelEntry.handler as Record<
1010
1186
  `@${string}`,
1011
1187
  | ((ctx: HandlerContext<any, TEnv>) => ReactNode | Promise<ReactNode>)
1012
1188
  | ReactNode
1013
1189
  >;
1190
+ // Handler may be undefined in production after static handler eviction.
1191
+ const handler = slots[slot];
1192
+
1193
+ // Use orphan.shortCode (the parent layout) to match the SSR path
1194
+ // (resolveParallelEntry receives parentShortCode = orphan.shortCode).
1195
+ // Using parallelEntry.shortCode would generate IDs the client doesn't know about.
1196
+ const parallelId = `${orphan.shortCode}.${slot}`;
1197
+ matchedIds.push(parallelId);
1198
+
1199
+ const isFullRefetch = clientSegmentIds.size === 0;
1200
+ let shouldResolve: boolean;
1201
+ if (isFullRefetch) {
1202
+ // Same load-bearing rationale as the main parallel path: full refetch
1203
+ // means the client has nothing to fall back to, so the slot must render.
1204
+ traceFullRefetchedParallelSlot(parallelId, belongsToRoute);
1205
+ shouldResolve = true;
1206
+ } else {
1207
+ // When slot is unknown to the client, seed the soft chain with `true`
1208
+ // (orphan parallels always belong to the route — we want them rendered
1209
+ // unless the user explicitly opts out via revalidate()).
1210
+ const defaultOverride = clientSegmentIds.has(parallelId)
1211
+ ? undefined
1212
+ : { value: true, reason: "new-segment" };
1014
1213
 
1015
- for (const [slot, handler] of Object.entries(slots)) {
1016
- // Use orphan.shortCode (the parent layout) to match the SSR path
1017
- // (resolveParallelEntry receives parentShortCode = orphan.shortCode).
1018
- // Using parallelEntry.shortCode would generate IDs the client doesn't know about.
1019
- const parallelId = `${orphan.shortCode}.${slot}`;
1020
- matchedIds.push(parallelId);
1021
-
1022
- const shouldResolve = await (async () => {
1023
- if (!clientSegmentIds.has(parallelId)) {
1024
- if (isTraceActive()) {
1025
- pushRevalidationTraceEntry({
1026
- segmentId: parallelId,
1027
- segmentType: "parallel",
1028
- belongsToRoute,
1029
- source: "parallel",
1030
- defaultShouldRevalidate: true,
1031
- finalShouldRevalidate: true,
1032
- reason: "new-segment",
1033
- });
1034
- }
1035
- return true;
1036
- }
1037
-
1038
- const dummySegment: ResolvedSegment = {
1039
- id: parallelId,
1040
- namespace: parallelEntry.id,
1041
- type: "parallel",
1042
- index: 0,
1043
- component: null as any,
1044
- params,
1045
- slot,
1046
- belongsToRoute,
1047
- parallelName: `${parallelEntry.id}.${slot}`,
1048
- ...(parallelEntry.mountPath
1049
- ? { mountPath: parallelEntry.mountPath }
1050
- : {}),
1051
- };
1214
+ const dummySegment: ResolvedSegment = {
1215
+ id: parallelId,
1216
+ namespace: parallelEntry.id,
1217
+ type: "parallel",
1218
+ index: 0,
1219
+ component: null as any,
1220
+ params,
1221
+ slot,
1222
+ belongsToRoute,
1223
+ parallelName: `${parallelEntry.id}.${slot}`,
1224
+ ...(parallelEntry.mountPath
1225
+ ? { mountPath: parallelEntry.mountPath }
1226
+ : {}),
1227
+ };
1052
1228
 
1053
- return await evaluateRevalidation({
1054
- segment: dummySegment,
1055
- prevParams,
1056
- getPrevSegment: null,
1057
- request,
1058
- prevUrl,
1059
- nextUrl,
1060
- revalidations: parallelEntry.revalidate.map((fn, i) => ({
1061
- name: `revalidate${i}`,
1062
- fn,
1063
- })),
1064
- routeKey,
1065
- context,
1066
- actionContext,
1067
- stale,
1068
- traceSource: "parallel",
1069
- });
1070
- })();
1071
- emitRevalidationDecision(
1072
- parallelId,
1073
- context.pathname,
1229
+ shouldResolve = await evaluateRevalidation({
1230
+ segment: dummySegment,
1231
+ prevParams,
1232
+ getPrevSegment: null,
1233
+ request,
1234
+ prevUrl,
1235
+ nextUrl,
1236
+ revalidations: parallelEntry.revalidate.map((fn, i) => ({
1237
+ name: `revalidate${i}`,
1238
+ fn,
1239
+ })),
1074
1240
  routeKey,
1075
- shouldResolve,
1076
- );
1241
+ context,
1242
+ actionContext,
1243
+ stale,
1244
+ traceSource: "parallel",
1245
+ defaultOverride,
1246
+ });
1247
+ }
1248
+ emitRevalidationDecision(
1249
+ parallelId,
1250
+ context.pathname,
1251
+ routeKey,
1252
+ shouldResolve,
1253
+ );
1077
1254
 
1078
- let component: ReactNode | undefined;
1079
- if (shouldResolve) {
1080
- component = await tryStaticSlot(parallelEntry, slot, parallelId);
1081
- }
1082
- if (component === undefined) {
1083
- const hasLoadingFallback =
1084
- parallelEntry.loading !== undefined &&
1085
- parallelEntry.loading !== false;
1086
- if (!shouldResolve) {
1087
- component = null;
1088
- } else if (hasLoadingFallback) {
1255
+ let component: ReactNode | undefined;
1256
+ let handlerRan = false;
1257
+ if (shouldResolve) {
1258
+ component = await tryStaticSlot(parallelEntry, slot, parallelId);
1259
+ }
1260
+ if (component === undefined) {
1261
+ const hasLoadingFallback =
1262
+ parallelEntry.loading !== undefined && parallelEntry.loading !== false;
1263
+ if (!shouldResolve) {
1264
+ component = null;
1265
+ } else if (handler === undefined) {
1266
+ // Handler evicted (production static slot) but static lookup missed.
1267
+ component = null;
1268
+ } else {
1269
+ // Slot-keyed pushes — see resolveParallelSegmentsWithRevalidation.
1270
+ (context as InternalHandlerContext<any, TEnv>)._currentSegmentId =
1271
+ parallelId;
1272
+ handlerRan = true;
1273
+ if (hasLoadingFallback) {
1089
1274
  const result =
1090
1275
  typeof handler === "function" ? handler(context) : handler;
1091
1276
  if (result instanceof Promise) {
@@ -1110,24 +1295,28 @@ export async function resolveOrphanLayoutWithRevalidation<TEnv>(
1110
1295
  typeof handler === "function" ? await handler(context) : handler;
1111
1296
  }
1112
1297
  }
1113
-
1114
- segments.push({
1115
- id: parallelId,
1116
- namespace: parallelEntry.id,
1117
- type: "parallel",
1118
- index: 0,
1119
- component,
1120
- loading: parallelEntry.loading === false ? null : parallelEntry.loading,
1121
- transition: parallelEntry.transition,
1122
- params,
1123
- slot,
1124
- belongsToRoute,
1125
- parallelName: `${parallelEntry.id}.${slot}`,
1126
- ...(parallelEntry.mountPath
1127
- ? { mountPath: parallelEntry.mountPath }
1128
- : {}),
1129
- });
1130
1298
  }
1299
+
1300
+ segments.push({
1301
+ id: parallelId,
1302
+ namespace: parallelEntry.id,
1303
+ type: "parallel",
1304
+ index: 0,
1305
+ component,
1306
+ loading: parallelEntry.loading === false ? null : parallelEntry.loading,
1307
+ transition: applyViewTransitionDefault(
1308
+ parallelEntry.transition,
1309
+ deps.viewTransitionDefault,
1310
+ ),
1311
+ params,
1312
+ slot,
1313
+ _handlerRan: handlerRan,
1314
+ belongsToRoute,
1315
+ parallelName: `${parallelEntry.id}.${slot}`,
1316
+ ...(parallelEntry.mountPath
1317
+ ? { mountPath: parallelEntry.mountPath }
1318
+ : {}),
1319
+ });
1131
1320
  }
1132
1321
 
1133
1322
  return { segments, matchedIds };
@@ -1152,6 +1341,7 @@ export async function resolveAllSegmentsWithRevalidation<TEnv>(
1152
1341
  localRouteName: string,
1153
1342
  pathname: string,
1154
1343
  deps: SegmentResolutionDeps<TEnv>,
1344
+ stale?: boolean,
1155
1345
  ): Promise<{ segments: ResolvedSegment[]; matchedIds: string[] }> {
1156
1346
  const allSegments: ResolvedSegment[] = [];
1157
1347
  const matchedIds: string[] = [];
@@ -1178,6 +1368,11 @@ export async function resolveAllSegmentsWithRevalidation<TEnv>(
1178
1368
  }
1179
1369
 
1180
1370
  const nonParallelEntry = entry as Exclude<EntryData, { type: "parallel" }>;
1371
+ if (entry.type === "cache") {
1372
+ const store = RangoContext.getStore();
1373
+ if (store) store.insideCacheScope = true;
1374
+ }
1375
+ const doneEntry = track(`segment:${entry.id}`, 1);
1181
1376
  const resolved = await resolveWithErrorBoundary(
1182
1377
  nonParallelEntry,
1183
1378
  params,
@@ -1195,15 +1390,14 @@ export async function resolveAllSegmentsWithRevalidation<TEnv>(
1195
1390
  loaderPromises,
1196
1391
  deps,
1197
1392
  actionContext,
1198
- false,
1393
+ stale,
1199
1394
  ),
1200
1395
  (seg) => ({ segments: [seg], matchedIds: [seg.id] }),
1201
1396
  deps,
1202
- telemetry
1203
- ? { request, url: context.url, routeKey, isPartial: true, telemetry }
1204
- : undefined,
1397
+ { request, url: context.url, routeKey, isPartial: true, telemetry },
1205
1398
  pathname,
1206
1399
  );
1400
+ doneEntry();
1207
1401
 
1208
1402
  // Deduplicate segments and matchedIds by ID, matching resolveAllSegments.
1209
1403
  // include() scopes can produce entries that resolve the same shared