@rangojs/router 0.0.0-experimental.f2337aef → 0.0.0-experimental.fa8a383a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/rango.js +8 -3
- package/dist/vite/index.js +139 -200
- package/package.json +1 -1
- package/skills/caching/SKILL.md +37 -4
- package/skills/parallel/SKILL.md +59 -0
- package/src/browser/event-controller.ts +5 -0
- package/src/browser/navigation-bridge.ts +1 -3
- package/src/browser/navigation-client.ts +60 -27
- package/src/browser/navigation-transaction.ts +11 -9
- package/src/browser/partial-update.ts +39 -9
- package/src/browser/prefetch/cache.ts +57 -5
- package/src/browser/prefetch/fetch.ts +30 -21
- package/src/browser/prefetch/queue.ts +53 -13
- package/src/browser/react/Link.tsx +9 -1
- package/src/browser/react/NavigationProvider.tsx +27 -0
- package/src/browser/rsc-router.tsx +109 -57
- package/src/browser/scroll-restoration.ts +20 -7
- package/src/browser/segment-reconciler.ts +6 -1
- package/src/browser/types.ts +9 -0
- package/src/build/route-types/router-processing.ts +12 -2
- package/src/cache/cache-scope.ts +2 -2
- package/src/cache/cf/cf-cache-store.ts +453 -11
- 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/debug.ts +2 -2
- package/src/route-definition/dsl-helpers.ts +32 -7
- package/src/route-definition/redirect.ts +2 -2
- package/src/router/lazy-includes.ts +4 -1
- package/src/router/logging.ts +1 -1
- package/src/router/manifest.ts +9 -3
- package/src/router/match-middleware/background-revalidation.ts +18 -1
- package/src/router/match-middleware/cache-lookup.ts +20 -3
- package/src/router/match-middleware/cache-store.ts +32 -6
- package/src/router/match-middleware/intercept-resolution.ts +9 -7
- package/src/router/match-middleware/segment-resolution.ts +7 -5
- package/src/router/match-result.ts +11 -1
- package/src/router/middleware.ts +2 -1
- package/src/router/segment-resolution/fresh.ts +104 -14
- package/src/router/segment-resolution/loader-cache.ts +1 -0
- package/src/router/segment-resolution/revalidation.ts +307 -272
- package/src/router.ts +5 -1
- package/src/rsc/handler.ts +9 -0
- package/src/segment-system.tsx +140 -4
- package/src/server/context.ts +90 -13
- package/src/server/request-context.ts +10 -4
- package/src/ssr/index.tsx +1 -0
- package/src/types/route-entry.ts +7 -0
- package/src/types/segments.ts +2 -0
- package/src/urls/path-helper.ts +1 -1
- package/src/vite/discovery/state.ts +0 -2
- package/src/vite/plugin-types.ts +0 -83
- package/src/vite/plugins/expose-action-id.ts +1 -3
- package/src/vite/plugins/version-plugin.ts +13 -1
- package/src/vite/rango.ts +144 -209
- package/src/vite/router-discovery.ts +0 -8
- package/src/vite/utils/banner.ts +3 -3
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import type { ReactNode } from "react";
|
|
9
9
|
import { invariant } from "../../errors";
|
|
10
|
-
import
|
|
10
|
+
import {
|
|
11
|
+
getParallelEntries,
|
|
12
|
+
getParallelSlotEntries,
|
|
13
|
+
type EntryData,
|
|
14
|
+
} from "../../server/context";
|
|
11
15
|
import type {
|
|
12
16
|
HandlerContext,
|
|
13
17
|
InternalHandlerContext,
|
|
@@ -15,6 +19,8 @@ import type {
|
|
|
15
19
|
} from "../../types";
|
|
16
20
|
import type { SegmentResolutionDeps } from "../types.js";
|
|
17
21
|
import { resolveLoaderData } from "./loader-cache.js";
|
|
22
|
+
import { _getRequestContext } from "../../server/request-context.js";
|
|
23
|
+
import { appendMetric } from "../metrics.js";
|
|
18
24
|
import {
|
|
19
25
|
handleHandlerResult,
|
|
20
26
|
tryStaticHandler,
|
|
@@ -90,8 +96,12 @@ export async function resolveLoaders<TEnv>(
|
|
|
90
96
|
const shortCode = shortCodeOverride ?? entry.shortCode;
|
|
91
97
|
const hasLoading = "loading" in entry && entry.loading !== undefined;
|
|
92
98
|
const loadingDisabled = hasLoading && entry.loading === false;
|
|
99
|
+
const ms = _getRequestContext()?._metricsStore;
|
|
93
100
|
|
|
94
101
|
if (!loadingDisabled) {
|
|
102
|
+
// Streaming loaders: promises kick off now, settle during RSC serialization.
|
|
103
|
+
// No per-loader timing here — settlement happens asynchronously during
|
|
104
|
+
// RSC/SSR stream consumption, after the perf timeline is logged.
|
|
95
105
|
return loaderEntries.map((loaderEntry, i) => {
|
|
96
106
|
const { loader } = loaderEntry;
|
|
97
107
|
const segmentId = `${shortCode}D${i}.${loader.$$id}`;
|
|
@@ -116,14 +126,31 @@ export async function resolveLoaders<TEnv>(
|
|
|
116
126
|
|
|
117
127
|
// Loading disabled: still start all loaders in parallel, but only emit
|
|
118
128
|
// settled promises so handlers don't stream loading placeholders.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
// We can measure actual execution time here since we await all loaders.
|
|
130
|
+
const pendingLoaderData = loaderEntries.map((loaderEntry) => {
|
|
131
|
+
const start = performance.now();
|
|
132
|
+
const promise = resolveLoaderData(loaderEntry, ctx, ctx.pathname);
|
|
133
|
+
return { promise, start, loaderId: loaderEntry.loader.$$id };
|
|
134
|
+
});
|
|
135
|
+
await Promise.all(pendingLoaderData.map((p) => p.promise));
|
|
123
136
|
|
|
124
137
|
return loaderEntries.map((loaderEntry, i) => {
|
|
125
138
|
const { loader } = loaderEntry;
|
|
126
139
|
const segmentId = `${shortCode}D${i}.${loader.$$id}`;
|
|
140
|
+
const pending = pendingLoaderData[i]!;
|
|
141
|
+
if (ms && !ms.metrics.some((m) => m.label === `loader:${loader.$$id}`)) {
|
|
142
|
+
// All loaders ran in parallel via Promise.all — each span covers
|
|
143
|
+
// from its own kickoff to the batch settlement, giving a ceiling
|
|
144
|
+
// on that loader's contribution to the overall wait.
|
|
145
|
+
const batchEnd = performance.now();
|
|
146
|
+
appendMetric(
|
|
147
|
+
ms,
|
|
148
|
+
`loader:${loader.$$id}`,
|
|
149
|
+
pending.start,
|
|
150
|
+
batchEnd - pending.start,
|
|
151
|
+
2,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
127
154
|
return {
|
|
128
155
|
id: segmentId,
|
|
129
156
|
namespace: entry.id,
|
|
@@ -133,7 +160,7 @@ export async function resolveLoaders<TEnv>(
|
|
|
133
160
|
params: ctx.params,
|
|
134
161
|
loaderId: loader.$$id,
|
|
135
162
|
loaderData: deps.wrapLoaderPromise(
|
|
136
|
-
|
|
163
|
+
pending.promise,
|
|
137
164
|
entry,
|
|
138
165
|
segmentId,
|
|
139
166
|
ctx.pathname,
|
|
@@ -197,7 +224,10 @@ export async function resolveSegment<TEnv>(
|
|
|
197
224
|
...(entry.mountPath ? { mountPath: entry.mountPath } : {}),
|
|
198
225
|
});
|
|
199
226
|
|
|
200
|
-
|
|
227
|
+
const resolvedParallelEntries = new Set<string>();
|
|
228
|
+
for (const { slot, entry: parallelEntry } of getParallelSlotEntries(
|
|
229
|
+
entry.parallel,
|
|
230
|
+
)) {
|
|
201
231
|
const parallelSegments = await resolveParallelEntry(
|
|
202
232
|
parallelEntry,
|
|
203
233
|
params,
|
|
@@ -207,8 +237,11 @@ export async function resolveSegment<TEnv>(
|
|
|
207
237
|
deps,
|
|
208
238
|
options,
|
|
209
239
|
routeKey,
|
|
240
|
+
[slot],
|
|
241
|
+
!resolvedParallelEntries.has(parallelEntry.id),
|
|
210
242
|
);
|
|
211
243
|
segments.push(...parallelSegments);
|
|
244
|
+
resolvedParallelEntries.add(parallelEntry.id);
|
|
212
245
|
}
|
|
213
246
|
|
|
214
247
|
for (const orphan of entry.layout) {
|
|
@@ -286,7 +319,10 @@ export async function resolveSegment<TEnv>(
|
|
|
286
319
|
segments.push(...orphanSegments);
|
|
287
320
|
}
|
|
288
321
|
|
|
289
|
-
|
|
322
|
+
const resolvedParallelEntries = new Set<string>();
|
|
323
|
+
for (const { slot, entry: parallelEntry } of getParallelSlotEntries(
|
|
324
|
+
entry.parallel,
|
|
325
|
+
)) {
|
|
290
326
|
const parallelSegments = await resolveParallelEntry(
|
|
291
327
|
parallelEntry,
|
|
292
328
|
params,
|
|
@@ -296,8 +332,11 @@ export async function resolveSegment<TEnv>(
|
|
|
296
332
|
deps,
|
|
297
333
|
options,
|
|
298
334
|
routeKey,
|
|
335
|
+
[slot],
|
|
336
|
+
!resolvedParallelEntries.has(parallelEntry.id),
|
|
299
337
|
);
|
|
300
338
|
segments.push(...parallelSegments);
|
|
339
|
+
resolvedParallelEntries.add(parallelEntry.id);
|
|
301
340
|
}
|
|
302
341
|
|
|
303
342
|
segments.push({
|
|
@@ -368,7 +407,10 @@ export async function resolveOrphanLayout<TEnv>(
|
|
|
368
407
|
...(orphan.mountPath ? { mountPath: orphan.mountPath } : {}),
|
|
369
408
|
});
|
|
370
409
|
|
|
371
|
-
|
|
410
|
+
const resolvedParallelEntries = new Set<string>();
|
|
411
|
+
for (const { slot, entry: parallelEntry } of getParallelSlotEntries(
|
|
412
|
+
orphan.parallel,
|
|
413
|
+
)) {
|
|
372
414
|
const parallelSegments = await resolveParallelEntry(
|
|
373
415
|
parallelEntry,
|
|
374
416
|
params,
|
|
@@ -378,8 +420,11 @@ export async function resolveOrphanLayout<TEnv>(
|
|
|
378
420
|
deps,
|
|
379
421
|
options,
|
|
380
422
|
routeKey,
|
|
423
|
+
[slot],
|
|
424
|
+
!resolvedParallelEntries.has(parallelEntry.id),
|
|
381
425
|
);
|
|
382
426
|
segments.push(...parallelSegments);
|
|
427
|
+
resolvedParallelEntries.add(parallelEntry.id);
|
|
383
428
|
}
|
|
384
429
|
|
|
385
430
|
return segments;
|
|
@@ -397,6 +442,8 @@ export async function resolveParallelEntry<TEnv>(
|
|
|
397
442
|
deps: SegmentResolutionDeps<TEnv>,
|
|
398
443
|
options?: ResolveSegmentOptions,
|
|
399
444
|
routeKey?: string,
|
|
445
|
+
slotNames?: `@${string}`[],
|
|
446
|
+
includeLoaders: boolean = true,
|
|
400
447
|
): Promise<ResolvedSegment[]> {
|
|
401
448
|
invariant(
|
|
402
449
|
parallelEntry.type === "parallel",
|
|
@@ -411,7 +458,12 @@ export async function resolveParallelEntry<TEnv>(
|
|
|
411
458
|
| ReactNode
|
|
412
459
|
>;
|
|
413
460
|
|
|
414
|
-
|
|
461
|
+
const slotsToResolve = slotNames ?? (Object.keys(slots) as `@${string}`[]);
|
|
462
|
+
|
|
463
|
+
for (const slot of slotsToResolve) {
|
|
464
|
+
// Try static lookup first — in production, handler bodies are evicted
|
|
465
|
+
// and replaced with stubs that have no .handler property (undefined).
|
|
466
|
+
// The static store holds the pre-rendered component for these slots.
|
|
415
467
|
let component: ReactNode | undefined = await tryStaticSlot(
|
|
416
468
|
parallelEntry,
|
|
417
469
|
slot,
|
|
@@ -419,6 +471,10 @@ export async function resolveParallelEntry<TEnv>(
|
|
|
419
471
|
);
|
|
420
472
|
|
|
421
473
|
if (component === undefined) {
|
|
474
|
+
const handler = slots[slot];
|
|
475
|
+
if (handler === undefined) {
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
422
478
|
const doneParallelHandler = track(
|
|
423
479
|
`handler:${parallelEntry.id}.${slot}`,
|
|
424
480
|
2,
|
|
@@ -472,7 +528,7 @@ export async function resolveParallelEntry<TEnv>(
|
|
|
472
528
|
});
|
|
473
529
|
}
|
|
474
530
|
|
|
475
|
-
if (!
|
|
531
|
+
if (!options?.skipLoaders && includeLoaders) {
|
|
476
532
|
const loaderSegments = await resolveLoaders(
|
|
477
533
|
parallelEntry,
|
|
478
534
|
context,
|
|
@@ -480,6 +536,15 @@ export async function resolveParallelEntry<TEnv>(
|
|
|
480
536
|
deps,
|
|
481
537
|
parentShortCode,
|
|
482
538
|
);
|
|
539
|
+
// Tag parallel-owned loaders so renderSegments can stream them
|
|
540
|
+
// using the parallel's loading() instead of awaiting on the layout
|
|
541
|
+
const parallelLoading =
|
|
542
|
+
parallelEntry.loading === false ? undefined : parallelEntry.loading;
|
|
543
|
+
if (parallelLoading) {
|
|
544
|
+
for (const seg of loaderSegments) {
|
|
545
|
+
seg.parallelLoading = parallelLoading;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
483
548
|
segments.push(...loaderSegments);
|
|
484
549
|
}
|
|
485
550
|
|
|
@@ -560,10 +625,35 @@ export async function resolveLoadersOnly<TEnv>(
|
|
|
560
625
|
): Promise<ResolvedSegment[]> {
|
|
561
626
|
const loaderSegments: ResolvedSegment[] = [];
|
|
562
627
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
628
|
+
async function collectEntryLoaders(
|
|
629
|
+
entry: EntryData,
|
|
630
|
+
belongsToRoute: boolean,
|
|
631
|
+
shortCodeOverride?: string,
|
|
632
|
+
): Promise<void> {
|
|
633
|
+
const segments = await resolveLoaders(
|
|
634
|
+
entry,
|
|
635
|
+
context,
|
|
636
|
+
belongsToRoute,
|
|
637
|
+
deps,
|
|
638
|
+
shortCodeOverride,
|
|
639
|
+
);
|
|
566
640
|
loaderSegments.push(...segments);
|
|
641
|
+
|
|
642
|
+
const seenParallelEntryIds = new Set<string>();
|
|
643
|
+
for (const parallelEntry of getParallelEntries(entry.parallel)) {
|
|
644
|
+
if (seenParallelEntryIds.has(parallelEntry.id)) continue;
|
|
645
|
+
seenParallelEntryIds.add(parallelEntry.id);
|
|
646
|
+
await collectEntryLoaders(parallelEntry, belongsToRoute, entry.shortCode);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
const childBelongsToRoute = belongsToRoute || entry.type === "route";
|
|
650
|
+
for (const layoutEntry of entry.layout) {
|
|
651
|
+
await collectEntryLoaders(layoutEntry, childBelongsToRoute);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
for (const entry of entries) {
|
|
656
|
+
await collectEntryLoaders(entry, entry.type === "route");
|
|
567
657
|
}
|
|
568
658
|
|
|
569
659
|
return loaderSegments;
|
|
@@ -147,6 +147,7 @@ export function resolveLoaderData<TEnv>(
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
const loaderId = loaderEntry.loader.$$id;
|
|
150
|
+
|
|
150
151
|
const ttl = resolveTtl(options.ttl, store.defaults, DEFAULT_ROUTE_TTL);
|
|
151
152
|
const swrWindow = resolveSwrWindow(options.swr, store.defaults);
|
|
152
153
|
const swr = swrWindow || undefined;
|