@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.
- package/AGENTS.md +4 -0
- package/README.md +242 -55
- package/dist/bin/rango.js +277 -99
- package/dist/vite/index.js +2929 -1132
- package/dist/vite/index.js.bak +5448 -0
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +68 -21
- package/skills/breadcrumbs/SKILL.md +252 -0
- package/skills/bundle-analysis/SKILL.md +159 -0
- package/skills/cache-guide/SKILL.md +243 -21
- package/skills/caching/SKILL.md +159 -10
- package/skills/composability/SKILL.md +27 -2
- package/skills/document-cache/SKILL.md +78 -55
- package/skills/handler-use/SKILL.md +364 -0
- package/skills/hooks/SKILL.md +262 -51
- package/skills/host-router/SKILL.md +243 -0
- package/skills/i18n/SKILL.md +276 -0
- package/skills/intercept/SKILL.md +46 -4
- package/skills/layout/SKILL.md +28 -7
- package/skills/links/SKILL.md +249 -17
- package/skills/loader/SKILL.md +291 -31
- package/skills/middleware/SKILL.md +49 -12
- package/skills/migrate-nextjs/SKILL.md +562 -0
- package/skills/migrate-react-router/SKILL.md +769 -0
- package/skills/mime-routes/SKILL.md +27 -0
- package/skills/observability/SKILL.md +137 -0
- package/skills/parallel/SKILL.md +197 -6
- package/skills/prerender/SKILL.md +125 -102
- package/skills/rango/SKILL.md +242 -23
- package/skills/react-compiler/SKILL.md +168 -0
- package/skills/response-routes/SKILL.md +66 -9
- package/skills/route/SKILL.md +91 -8
- package/skills/router-setup/SKILL.md +98 -8
- package/skills/server-actions/SKILL.md +751 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/testing/SKILL.md +511 -188
- package/skills/typesafety/SKILL.md +354 -50
- package/skills/use-cache/SKILL.md +34 -5
- package/skills/view-transitions/SKILL.md +294 -0
- package/src/__augment-tests__/augment.ts +81 -0
- package/src/__augment-tests__/augmented.check.ts +117 -0
- package/src/__internal.ts +92 -0
- package/src/browser/action-coordinator.ts +53 -36
- package/src/browser/app-shell.ts +52 -0
- package/src/browser/app-version.ts +14 -0
- package/src/browser/event-controller.ts +91 -70
- package/src/browser/history-state.ts +21 -0
- package/src/browser/index.ts +3 -3
- package/src/browser/link-interceptor.ts +4 -0
- package/src/browser/navigation-bridge.ts +183 -18
- package/src/browser/navigation-client.ts +187 -57
- package/src/browser/navigation-store.ts +75 -17
- package/src/browser/navigation-transaction.ts +21 -37
- package/src/browser/partial-update.ts +143 -40
- package/src/browser/prefetch/cache.ts +275 -28
- package/src/browser/prefetch/fetch.ts +191 -46
- package/src/browser/prefetch/policy.ts +6 -0
- package/src/browser/prefetch/queue.ts +123 -20
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/rango-state.ts +53 -13
- package/src/browser/react/Link.tsx +98 -14
- package/src/browser/react/NavigationProvider.tsx +110 -33
- package/src/browser/react/context.ts +7 -2
- package/src/browser/react/filter-segment-order.ts +51 -7
- package/src/browser/react/index.ts +3 -0
- package/src/browser/react/location-state-shared.ts +175 -4
- package/src/browser/react/location-state.ts +39 -13
- package/src/browser/react/use-handle.ts +23 -64
- package/src/browser/react/use-navigation.ts +22 -2
- package/src/browser/react/use-params.ts +20 -8
- package/src/browser/react/use-reverse.ts +106 -0
- package/src/browser/react/use-router.ts +43 -10
- package/src/browser/react/use-segments.ts +11 -8
- package/src/browser/response-adapter.ts +25 -0
- package/src/browser/rsc-router.tsx +200 -75
- package/src/browser/scroll-restoration.ts +46 -39
- package/src/browser/segment-reconciler.ts +36 -9
- package/src/browser/segment-structure-assert.ts +2 -2
- package/src/browser/server-action-bridge.ts +31 -36
- package/src/browser/types.ts +81 -5
- package/src/build/collect-fallback-refs.ts +107 -0
- package/src/build/generate-manifest.ts +65 -40
- package/src/build/generate-route-types.ts +5 -0
- package/src/build/index.ts +2 -0
- package/src/build/route-trie.ts +69 -26
- package/src/build/route-types/codegen.ts +4 -4
- package/src/build/route-types/include-resolution.ts +9 -2
- package/src/build/route-types/per-module-writer.ts +7 -4
- package/src/build/route-types/router-processing.ts +278 -88
- package/src/build/route-types/scan-filter.ts +9 -2
- package/src/build/route-types/source-scan.ts +118 -0
- package/src/build/runtime-discovery.ts +9 -20
- package/src/cache/cache-runtime.ts +15 -11
- package/src/cache/cache-scope.ts +76 -49
- package/src/cache/cf/cf-cache-store.ts +501 -18
- package/src/cache/cf/index.ts +5 -1
- package/src/cache/document-cache.ts +17 -7
- package/src/cache/index.ts +1 -0
- package/src/cache/taint.ts +55 -0
- package/src/client.rsc.tsx +5 -1
- package/src/client.tsx +95 -284
- package/src/context-var.ts +72 -2
- package/src/debug.ts +2 -2
- package/src/decode-loader-results.ts +36 -0
- package/src/errors.ts +30 -1
- package/src/handle.ts +65 -12
- package/src/handles/breadcrumbs.ts +66 -0
- package/src/handles/index.ts +1 -0
- package/src/host/index.ts +2 -5
- package/src/host/router.ts +129 -57
- package/src/host/types.ts +31 -2
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +140 -20
- package/src/index.rsc.ts +15 -40
- package/src/index.ts +92 -76
- package/src/loader-store.ts +500 -0
- package/src/loader.rsc.ts +2 -5
- package/src/loader.ts +3 -10
- package/src/missing-id-error.ts +68 -0
- package/src/outlet-context.ts +1 -1
- package/src/prerender/store.ts +57 -15
- package/src/prerender.ts +141 -80
- package/src/response-utils.ts +37 -0
- package/src/reverse.ts +65 -15
- package/src/route-content-wrapper.tsx +6 -28
- package/src/route-definition/dsl-helpers.ts +435 -260
- package/src/route-definition/helper-factories.ts +29 -139
- package/src/route-definition/helpers-types.ts +110 -34
- package/src/route-definition/index.ts +3 -3
- package/src/route-definition/redirect.ts +11 -3
- package/src/route-definition/resolve-handler-use.ts +155 -0
- package/src/route-definition/use-item-types.ts +32 -0
- package/src/route-map-builder.ts +7 -1
- package/src/route-types.ts +37 -41
- package/src/router/basename.ts +14 -0
- package/src/router/content-negotiation.ts +113 -1
- package/src/router/error-handling.ts +1 -1
- package/src/router/find-match.ts +4 -2
- package/src/router/handler-context.ts +105 -39
- package/src/router/intercept-resolution.ts +15 -22
- package/src/router/lazy-includes.ts +12 -9
- package/src/router/loader-resolution.ts +175 -23
- package/src/router/logging.ts +5 -2
- package/src/router/manifest.ts +31 -16
- package/src/router/match-api.ts +129 -193
- package/src/router/match-handlers.ts +63 -20
- package/src/router/match-middleware/background-revalidation.ts +30 -2
- package/src/router/match-middleware/cache-lookup.ts +136 -106
- package/src/router/match-middleware/cache-store.ts +54 -10
- package/src/router/match-middleware/intercept-resolution.ts +9 -7
- package/src/router/match-middleware/segment-resolution.ts +61 -5
- package/src/router/match-result.ts +124 -18
- package/src/router/metrics.ts +239 -14
- package/src/router/middleware-types.ts +61 -31
- package/src/router/middleware.ts +226 -124
- package/src/router/navigation-snapshot.ts +182 -0
- package/src/router/pattern-matching.ts +118 -19
- package/src/router/prerender-match.ts +114 -10
- package/src/router/preview-match.ts +32 -102
- package/src/router/request-classification.ts +286 -0
- package/src/router/revalidation.ts +85 -9
- package/src/router/route-snapshot.ts +245 -0
- package/src/router/router-context.ts +6 -1
- package/src/router/router-interfaces.ts +91 -29
- package/src/router/router-options.ts +89 -19
- package/src/router/router-registry.ts +2 -5
- package/src/router/segment-resolution/fresh.ts +240 -23
- package/src/router/segment-resolution/helpers.ts +30 -25
- package/src/router/segment-resolution/loader-cache.ts +1 -0
- package/src/router/segment-resolution/revalidation.ts +483 -289
- package/src/router/segment-resolution/view-transition-default.ts +36 -0
- package/src/router/segment-wrappers.ts +2 -0
- package/src/router/substitute-pattern-params.ts +56 -0
- package/src/router/telemetry.ts +99 -0
- package/src/router/trie-matching.ts +38 -15
- package/src/router/types.ts +9 -0
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +120 -32
- package/src/rsc/handler-context.ts +2 -2
- package/src/rsc/handler.ts +524 -370
- package/src/rsc/helpers.ts +91 -43
- package/src/rsc/index.ts +1 -21
- package/src/rsc/loader-fetch.ts +23 -3
- package/src/rsc/manifest-init.ts +5 -1
- package/src/rsc/origin-guard.ts +28 -10
- package/src/rsc/progressive-enhancement.ts +39 -10
- package/src/rsc/response-route-handler.ts +46 -53
- package/src/rsc/rsc-rendering.ts +69 -89
- package/src/rsc/runtime-warnings.ts +9 -10
- package/src/rsc/server-action.ts +39 -47
- package/src/rsc/ssr-setup.ts +144 -0
- package/src/rsc/types.ts +19 -3
- package/src/search-params.ts +20 -17
- package/src/segment-content-promise.ts +67 -0
- package/src/segment-loader-promise.ts +122 -0
- package/src/segment-system.tsx +219 -67
- package/src/serialize.ts +243 -0
- package/src/server/context.ts +285 -63
- package/src/server/cookie-store.ts +28 -4
- package/src/server/handle-store.ts +19 -0
- package/src/server/loader-registry.ts +9 -8
- package/src/server/request-context.ts +228 -65
- package/src/server.ts +6 -0
- package/src/ssr/index.tsx +9 -1
- package/src/static-handler.ts +19 -7
- package/src/testing/cache-status.ts +166 -0
- package/src/testing/collect-handle.ts +63 -0
- package/src/testing/dispatch.ts +440 -0
- package/src/testing/dom.entry.ts +22 -0
- package/src/testing/e2e/fixture.ts +154 -0
- package/src/testing/e2e/index.ts +149 -0
- package/src/testing/e2e/matchers.ts +51 -0
- package/src/testing/e2e/page-helpers.ts +272 -0
- package/src/testing/e2e/parity.ts +306 -0
- package/src/testing/e2e/server.ts +183 -0
- package/src/testing/flight-matchers.ts +104 -0
- package/src/testing/flight-runtime.d.ts +21 -0
- package/src/testing/flight.entry.ts +22 -0
- package/src/testing/flight.ts +182 -0
- package/src/testing/generated-routes.ts +223 -0
- package/src/testing/index.ts +98 -0
- package/src/testing/internal/context.ts +151 -0
- package/src/testing/render-route.tsx +536 -0
- package/src/testing/run-loader.ts +296 -0
- package/src/testing/run-middleware.ts +170 -0
- package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
- package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
- package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
- package/src/testing/vitest-stubs/version.ts +5 -0
- package/src/testing/vitest.ts +112 -0
- package/src/theme/index.ts +4 -13
- package/src/types/cache-types.ts +4 -4
- package/src/types/global-namespace.ts +39 -26
- package/src/types/handler-context.ts +197 -79
- package/src/types/index.ts +1 -0
- package/src/types/loader-types.ts +41 -15
- package/src/types/request-scope.ts +126 -0
- package/src/types/route-config.ts +17 -8
- package/src/types/route-entry.ts +19 -1
- package/src/types/segments.ts +37 -6
- package/src/urls/include-helper.ts +34 -67
- package/src/urls/index.ts +0 -3
- package/src/urls/path-helper-types.ts +50 -9
- package/src/urls/path-helper.ts +63 -63
- package/src/urls/pattern-types.ts +48 -19
- package/src/urls/response-types.ts +25 -22
- package/src/urls/type-extraction.ts +26 -116
- package/src/urls/urls-function.ts +1 -5
- package/src/use-loader.tsx +487 -44
- package/src/vite/debug.ts +185 -0
- package/src/vite/discovery/bundle-postprocess.ts +63 -91
- package/src/vite/discovery/discover-routers.ts +106 -53
- package/src/vite/discovery/discovery-errors.ts +194 -0
- package/src/vite/discovery/gate-state.ts +171 -0
- package/src/vite/discovery/prerender-collection.ts +222 -107
- package/src/vite/discovery/route-types-writer.ts +40 -84
- package/src/vite/discovery/self-gen-tracking.ts +27 -1
- package/src/vite/discovery/state.ts +50 -13
- package/src/vite/discovery/virtual-module-codegen.ts +13 -23
- package/src/vite/index.ts +10 -3
- package/src/vite/plugin-types.ts +111 -72
- package/src/vite/plugins/cjs-to-esm.ts +8 -7
- package/src/vite/plugins/client-ref-dedup.ts +16 -0
- package/src/vite/plugins/client-ref-hashing.ts +28 -5
- package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
- package/src/vite/plugins/expose-action-id.ts +55 -33
- package/src/vite/plugins/expose-id-utils.ts +24 -8
- package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
- package/src/vite/plugins/expose-ids/handler-transform.ts +12 -35
- package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
- package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
- package/src/vite/plugins/expose-internal-ids.ts +544 -317
- package/src/vite/plugins/performance-tracks.ts +92 -0
- package/src/vite/plugins/refresh-cmd.ts +127 -0
- package/src/vite/plugins/use-cache-transform.ts +65 -50
- package/src/vite/plugins/version-injector.ts +39 -23
- package/src/vite/plugins/version-plugin.ts +72 -3
- package/src/vite/plugins/virtual-entries.ts +2 -2
- package/src/vite/rango.ts +265 -226
- package/src/vite/router-discovery.ts +924 -137
- package/src/vite/utils/ast-handler-extract.ts +15 -15
- package/src/vite/utils/banner.ts +4 -4
- package/src/vite/utils/bundle-analysis.ts +4 -2
- package/src/vite/utils/client-chunks.ts +190 -0
- package/src/vite/utils/forward-user-plugins.ts +193 -0
- package/src/vite/utils/manifest-utils.ts +21 -5
- package/src/vite/utils/package-resolution.ts +41 -1
- package/src/vite/utils/prerender-utils.ts +98 -5
- package/src/vite/utils/shared-utils.ts +109 -27
- package/src/browser/action-response-classifier.ts +0 -99
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
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
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
-
|
|
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)
|
|
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
|
-
|
|
758
|
+
const result = handleHandlerResult(await handler(context));
|
|
759
|
+
doneHandler();
|
|
760
|
+
return result;
|
|
634
761
|
}
|
|
635
762
|
if (!actionContext) {
|
|
636
|
-
const result = handleHandlerResult(
|
|
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:
|
|
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:
|
|
1147
|
+
transition: applyViewTransitionDefault(
|
|
1148
|
+
orphan.transition,
|
|
1149
|
+
deps.viewTransitionDefault,
|
|
1150
|
+
),
|
|
982
1151
|
...(orphan.mountPath ? { mountPath: orphan.mountPath } : {}),
|
|
983
1152
|
});
|
|
984
1153
|
|
|
985
|
-
|
|
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
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
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
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
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
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
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
|
-
|
|
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
|