@rangojs/router 0.0.0-experimental.debug-cache-fix → 0.0.0-experimental.dfdb0387

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 (115) hide show
  1. package/README.md +76 -18
  2. package/dist/bin/rango.js +130 -47
  3. package/dist/vite/index.js +702 -231
  4. package/package.json +2 -2
  5. package/skills/cache-guide/SKILL.md +32 -0
  6. package/skills/caching/SKILL.md +8 -0
  7. package/skills/links/SKILL.md +3 -1
  8. package/skills/loader/SKILL.md +53 -43
  9. package/skills/middleware/SKILL.md +2 -0
  10. package/skills/prerender/SKILL.md +110 -68
  11. package/skills/route/SKILL.md +31 -0
  12. package/skills/router-setup/SKILL.md +87 -2
  13. package/skills/typesafety/SKILL.md +10 -0
  14. package/src/__internal.ts +1 -1
  15. package/src/browser/app-version.ts +14 -0
  16. package/src/browser/navigation-bridge.ts +16 -3
  17. package/src/browser/navigation-client.ts +98 -46
  18. package/src/browser/navigation-store.ts +43 -8
  19. package/src/browser/partial-update.ts +32 -5
  20. package/src/browser/prefetch/cache.ts +16 -6
  21. package/src/browser/prefetch/fetch.ts +52 -6
  22. package/src/browser/prefetch/queue.ts +61 -29
  23. package/src/browser/prefetch/resource-ready.ts +77 -0
  24. package/src/browser/react/Link.tsx +67 -8
  25. package/src/browser/react/NavigationProvider.tsx +13 -4
  26. package/src/browser/react/context.ts +7 -2
  27. package/src/browser/react/use-handle.ts +9 -58
  28. package/src/browser/react/use-router.ts +21 -8
  29. package/src/browser/rsc-router.tsx +26 -3
  30. package/src/browser/scroll-restoration.ts +10 -8
  31. package/src/browser/segment-reconciler.ts +26 -0
  32. package/src/browser/server-action-bridge.ts +8 -6
  33. package/src/browser/types.ts +27 -5
  34. package/src/build/generate-manifest.ts +6 -6
  35. package/src/build/generate-route-types.ts +3 -0
  36. package/src/build/route-types/include-resolution.ts +8 -1
  37. package/src/build/route-types/router-processing.ts +211 -72
  38. package/src/build/route-types/scan-filter.ts +8 -1
  39. package/src/cache/cache-scope.ts +12 -14
  40. package/src/cache/taint.ts +55 -0
  41. package/src/client.tsx +2 -56
  42. package/src/context-var.ts +72 -2
  43. package/src/handle.ts +40 -0
  44. package/src/index.rsc.ts +3 -1
  45. package/src/index.ts +12 -0
  46. package/src/prerender/store.ts +5 -4
  47. package/src/prerender.ts +138 -77
  48. package/src/reverse.ts +22 -1
  49. package/src/route-definition/dsl-helpers.ts +42 -19
  50. package/src/route-definition/helpers-types.ts +10 -6
  51. package/src/route-definition/index.ts +3 -0
  52. package/src/route-definition/redirect.ts +9 -1
  53. package/src/route-definition/resolve-handler-use.ts +149 -0
  54. package/src/route-types.ts +11 -0
  55. package/src/router/content-negotiation.ts +100 -1
  56. package/src/router/handler-context.ts +79 -23
  57. package/src/router/intercept-resolution.ts +9 -4
  58. package/src/router/loader-resolution.ts +156 -21
  59. package/src/router/match-api.ts +124 -189
  60. package/src/router/match-middleware/cache-lookup.ts +26 -7
  61. package/src/router/match-middleware/segment-resolution.ts +53 -0
  62. package/src/router/match-result.ts +82 -4
  63. package/src/router/middleware-types.ts +6 -8
  64. package/src/router/middleware.ts +2 -5
  65. package/src/router/navigation-snapshot.ts +182 -0
  66. package/src/router/prerender-match.ts +110 -10
  67. package/src/router/preview-match.ts +30 -102
  68. package/src/router/request-classification.ts +310 -0
  69. package/src/router/route-snapshot.ts +245 -0
  70. package/src/router/router-interfaces.ts +36 -4
  71. package/src/router/router-options.ts +37 -11
  72. package/src/router/segment-resolution/fresh.ts +80 -9
  73. package/src/router/segment-resolution/helpers.ts +29 -24
  74. package/src/router/segment-resolution/revalidation.ts +91 -8
  75. package/src/router/types.ts +1 -0
  76. package/src/router.ts +54 -5
  77. package/src/rsc/handler.ts +472 -372
  78. package/src/rsc/loader-fetch.ts +23 -3
  79. package/src/rsc/manifest-init.ts +5 -1
  80. package/src/rsc/progressive-enhancement.ts +14 -2
  81. package/src/rsc/rsc-rendering.ts +10 -1
  82. package/src/rsc/server-action.ts +8 -0
  83. package/src/rsc/ssr-setup.ts +2 -2
  84. package/src/rsc/types.ts +9 -1
  85. package/src/server/context.ts +50 -1
  86. package/src/server/handle-store.ts +19 -0
  87. package/src/server/loader-registry.ts +9 -8
  88. package/src/server/request-context.ts +175 -15
  89. package/src/ssr/index.tsx +3 -0
  90. package/src/static-handler.ts +18 -6
  91. package/src/types/cache-types.ts +4 -4
  92. package/src/types/handler-context.ts +37 -19
  93. package/src/types/loader-types.ts +36 -9
  94. package/src/types/route-entry.ts +1 -1
  95. package/src/types/segments.ts +1 -0
  96. package/src/urls/path-helper-types.ts +9 -2
  97. package/src/urls/path-helper.ts +47 -12
  98. package/src/urls/pattern-types.ts +12 -0
  99. package/src/urls/response-types.ts +16 -6
  100. package/src/use-loader.tsx +77 -5
  101. package/src/vite/discovery/bundle-postprocess.ts +30 -33
  102. package/src/vite/discovery/discover-routers.ts +5 -1
  103. package/src/vite/discovery/prerender-collection.ts +128 -74
  104. package/src/vite/discovery/state.ts +13 -4
  105. package/src/vite/index.ts +4 -0
  106. package/src/vite/plugin-types.ts +60 -5
  107. package/src/vite/plugins/expose-id-utils.ts +12 -0
  108. package/src/vite/plugins/expose-ids/handler-transform.ts +30 -0
  109. package/src/vite/plugins/expose-internal-ids.ts +257 -40
  110. package/src/vite/plugins/performance-tracks.ts +88 -0
  111. package/src/vite/plugins/refresh-cmd.ts +88 -26
  112. package/src/vite/rango.ts +19 -2
  113. package/src/vite/router-discovery.ts +178 -37
  114. package/src/vite/utils/prerender-utils.ts +18 -0
  115. package/src/vite/utils/shared-utils.ts +3 -2
@@ -36,7 +36,14 @@ import {
36
36
  setRequestContextPrevRouteKey,
37
37
  } from "../server/request-context.js";
38
38
  import { isAutoGeneratedRouteName } from "../route-name.js";
39
+ import type { DefaultRouteName } from "../types/global-namespace.js";
39
40
  import { debugLog, debugWarn } from "./logging.js";
41
+ import {
42
+ resolveRoute,
43
+ ensureFullRouteSnapshot,
44
+ type RouteSnapshot,
45
+ } from "./route-snapshot.js";
46
+ import { resolveNavigation } from "./navigation-snapshot.js";
40
47
 
41
48
  /**
42
49
  * Create match context for full requests (document/SSR).
@@ -52,57 +59,36 @@ export async function createMatchContextForFull<TEnv>(
52
59
 
53
60
  const metricsStore = deps.getMetricsStore();
54
61
 
55
- const routeMatchStart = metricsStore ? performance.now() : 0;
56
- const matched = deps.findMatch(pathname, metricsStore);
57
- if (metricsStore) {
58
- metricsStore.metrics.push({
59
- label: "route-matching",
60
- duration: performance.now() - routeMatchStart,
61
- startTime: routeMatchStart - metricsStore.requestStart,
62
- });
63
- }
62
+ // Full renders always resolve fresh with isSSR: true because loadManifest
63
+ // keys its cache on isSSR and stamps Store.isSSR for downstream behavior.
64
+ const result = await resolveRoute<TEnv>(pathname, {
65
+ findMatch: (p) => deps.findMatch(p, metricsStore),
66
+ metricsStore,
67
+ isSSR: true,
68
+ });
64
69
 
65
- if (!matched) {
70
+ if (!result) {
66
71
  throw new RouteNotFoundError(`No route matched for ${pathname}`, {
67
72
  cause: { pathname, method: request.method },
68
73
  });
69
74
  }
70
75
 
71
- if (matched.redirectTo) {
76
+ if (result.type === "redirect") {
72
77
  return {
73
78
  type: "redirect",
74
- redirectUrl: matched.redirectTo + url.search,
79
+ redirectUrl: result.redirectTo + url.search,
75
80
  };
76
81
  }
77
82
 
78
- const manifestStart = metricsStore ? performance.now() : 0;
79
- const manifestEntry = await loadManifest(
80
- matched.entry,
81
- matched.routeKey,
82
- pathname,
83
- metricsStore,
84
- true,
85
- );
86
- if (metricsStore) {
87
- metricsStore.metrics.push({
88
- label: "manifest-loading",
89
- duration: performance.now() - manifestStart,
90
- startTime: manifestStart - metricsStore.requestStart,
91
- });
92
- }
83
+ const snapshot = result.snapshot;
93
84
 
94
- if (
95
- manifestEntry.type === "route" &&
96
- manifestEntry.prerenderDef?.options?.passthrough === true
97
- ) {
85
+ const { matched } = snapshot;
86
+
87
+ // Backward compat: downstream middleware reads matched.pt
88
+ if (snapshot.isPassthrough) {
98
89
  matched.pt = true;
99
90
  }
100
91
 
101
- const routeMiddleware = collectRouteMiddleware(
102
- traverseBack(manifestEntry),
103
- matched.params,
104
- );
105
-
106
92
  // Clean URL without internal _rsc* params for userland access
107
93
  const cleanUrl = stripInternalParams(url);
108
94
 
@@ -134,14 +120,6 @@ export async function createMatchContextForFull<TEnv>(
134
120
  Store.metrics = metricsStore;
135
121
  }
136
122
 
137
- const entries = [...traverseBack(manifestEntry)];
138
- let cacheScope: CacheScope | null = null;
139
- for (const entry of entries) {
140
- if (entry.cache) {
141
- cacheScope = createCacheScope(entry.cache, cacheScope);
142
- }
143
- }
144
-
145
123
  return {
146
124
  request,
147
125
  url: cleanUrl,
@@ -154,12 +132,10 @@ export async function createMatchContextForFull<TEnv>(
154
132
  prevParams: {},
155
133
  prevMatch: null,
156
134
  matched,
157
- manifestEntry,
158
- entries,
135
+ manifestEntry: snapshot.manifestEntry,
136
+ entries: snapshot.entries,
159
137
  routeKey: matched.routeKey,
160
- localRouteName: matched.routeKey.includes(".")
161
- ? matched.routeKey.split(".").pop()!
162
- : matched.routeKey,
138
+ localRouteName: snapshot.localRouteName,
163
139
  handlerContext,
164
140
  loaderPromises,
165
141
  routeMap: deps.getRouteMap(),
@@ -175,16 +151,16 @@ export async function createMatchContextForFull<TEnv>(
175
151
  segments: { path: [], ids: [] },
176
152
  toRouteName:
177
153
  matched.routeKey && !isAutoGeneratedRouteName(matched.routeKey)
178
- ? matched.routeKey
154
+ ? (matched.routeKey as DefaultRouteName)
179
155
  : undefined,
180
156
  },
181
157
  isSameRouteNavigation: false,
182
158
  interceptResult: null,
183
- cacheScope,
159
+ cacheScope: snapshot.cacheScope,
184
160
  isIntercept: false,
185
161
  actionContext: undefined,
186
162
  isAction: false,
187
- routeMiddleware,
163
+ routeMiddleware: snapshot.routeMiddleware,
188
164
  isFullMatch: true,
189
165
  };
190
166
  }
@@ -204,103 +180,85 @@ export async function createMatchContextForPartial<TEnv>(
204
180
 
205
181
  const metricsStore = deps.getMetricsStore();
206
182
 
207
- const clientSegmentIds =
208
- url.searchParams.get("_rsc_segments")?.split(",").filter(Boolean) || [];
209
- const stale = url.searchParams.get("_rsc_stale") === "true";
210
- const previousUrl =
211
- request.headers.get("X-RSC-Router-Client-Path") ||
212
- request.headers.get("Referer");
213
- const interceptSourceUrl = request.headers.get(
214
- "X-RSC-Router-Intercept-Source",
215
- );
183
+ const isHmr = !!request.headers.get("X-RSC-HMR");
216
184
 
217
185
  // HMR: clear manifest cache so stale handler references are discarded
218
- if (request.headers.get("X-RSC-HMR")) {
186
+ if (isHmr) {
219
187
  clearManifestCache();
220
188
  }
221
189
 
222
- if (!previousUrl) {
223
- return null;
224
- }
225
-
226
- let prevUrl: URL;
227
- try {
228
- prevUrl = new URL(previousUrl, url.origin);
229
- } catch {
230
- return null;
231
- }
190
+ // Reuse the classified snapshot when available and not invalidated by HMR.
191
+ // classifyRequest already called resolveRoute(lite) with isSSR=false, which
192
+ // matches the partial path. On HMR, discard to pick up manifest changes.
193
+ const classifiedRoute = isHmr
194
+ ? undefined
195
+ : getRequestContext()?._classifiedRoute;
196
+
197
+ // Time route matching. On the reuse path, only nav findMatch calls are new
198
+ // (current-route findMatch and manifest-loading were already timed during
199
+ // classifyRequest via its metricsStore). On the fresh path, all findMatch
200
+ // calls are measured together.
201
+ const routeMatchStart = metricsStore ? performance.now() : 0;
232
202
 
233
- let interceptContextUrl: URL;
234
- try {
235
- interceptContextUrl = interceptSourceUrl
236
- ? new URL(interceptSourceUrl, url.origin)
237
- : prevUrl;
238
- } catch {
239
- interceptContextUrl = prevUrl;
240
- }
203
+ let snapshot: RouteSnapshot<TEnv>;
204
+ if (classifiedRoute && classifiedRoute.manifestEntry) {
205
+ snapshot = ensureFullRouteSnapshot(classifiedRoute);
206
+ } else {
207
+ const result = await resolveRoute<TEnv>(pathname, {
208
+ findMatch: (p) => deps.findMatch(p, metricsStore),
209
+ metricsStore,
210
+ isSSR: false,
211
+ skipRouteMatchMetric: true,
212
+ });
241
213
 
242
- const routeMatchStart = metricsStore ? performance.now() : 0;
243
- const prevMatch = deps.findMatch(prevUrl.pathname);
244
- const prevParams = prevMatch?.params || {};
245
- const interceptContextMatch = interceptSourceUrl
246
- ? deps.findMatch(interceptContextUrl.pathname)
247
- : prevMatch;
214
+ if (!result) {
215
+ throw new RouteNotFoundError(`No route matched for ${pathname}`, {
216
+ cause: { pathname, method: request.method },
217
+ });
218
+ }
248
219
 
249
- const matched = deps.findMatch(pathname, metricsStore);
220
+ if (result.type === "redirect") {
221
+ return null;
222
+ }
250
223
 
251
- if (metricsStore) {
252
- metricsStore.metrics.push({
253
- label: "route-matching",
254
- duration: performance.now() - routeMatchStart,
255
- startTime: routeMatchStart - metricsStore.requestStart,
256
- });
224
+ snapshot = result.snapshot;
257
225
  }
258
226
 
259
- if (!matched) {
260
- throw new RouteNotFoundError(`No route matched for ${pathname}`, {
261
- cause: { pathname, method: request.method, previousUrl },
262
- });
263
- }
227
+ const { matched } = snapshot;
264
228
 
265
- if (matched.redirectTo) {
266
- return null;
229
+ // Backward compat: downstream middleware reads matched.pt
230
+ if (snapshot.isPassthrough) {
231
+ matched.pt = true;
267
232
  }
268
233
 
269
- if (prevMatch && prevMatch.entry !== matched.entry && !matched.pr) {
270
- debugLog("matchPartial", "route group changed", {
271
- from: prevMatch.routeKey,
272
- to: matched.routeKey,
273
- });
234
+ // Navigation state (prev + intercept-source findMatch calls)
235
+ const nav = resolveNavigation(request, url, matched.routeKey, {
236
+ findMatch: deps.findMatch,
237
+ });
238
+ if (!nav) {
239
+ return null;
274
240
  }
275
241
 
276
- const manifestStart = metricsStore ? performance.now() : 0;
277
- const manifestEntry = await loadManifest(
278
- matched.entry,
279
- matched.routeKey,
280
- pathname,
281
- metricsStore,
282
- false,
283
- );
242
+ // Push route-matching metric. On the fresh path this covers all findMatch
243
+ // calls (current + prev + intercept-source). On the reuse path, current-route
244
+ // findMatch was already timed during classification, so this only covers
245
+ // the nav lookups (prev + intercept-source).
284
246
  if (metricsStore) {
247
+ const isReuse = !!classifiedRoute;
285
248
  metricsStore.metrics.push({
286
- label: "manifest-loading",
287
- duration: performance.now() - manifestStart,
288
- startTime: manifestStart - metricsStore.requestStart,
249
+ label: isReuse ? "route-matching:nav" : "route-matching",
250
+ duration: performance.now() - routeMatchStart,
251
+ startTime: routeMatchStart - metricsStore.requestStart,
289
252
  });
290
253
  }
291
254
 
292
- if (
293
- manifestEntry.type === "route" &&
294
- manifestEntry.prerenderDef?.options?.passthrough === true
295
- ) {
296
- matched.pt = true;
255
+ if (nav.prevMatch && nav.prevMatch.entry !== matched.entry && !matched.pr) {
256
+ debugLog("matchPartial", "route group changed", {
257
+ from: nav.prevMatch.routeKey,
258
+ to: matched.routeKey,
259
+ });
297
260
  }
298
261
 
299
- const routeMiddleware = collectRouteMiddleware(
300
- traverseBack(manifestEntry),
301
- matched.params,
302
- );
303
-
304
262
  // Clean URL without internal _rsc* params for userland access
305
263
  const cleanUrl = stripInternalParams(url);
306
264
 
@@ -317,9 +275,8 @@ export async function createMatchContextForPartial<TEnv>(
317
275
  matched.pt === true,
318
276
  );
319
277
 
320
- const clientSegmentSet = new Set(clientSegmentIds);
321
278
  debugLog("matchPartial", "client segments", {
322
- segments: Array.from(clientSegmentSet),
279
+ segments: Array.from(nav.clientSegmentSet),
323
280
  });
324
281
 
325
282
  const loaderPromises = new Map<string, Promise<any>>();
@@ -337,100 +294,78 @@ export async function createMatchContextForPartial<TEnv>(
337
294
  Store.metrics = metricsStore;
338
295
  }
339
296
 
340
- const isSameRouteNavigation = !!(
341
- interceptContextMatch && interceptContextMatch.routeKey === matched.routeKey
342
- );
343
-
344
- if (interceptSourceUrl) {
297
+ if (nav.hasInterceptSource) {
345
298
  debugLog("matchPartial.intercept", "intercept context detected", {
346
299
  currentUrl: pathname,
347
- interceptSource: interceptSourceUrl,
348
- contextRoute: interceptContextMatch?.routeKey,
300
+ interceptSource: nav.interceptContextUrl.href,
301
+ contextRoute: nav.interceptContextMatch?.routeKey,
349
302
  currentRoute: matched.routeKey,
350
- sameRouteNavigation: isSameRouteNavigation,
303
+ sameRouteNavigation: nav.isSameRouteNavigation,
351
304
  });
352
305
  }
353
306
 
354
- const localRouteName = matched.routeKey.includes(".")
355
- ? matched.routeKey.split(".").pop()!
356
- : matched.routeKey;
357
-
358
- const filteredSegmentIds = clientSegmentIds.filter((id) => {
359
- if (id.includes(".@")) return false;
360
- if (/D\d+\./.test(id)) return false;
361
- return true;
362
- });
363
- const effectiveFromUrl = interceptSourceUrl ? interceptContextUrl : prevUrl;
364
- const effectiveFromMatch = interceptSourceUrl
365
- ? interceptContextMatch
366
- : prevMatch;
367
-
368
307
  // Store previous route key on the request context for revalidation
369
308
  // fromRouteName. Uses effectiveFromMatch so intercept-source navigations
370
309
  // see the intercept origin route, not the plain previous URL route.
371
- setRequestContextPrevRouteKey(effectiveFromMatch?.routeKey);
310
+ setRequestContextPrevRouteKey(nav.effectiveFromMatch?.routeKey);
372
311
 
373
312
  const interceptSelectorContext: InterceptSelectorContext = {
374
- from: effectiveFromUrl,
313
+ from: nav.effectiveFromUrl,
375
314
  to: cleanUrl,
376
315
  params: matched.params,
377
316
  request,
378
317
  env,
379
318
  segments: {
380
- path: effectiveFromUrl.pathname.split("/").filter(Boolean),
381
- ids: filteredSegmentIds,
319
+ path: nav.effectiveFromUrl.pathname.split("/").filter(Boolean),
320
+ ids: nav.filteredSegmentIds,
382
321
  },
383
322
  fromRouteName:
384
- effectiveFromMatch?.routeKey &&
385
- !isAutoGeneratedRouteName(effectiveFromMatch.routeKey)
386
- ? effectiveFromMatch.routeKey
323
+ nav.effectiveFromMatch?.routeKey &&
324
+ !isAutoGeneratedRouteName(nav.effectiveFromMatch.routeKey)
325
+ ? (nav.effectiveFromMatch.routeKey as DefaultRouteName)
387
326
  : undefined,
388
327
  toRouteName:
389
328
  matched.routeKey && !isAutoGeneratedRouteName(matched.routeKey)
390
- ? matched.routeKey
329
+ ? (matched.routeKey as DefaultRouteName)
391
330
  : undefined,
392
331
  };
393
332
  const isAction = !!actionContext;
394
333
 
395
- const clientHasInterceptSegments = [...clientSegmentSet].some((id) =>
334
+ const clientHasInterceptSegments = [...nav.clientSegmentSet].some((id) =>
396
335
  id.includes(".@"),
397
336
  );
398
337
  const skipInterceptForAction = isAction && !clientHasInterceptSegments;
399
338
  const interceptResult =
400
- isSameRouteNavigation || skipInterceptForAction
339
+ nav.isSameRouteNavigation || skipInterceptForAction
401
340
  ? null
402
341
  : findInterceptForRoute(
403
342
  matched.routeKey,
404
- manifestEntry.parent,
343
+ snapshot.manifestEntry.parent,
405
344
  interceptSelectorContext,
406
345
  isAction,
407
346
  ) ||
408
- (localRouteName !== matched.routeKey
347
+ (snapshot.localRouteName !== matched.routeKey
409
348
  ? findInterceptForRoute(
410
- localRouteName,
411
- manifestEntry.parent,
349
+ snapshot.localRouteName,
350
+ snapshot.manifestEntry.parent,
412
351
  interceptSelectorContext,
413
352
  isAction,
414
353
  )
415
354
  : null);
416
355
 
356
+ // Make a mutable copy of clientSegmentSet so we can delete entries
357
+ // for same-route navigation forcing
358
+ const clientSegmentSet = new Set(nav.clientSegmentSet);
359
+
417
360
  if (
418
- isSameRouteNavigation &&
419
- manifestEntry.type === "route" &&
420
- interceptSourceUrl
361
+ nav.isSameRouteNavigation &&
362
+ snapshot.manifestEntry.type === "route" &&
363
+ nav.hasInterceptSource
421
364
  ) {
422
365
  debugLog("matchPartial.intercept", "forcing route segment render", {
423
- segmentId: manifestEntry.shortCode,
366
+ segmentId: snapshot.manifestEntry.shortCode,
424
367
  });
425
- clientSegmentSet.delete(manifestEntry.shortCode);
426
- }
427
-
428
- const entries = [...traverseBack(manifestEntry)];
429
- let cacheScope: CacheScope | null = null;
430
- for (const entry of entries) {
431
- if (entry.cache) {
432
- cacheScope = createCacheScope(entry.cache, cacheScope);
433
- }
368
+ clientSegmentSet.delete(snapshot.manifestEntry.shortCode);
434
369
  }
435
370
 
436
371
  const isIntercept = !!interceptResult;
@@ -440,31 +375,31 @@ export async function createMatchContextForPartial<TEnv>(
440
375
  url: cleanUrl,
441
376
  pathname,
442
377
  env,
443
- clientSegmentIds,
378
+ clientSegmentIds: nav.clientSegmentIds,
444
379
  clientSegmentSet,
445
- stale,
446
- prevUrl,
447
- prevParams,
448
- prevMatch,
380
+ stale: nav.stale,
381
+ prevUrl: nav.prevUrl,
382
+ prevParams: nav.prevParams,
383
+ prevMatch: nav.prevMatch,
449
384
  matched,
450
- manifestEntry,
451
- entries,
385
+ manifestEntry: snapshot.manifestEntry,
386
+ entries: snapshot.entries,
452
387
  routeKey: matched.routeKey,
453
- localRouteName,
388
+ localRouteName: snapshot.localRouteName,
454
389
  handlerContext,
455
390
  loaderPromises,
456
391
  routeMap: deps.getRouteMap(),
457
392
  metricsStore,
458
393
  Store,
459
- interceptContextMatch,
394
+ interceptContextMatch: nav.interceptContextMatch,
460
395
  interceptSelectorContext,
461
- isSameRouteNavigation,
396
+ isSameRouteNavigation: nav.isSameRouteNavigation,
462
397
  interceptResult,
463
- cacheScope,
398
+ cacheScope: snapshot.cacheScope,
464
399
  isIntercept,
465
400
  actionContext,
466
401
  isAction,
467
- routeMiddleware,
402
+ routeMiddleware: snapshot.routeMiddleware,
468
403
  isFullMatch: false,
469
404
  };
470
405
  }
@@ -96,6 +96,7 @@ import type { MatchContext, MatchPipelineState } from "../match-context.js";
96
96
  import { getRouterContext } from "../router-context.js";
97
97
  import { resolveSink, safeEmit } from "../telemetry.js";
98
98
  import { pushRevalidationTraceEntry, isTraceActive } from "../logging.js";
99
+ import { treeHasStreaming } from "./segment-resolution.js";
99
100
  import type { PrerenderStore, PrerenderEntry } from "../../prerender/store.js";
100
101
  import type { HandleStore } from "../../server/handle-store.js";
101
102
  import {
@@ -193,6 +194,16 @@ async function* yieldFromStore<TEnv>(
193
194
  state.cachedSegments = segments;
194
195
  state.cachedMatchedIds = segments.map((s) => s.id);
195
196
 
197
+ // Set streaming flag (once) and resolve render barrier.
198
+ const reqCtx = handleStoreRef ? undefined : _lazyGetRequestContext?.();
199
+ const barrierReqCtx = reqCtx ?? _getRequestContext();
200
+ if (barrierReqCtx) {
201
+ if (barrierReqCtx._treeHasStreaming === undefined) {
202
+ barrierReqCtx._treeHasStreaming = treeHasStreaming(ctx.entries);
203
+ }
204
+ barrierReqCtx._resolveRenderBarrier(segments);
205
+ }
206
+
196
207
  // For partial navigation, nullify components the client already has
197
208
  // so parent layouts stay live (client keeps its existing versions).
198
209
  // When params changed (e.g., different guide slug), the segments have
@@ -316,14 +327,15 @@ export function withCacheLookup<TEnv>(
316
327
 
317
328
  // Prerender lookup: check build-time cached data before runtime cache.
318
329
  // Prerender data is available regardless of runtime cache configuration.
319
- if (!ctx.isAction && ctx.matched.pr) {
330
+ // Skip for HMR requests — the dev prerender endpoint reads from a stale
331
+ // RouterRegistry snapshot; rendering fresh ensures edits are visible.
332
+ const isHmr = !!ctx.request.headers.get("X-RSC-HMR");
333
+ if (!ctx.isAction && !isHmr && ctx.matched.pr) {
320
334
  await ensurePrerenderDeps();
321
335
  if (prerenderStoreInstance) {
322
336
  const paramHash = _hashParams!(ctx.matched.params);
323
337
  const isPassthroughPrerenderRoute = ctx.entries.some(
324
- (entry) =>
325
- entry.type === "route" &&
326
- entry.prerenderDef?.options?.passthrough === true,
338
+ (entry) => entry.type === "route" && entry.isPassthrough === true,
327
339
  );
328
340
 
329
341
  if (ctx.isIntercept) {
@@ -393,9 +405,7 @@ export function withCacheLookup<TEnv>(
393
405
  if (prerenderStoreInstance) {
394
406
  const paramHash = _hashParams!(ctx.matched.params);
395
407
  const isPassthroughPrerenderRoute = ctx.entries.some(
396
- (entry) =>
397
- entry.type === "route" &&
398
- entry.prerenderDef?.options?.passthrough === true,
408
+ (entry) => entry.type === "route" && entry.isPassthrough === true,
399
409
  );
400
410
 
401
411
  if (ctx.isIntercept) {
@@ -615,6 +625,15 @@ export function withCacheLookup<TEnv>(
615
625
  yield segment;
616
626
  }
617
627
 
628
+ // Set streaming flag (once) and resolve render barrier.
629
+ const barrierReqCtx = _getRequestContext();
630
+ if (barrierReqCtx) {
631
+ if (barrierReqCtx._treeHasStreaming === undefined) {
632
+ barrierReqCtx._treeHasStreaming = treeHasStreaming(ctx.entries);
633
+ }
634
+ barrierReqCtx._resolveRenderBarrier(cacheResult.segments);
635
+ }
636
+
618
637
  // Resolve loaders fresh (loaders are NOT cached by default)
619
638
  // This ensures fresh data even on cache hit
620
639
  const Store = ctx.Store;
@@ -87,10 +87,49 @@
87
87
  * if (state.cacheHit) return; // Now we can check
88
88
  */
89
89
  import type { ResolvedSegment } from "../../types.js";
90
+ import type { EntryData } from "../../server/context.js";
91
+ import { _getRequestContext } from "../../server/request-context.js";
90
92
  import type { MatchContext, MatchPipelineState } from "../match-context.js";
91
93
  import { getRouterContext } from "../router-context.js";
92
94
  import type { GeneratorMiddleware } from "./cache-lookup.js";
93
95
 
96
+ /**
97
+ * Check whether any entry in the tree uses loading() (streaming).
98
+ * Matches the router's streaming semantics in fresh.ts: streaming is
99
+ * enabled when `loading` is defined AND not `false`. `loading: false`
100
+ * explicitly disables streaming; `undefined` means no loading at all.
101
+ */
102
+ export function treeHasStreaming(entries: EntryData[]): boolean {
103
+ for (const entry of entries) {
104
+ if (
105
+ "loading" in entry &&
106
+ entry.loading !== undefined &&
107
+ entry.loading !== false
108
+ )
109
+ return true;
110
+ if (entry.layout) {
111
+ if (treeHasStreaming(entry.layout)) return true;
112
+ }
113
+ if (entry.parallel) {
114
+ for (const key in entry.parallel) {
115
+ const parallelEntry = entry.parallel[key as `@${string}`];
116
+ if (parallelEntry) {
117
+ if (
118
+ "loading" in parallelEntry &&
119
+ parallelEntry.loading !== undefined &&
120
+ parallelEntry.loading !== false
121
+ )
122
+ return true;
123
+ if (parallelEntry.layout) {
124
+ if (treeHasStreaming(parallelEntry.layout)) return true;
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+ return false;
131
+ }
132
+
94
133
  /**
95
134
  * Creates segment resolution middleware
96
135
  *
@@ -116,6 +155,7 @@ export function withSegmentResolution<TEnv>(
116
155
  const ownStart = performance.now();
117
156
 
118
157
  // If cache hit, segments were already yielded by cache lookup
158
+ // (render barrier is resolved on the cache-hit path)
119
159
  if (state.cacheHit) {
120
160
  if (ms) {
121
161
  ms.metrics.push({
@@ -127,6 +167,11 @@ export function withSegmentResolution<TEnv>(
127
167
  return;
128
168
  }
129
169
 
170
+ const reqCtx = _getRequestContext();
171
+ if (reqCtx && reqCtx._treeHasStreaming === undefined) {
172
+ reqCtx._treeHasStreaming = treeHasStreaming(ctx.entries);
173
+ }
174
+
130
175
  const { resolveAllSegmentsWithRevalidation, resolveAllSegments } =
131
176
  getRouterContext<TEnv>();
132
177
 
@@ -148,6 +193,10 @@ export function withSegmentResolution<TEnv>(
148
193
  state.segments = segments;
149
194
  state.matchedIds = segments.map((s: { id: string }) => s.id);
150
195
 
196
+ if (reqCtx) {
197
+ reqCtx._resolveRenderBarrier(segments);
198
+ }
199
+
151
200
  // Yield all resolved segments
152
201
  for (const segment of segments) {
153
202
  yield segment;
@@ -178,6 +227,10 @@ export function withSegmentResolution<TEnv>(
178
227
  state.segments = result.segments;
179
228
  state.matchedIds = result.matchedIds;
180
229
 
230
+ if (reqCtx) {
231
+ reqCtx._resolveRenderBarrier(result.segments);
232
+ }
233
+
181
234
  // Yield all resolved segments
182
235
  for (const segment of result.segments) {
183
236
  yield segment;