@teyik0/furin 0.9.0-alpha.4 → 0.9.0-alpha.6
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/adapter/runtime-build.d.ts +1 -0
- package/dist/adapter/vercel.js +9 -6
- package/dist/build/index.js +74 -31
- package/dist/build/route-metadata.d.ts +1 -1
- package/dist/cli/index.js +74 -31
- package/dist/client/chunks/{client-rdxyrw11.js → client-hjqd5m3b.js} +1 -1
- package/dist/client/chunks/{client-p0jqzfvc.js → client-whph3y67.js} +1 -1
- package/dist/client/chunks/{client-a7spxfnn.js → client-xf7r768c.js} +13 -1
- package/dist/client/define-route.d.ts +12 -0
- package/dist/client/internal/runtime-types.d.ts +7 -0
- package/dist/client/link.js +200 -40
- package/dist/client/route-element.d.ts +5 -0
- package/dist/client/router/history.d.ts +6 -0
- package/dist/client/router/link-utils.d.ts +7 -0
- package/dist/client/router/navigation-controller.d.ts +20 -2
- package/dist/client/router/pending.d.ts +17 -0
- package/dist/client/router/search/index.d.ts +2 -0
- package/dist/client/router/search/index.js +7 -3
- package/dist/client/router/types.d.ts +21 -1
- package/dist/client.js +19 -4
- package/dist/define-route.d.ts +37 -10
- package/dist/furin.js +88 -29
- package/dist/plugin/client-plugin.d.ts +1 -1
- package/dist/plugin/index.js +36 -17
- package/dist/plugin/route-manifest.d.ts +2 -1
- package/dist/plugin/strip-server-stages.d.ts +1 -1
- package/dist/server/internal.d.ts +1 -0
- package/dist/server/internal.js +42 -15
- package/dist/server/router/defined-route.d.ts +3 -0
- package/dist/server/router/types.d.ts +7 -1
- package/dist/server/static-export.js +45 -15
- package/dist/shared/pending.d.ts +13 -0
- package/dist/shared/search-params.d.ts +1 -0
- package/package.json +1 -1
- package/src/adapter/runtime-build.ts +4 -0
- package/src/adapter/vercel.ts +21 -8
- package/src/build/hydrate.ts +11 -2
- package/src/build/preload-manifest.ts +3 -1
- package/src/build/route-metadata.ts +3 -2
- package/src/client/define-route.ts +23 -3
- package/src/client/internal/runtime-types.ts +7 -0
- package/src/client/link.tsx +26 -4
- package/src/client/route-element.tsx +41 -15
- package/src/client/router/context.ts +29 -8
- package/src/client/router/history.ts +10 -0
- package/src/client/router/link-utils.ts +23 -0
- package/src/client/router/navigation-controller.ts +239 -19
- package/src/client/router/pending.ts +58 -0
- package/src/client/router/provider.tsx +5 -2
- package/src/client/router/search/index.ts +7 -2
- package/src/client/router/types.ts +29 -3
- package/src/define-route.ts +74 -26
- package/src/plugin/client-plugin.ts +5 -4
- package/src/plugin/route-config.ts +9 -2
- package/src/plugin/route-manifest.ts +11 -3
- package/src/plugin/route-tree.ts +2 -2
- package/src/plugin/strip-server-stages.ts +60 -35
- package/src/server/internal.ts +1 -0
- package/src/server/router/defined-route.ts +6 -0
- package/src/server/router/discovery.ts +5 -2
- package/src/server/router/types.ts +7 -1
- package/src/shared/pending.ts +16 -0
- package/src/shared/search-params.ts +1 -1
|
@@ -3200,6 +3200,18 @@ function applyLinkParams(to, params) {
|
|
|
3200
3200
|
}
|
|
3201
3201
|
return url;
|
|
3202
3202
|
}
|
|
3203
|
+
function resolveTargetSearch(path, search, routes) {
|
|
3204
|
+
if (path.includes("?")) {
|
|
3205
|
+
return;
|
|
3206
|
+
}
|
|
3207
|
+
const resolved = { ...findSearchDefaultsForRouteTarget(path, routes) };
|
|
3208
|
+
for (const [key, value] of Object.entries(search ?? {})) {
|
|
3209
|
+
if (value !== null && value !== undefined) {
|
|
3210
|
+
resolved[key] = value;
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
return resolved;
|
|
3214
|
+
}
|
|
3203
3215
|
function buildHref(to, search, hash, searchDefaults) {
|
|
3204
3216
|
let url = to;
|
|
3205
3217
|
if (search && Object.keys(search).length > 0) {
|
|
@@ -8318,7 +8330,14 @@ function withDocumentState(element, assets, head, data, nonce, jsonCompatible) {
|
|
|
8318
8330
|
|
|
8319
8331
|
// src/client/link.tsx
|
|
8320
8332
|
init_search_params();
|
|
8321
|
-
import {
|
|
8333
|
+
import {
|
|
8334
|
+
createElement as createElement6,
|
|
8335
|
+
useCallback as useCallback3,
|
|
8336
|
+
useEffect as useEffect2,
|
|
8337
|
+
useMemo as useMemo2,
|
|
8338
|
+
useRef,
|
|
8339
|
+
useSyncExternalStore as useSyncExternalStore2
|
|
8340
|
+
} from "react";
|
|
8322
8341
|
|
|
8323
8342
|
// src/client/router/context.ts
|
|
8324
8343
|
init_link_utils();
|
|
@@ -8587,6 +8606,18 @@ function selectRouteBoundary(boundaries, rootBoundary, index, kind) {
|
|
|
8587
8606
|
function wrapLayout(route, props, element) {
|
|
8588
8607
|
return route?.layout ? createElement5(route.layout, props, element) : element;
|
|
8589
8608
|
}
|
|
8609
|
+
function wrapSegments(input, depth, props, fallbackProps, element) {
|
|
8610
|
+
let wrapped = element;
|
|
8611
|
+
for (let layout = depth;layout >= 0; layout -= 1) {
|
|
8612
|
+
for (const boundary of input.boundaries.toReversed()) {
|
|
8613
|
+
if (boundary.depth === layout) {
|
|
8614
|
+
wrapped = wrapSegmentBoundaries(wrapped, boundary, input.boundaryOptions);
|
|
8615
|
+
}
|
|
8616
|
+
}
|
|
8617
|
+
wrapped = wrapLayout(input.chain[layout], props[layout] ?? fallbackProps, wrapped);
|
|
8618
|
+
}
|
|
8619
|
+
return wrapped;
|
|
8620
|
+
}
|
|
8590
8621
|
function failureElement(failure, component, reset) {
|
|
8591
8622
|
if (failure.status === "error") {
|
|
8592
8623
|
return createElement5(component ?? DefaultErrorFallback, {
|
|
@@ -8611,9 +8642,10 @@ function resolveRouteElement(input) {
|
|
|
8611
8642
|
inherited = { ...inherited, ...match.loaderData };
|
|
8612
8643
|
props.push({ ...inherited, ...context });
|
|
8613
8644
|
}
|
|
8645
|
+
const { pending } = input;
|
|
8614
8646
|
const index = matches.findIndex((match) => match.status !== "success");
|
|
8615
8647
|
const failure = matches[index];
|
|
8616
|
-
if (failure && failure.status !== "success") {
|
|
8648
|
+
if (failure && failure.status !== "success" && !pending) {
|
|
8617
8649
|
const { component, depth } = selectRouteBoundary(boundaries, input.rootBoundary, index, failure.status);
|
|
8618
8650
|
let element = failureElement(failure, component, input.reset);
|
|
8619
8651
|
for (let layout = depth;layout >= 0; layout -= 1) {
|
|
@@ -8625,18 +8657,10 @@ function resolveRouteElement(input) {
|
|
|
8625
8657
|
throw new Error("[furin] internal invariant: a successful route render requires a page.");
|
|
8626
8658
|
}
|
|
8627
8659
|
const pageProps = Object.fromEntries(Object.entries(data).filter(([key]) => !key.startsWith("__furin")));
|
|
8628
|
-
|
|
8660
|
+
const element = pending ? wrapSegments(input, pending.depth, props, pageProps, createElement5(pending.component)) : wrapSegments(input, chain.length - 1, props, pageProps, createElement5(page.component, {
|
|
8629
8661
|
...pageProps,
|
|
8630
8662
|
key: pageKey(page.pattern, pageProps, chain.at(-1)?.remountDeps)
|
|
8631
|
-
});
|
|
8632
|
-
for (let layout = chain.length - 1;layout >= 0; layout -= 1) {
|
|
8633
|
-
for (const boundary of boundaries.toReversed()) {
|
|
8634
|
-
if (boundary.depth === layout) {
|
|
8635
|
-
element = wrapSegmentBoundaries(element, boundary, input.boundaryOptions);
|
|
8636
|
-
}
|
|
8637
|
-
}
|
|
8638
|
-
element = wrapLayout(chain[layout], props[layout] ?? pageProps, element);
|
|
8639
|
-
}
|
|
8663
|
+
}));
|
|
8640
8664
|
return withRouteSnapshot(element, page.pattern, pageProps);
|
|
8641
8665
|
}
|
|
8642
8666
|
|
|
@@ -8743,6 +8767,7 @@ function LinkInteractive({
|
|
|
8743
8767
|
replace,
|
|
8744
8768
|
disabled,
|
|
8745
8769
|
resetScroll,
|
|
8770
|
+
shallow,
|
|
8746
8771
|
activeProps,
|
|
8747
8772
|
inactiveProps,
|
|
8748
8773
|
onClick,
|
|
@@ -8758,6 +8783,7 @@ function LinkInteractive({
|
|
|
8758
8783
|
const anchorRef = useRef(null);
|
|
8759
8784
|
const intentTimerRef = useRef(null);
|
|
8760
8785
|
const { activeHref, logicalHref, href } = resolveLinkHref({ hash, params, search, to }, router2);
|
|
8786
|
+
const targetSearch = useMemo2(() => resolveTargetSearch(applyLinkParams(to, params), search, router2.searchRoutes), [logicalHref, router2.searchRoutes]);
|
|
8761
8787
|
const isActive = useSyncExternalStore2(store.subscribe, () => activeHref !== undefined && store.getCurrentHref() === activeHref, () => activeHref !== undefined && store.getCurrentHref() === activeHref);
|
|
8762
8788
|
const { resolvedChildren, extraProps } = resolveLinkState({ activeProps, children, inactiveProps }, isActive);
|
|
8763
8789
|
const effectivePreload = preload ?? router2.defaultPreload;
|
|
@@ -8771,9 +8797,9 @@ function LinkInteractive({
|
|
|
8771
8797
|
}
|
|
8772
8798
|
const target = shouldInterceptClick(anchor, { altKey: false, ctrlKey: false, metaKey: false, shiftKey: false }, router2.basePath, window.location.origin, window.location.pathname);
|
|
8773
8799
|
if (target !== null) {
|
|
8774
|
-
prefetch(target, { staleTime: effectiveStaleTime });
|
|
8800
|
+
prefetch(target, { search: targetSearch, staleTime: effectiveStaleTime });
|
|
8775
8801
|
}
|
|
8776
|
-
}, [prefetch, effectiveStaleTime, router2.basePath]);
|
|
8802
|
+
}, [prefetch, effectiveStaleTime, router2.basePath, targetSearch]);
|
|
8777
8803
|
useEffect2(() => {
|
|
8778
8804
|
if (effectivePreload === "render") {
|
|
8779
8805
|
triggerPrefetch();
|
|
@@ -8823,7 +8849,7 @@ function LinkInteractive({
|
|
|
8823
8849
|
window.location.assign(href);
|
|
8824
8850
|
return;
|
|
8825
8851
|
}
|
|
8826
|
-
router2.navigate(target, { replace, resetScroll:
|
|
8852
|
+
router2.navigate(target, { replace, resetScroll, search: targetSearch, shallow });
|
|
8827
8853
|
};
|
|
8828
8854
|
const handleMouseEnter = (e) => {
|
|
8829
8855
|
onMouseEnter?.(e);
|
|
@@ -8891,6 +8917,7 @@ function renderLinkElement(props, router2) {
|
|
|
8891
8917
|
preloadStaleTime: _ps,
|
|
8892
8918
|
replace: _r,
|
|
8893
8919
|
resetScroll: _rs,
|
|
8920
|
+
shallow: _sh,
|
|
8894
8921
|
onClick: _oc,
|
|
8895
8922
|
onMouseEnter: _ome,
|
|
8896
8923
|
onMouseLeave: _oml,
|
|
@@ -10545,6 +10572,7 @@ function adaptDefinedLayout(route, parent, sourcePath) {
|
|
|
10545
10572
|
notFoundComponent: route.notFoundComponent,
|
|
10546
10573
|
params: route.schemas?.params,
|
|
10547
10574
|
...parent ? { parent } : {},
|
|
10575
|
+
pending: route.pending,
|
|
10548
10576
|
query: route.schemas?.query,
|
|
10549
10577
|
requestLoader: route.requestLoader,
|
|
10550
10578
|
revalidate: route.revalidate,
|
|
@@ -10562,6 +10590,7 @@ function adaptDefinedPage(route, parent) {
|
|
|
10562
10590
|
__type: "FURIN_ROUTE",
|
|
10563
10591
|
params: route.schemas?.params,
|
|
10564
10592
|
parent,
|
|
10593
|
+
loaderDeps: route.loaderDeps,
|
|
10565
10594
|
query: route.schemas?.query,
|
|
10566
10595
|
remountDeps: route.remountDeps,
|
|
10567
10596
|
requestLoader: route.requestLoader
|
|
@@ -10572,6 +10601,7 @@ function adaptDefinedPage(route, parent) {
|
|
|
10572
10601
|
loader: route.loader,
|
|
10573
10602
|
mode: route.mode,
|
|
10574
10603
|
notFoundComponent: route.notFoundComponent,
|
|
10604
|
+
pending: route.pending,
|
|
10575
10605
|
revalidate: route.revalidate,
|
|
10576
10606
|
staticParams: route.staticParams,
|
|
10577
10607
|
tags: copyTags(route.tags)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
export type PendingComponent = FC;
|
|
3
|
+
/** When a navigation shows a route's pending screen (TanStack `pendingMs` / `pendingMinMs`). */
|
|
4
|
+
export interface PendingOptions {
|
|
5
|
+
/** Minimum time the screen stays once shown, so it never blinks. Default: 500. */
|
|
6
|
+
minMs?: number;
|
|
7
|
+
/** Delay before the screen shows, so fast navigations never flash it. Default: 1000. */
|
|
8
|
+
ms?: number;
|
|
9
|
+
}
|
|
10
|
+
/** A route's `.pending()` (TanStack style) or a directory's `loading.tsx` (Next.js style). */
|
|
11
|
+
export interface RoutePending extends PendingOptions {
|
|
12
|
+
component: PendingComponent;
|
|
13
|
+
}
|
|
@@ -9,6 +9,7 @@ export interface SearchRouteMetadata {
|
|
|
9
9
|
regex: RegExp;
|
|
10
10
|
searchDefaults?: SearchParamsInput;
|
|
11
11
|
}
|
|
12
|
+
export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
12
13
|
export declare function buildSearchParams(search: SearchParamsInput, defaults?: SearchParamsInput): URLSearchParams;
|
|
13
14
|
export declare function collectSearchDefaults(schema: unknown): SearchParamsInput | undefined;
|
|
14
15
|
export declare function findSearchDefaults(pathname: string, routes: readonly SearchRouteMetadata[]): SearchParamsInput | undefined;
|
package/package.json
CHANGED
|
@@ -152,6 +152,9 @@ export async function createBuildFingerprint(
|
|
|
152
152
|
if (segment.notFoundPath) {
|
|
153
153
|
fingerprintPaths.add(segment.notFoundPath);
|
|
154
154
|
}
|
|
155
|
+
if (segment.pendingPath) {
|
|
156
|
+
fingerprintPaths.add(segment.pendingPath);
|
|
157
|
+
}
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
160
|
const sources = new Map<string, string>();
|
|
@@ -285,6 +288,7 @@ export function buildCompileMetadata(root: BuildRoot | RootLayout, routes: Build
|
|
|
285
288
|
...(boundary.fromRoute ? { fromRoute: boundary.fromRoute } : {}),
|
|
286
289
|
notFoundPath: boundary.notFoundPath ? toPosixPath(boundary.notFoundPath) : undefined,
|
|
287
290
|
path: toPosixPath(boundary.path),
|
|
291
|
+
pendingPath: boundary.pendingPath ? toPosixPath(boundary.pendingPath) : undefined,
|
|
288
292
|
})),
|
|
289
293
|
};
|
|
290
294
|
}
|
package/src/adapter/vercel.ts
CHANGED
|
@@ -200,6 +200,21 @@ function prerenderAllowQuery(route: AdapterRoute): string[] | undefined {
|
|
|
200
200
|
return route.queryKeys === null ? undefined : [ISR_PATH_PARAM, ...route.queryKeys];
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
+
/**
|
|
204
|
+
* A PPR shell resumes on its own output path, as Next.js does. Vercel stops
|
|
205
|
+
* routing to an output that another prerender targets through `chain`, so
|
|
206
|
+
* chaining to `__server` would 404 every request routed to it.
|
|
207
|
+
*/
|
|
208
|
+
function pprChain(
|
|
209
|
+
route: AdapterRoute,
|
|
210
|
+
functionName: string,
|
|
211
|
+
pprResumeKey: string
|
|
212
|
+
): PrerenderConfig["chain"] {
|
|
213
|
+
return route.ppr
|
|
214
|
+
? { headers: { "x-furin-ppr-resume": pprResumeKey }, outputPath: functionName }
|
|
215
|
+
: undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
203
218
|
function createPrerenderSpecs(
|
|
204
219
|
apps: AdapterApp[],
|
|
205
220
|
pprResumeKey: string
|
|
@@ -215,6 +230,7 @@ function createPrerenderSpecs(
|
|
|
215
230
|
}
|
|
216
231
|
const physicalPattern = physicalPath(app.prefix, route.pattern);
|
|
217
232
|
const source = routePatternSource(app.prefix, route.pattern);
|
|
233
|
+
const functionName = functionNameForPath(physicalPattern, route.mode, names);
|
|
218
234
|
specs.set(source, {
|
|
219
235
|
config: {
|
|
220
236
|
// PPR holes resume with the query the shell recorded, which is the
|
|
@@ -222,14 +238,10 @@ function createPrerenderSpecs(
|
|
|
222
238
|
allowQuery: prerenderAllowQuery(route),
|
|
223
239
|
expiration: expirationFor(route),
|
|
224
240
|
passQuery: true,
|
|
225
|
-
|
|
226
|
-
? {
|
|
227
|
-
chain: { headers: { "x-furin-ppr-resume": pprResumeKey }, outputPath: "__server" },
|
|
228
|
-
}
|
|
229
|
-
: {}),
|
|
241
|
+
chain: pprChain(route, functionName, pprResumeKey),
|
|
230
242
|
},
|
|
231
243
|
exact: !DYNAMIC_SEGMENT_RE.test(route.pattern),
|
|
232
|
-
functionName
|
|
244
|
+
functionName,
|
|
233
245
|
pattern: physicalPattern,
|
|
234
246
|
source,
|
|
235
247
|
});
|
|
@@ -245,15 +257,16 @@ function createPrerenderSpecs(
|
|
|
245
257
|
const path = physicalPath(app.prefix, prerender.path);
|
|
246
258
|
let spec = specs.get(routePatternSource(app.prefix, route.pattern)) as PrerenderSpec;
|
|
247
259
|
if (DYNAMIC_SEGMENT_RE.test(route.pattern)) {
|
|
260
|
+
const functionName = functionNameForPath(path, route.mode, names);
|
|
248
261
|
spec = {
|
|
249
262
|
config: {
|
|
250
263
|
allowQuery: spec.config.allowQuery,
|
|
251
|
-
chain:
|
|
264
|
+
chain: pprChain(route, functionName, pprResumeKey),
|
|
252
265
|
expiration: expirationFor(route),
|
|
253
266
|
passQuery: true,
|
|
254
267
|
},
|
|
255
268
|
exact: true,
|
|
256
|
-
functionName
|
|
269
|
+
functionName,
|
|
257
270
|
pattern: path,
|
|
258
271
|
source: exactPathSource(path),
|
|
259
272
|
};
|
package/src/build/hydrate.ts
CHANGED
|
@@ -118,7 +118,8 @@ function hydrateEntry(
|
|
|
118
118
|
for (const seg of route.segmentBoundaries ?? []) {
|
|
119
119
|
const errorIdent = getBoundaryIdent(boundaryIdents, seg.errorPath);
|
|
120
120
|
const notFoundIdent = getBoundaryIdent(boundaryIdents, seg.notFoundPath);
|
|
121
|
-
|
|
121
|
+
const pendingIdent = getBoundaryIdent(boundaryIdents, seg.pendingPath);
|
|
122
|
+
if (!(errorIdent || notFoundIdent || pendingIdent)) {
|
|
122
123
|
continue;
|
|
123
124
|
}
|
|
124
125
|
const parts = [`depth: ${seg.depth}`];
|
|
@@ -131,6 +132,14 @@ function hydrateEntry(
|
|
|
131
132
|
if (notFoundIdent) {
|
|
132
133
|
parts.push(`notFound: ${notFoundIdent}.${notFoundExport}`);
|
|
133
134
|
}
|
|
135
|
+
// `.pending()` stores its options with it; `loading.tsx` exports them by name.
|
|
136
|
+
if (pendingIdent) {
|
|
137
|
+
parts.push(
|
|
138
|
+
seg.fromRoute
|
|
139
|
+
? `pending: ${pendingIdent}.route.pending`
|
|
140
|
+
: `pending: { component: ${pendingIdent}.default, minMs: ${pendingIdent}.pendingMinMs, ms: ${pendingIdent}.pendingMs }`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
134
143
|
if (seg.depth === 0 && seg.path.replaceAll("\\", "/") !== rootDirectory) {
|
|
135
144
|
parts.push("isRoot: false");
|
|
136
145
|
}
|
|
@@ -157,7 +166,7 @@ function hydrateEntry(
|
|
|
157
166
|
? `, segmentBoundaries: [${boundaryLiterals.join(", ")}]`
|
|
158
167
|
: "";
|
|
159
168
|
const pageComponentKey = JSON.stringify(`page:${modulePathKey(resolvedPage)}`);
|
|
160
|
-
const loadBody = `Promise.all([${lazyImports.join(", ")}]).then(([${importIdents.join(", ")}]) => { const __furin_page_route = __furin_page.route; let __furin_parent = root; ${layoutAssignments} return { default: { __type: "FURIN_PAGE", _route: { __type: "FURIN_ROUTE", parent: __furin_parent, remountDeps: __furin_page_route.remountDeps }, component: hotComponent(${pageComponentKey}, __furin_page_route.component) }${boundaryResult} }; })`;
|
|
169
|
+
const loadBody = `Promise.all([${lazyImports.join(", ")}]).then(([${importIdents.join(", ")}]) => { const __furin_page_route = __furin_page.route; let __furin_parent = root; ${layoutAssignments} return { default: { __type: "FURIN_PAGE", _route: { __type: "FURIN_ROUTE", parent: __furin_parent, loaderDeps: __furin_page_route.loaderDeps, remountDeps: __furin_page_route.remountDeps }, component: hotComponent(${pageComponentKey}, __furin_page_route.component) }${boundaryResult} }; })`;
|
|
161
170
|
|
|
162
171
|
const searchDefaultsEntry = searchDefaults
|
|
163
172
|
? `, searchDefaults: ${JSON.stringify(searchDefaults)}`
|
|
@@ -20,7 +20,9 @@ function routeModulePaths(route: BuildRouteInput): string[] {
|
|
|
20
20
|
.filter((entry) => entry.layout && entry.sourcePath)
|
|
21
21
|
.map((entry) => entry.sourcePath as string);
|
|
22
22
|
const boundaries = (route.segmentBoundaries ?? []).flatMap((segment) =>
|
|
23
|
-
[segment.errorPath, segment.notFoundPath].filter(
|
|
23
|
+
[segment.errorPath, segment.notFoundPath, segment.pendingPath].filter(
|
|
24
|
+
(path) => path !== undefined
|
|
25
|
+
)
|
|
24
26
|
);
|
|
25
27
|
return [route.path, ...layouts, ...boundaries];
|
|
26
28
|
}
|
|
@@ -31,7 +31,7 @@ export interface BuildRoute
|
|
|
31
31
|
routeChain: { layout: boolean; sourcePath?: string }[];
|
|
32
32
|
segmentBoundaries: Pick<
|
|
33
33
|
SegmentBoundary,
|
|
34
|
-
"depth" | "path" | "errorPath" | "fromRoute" | "notFoundPath"
|
|
34
|
+
"depth" | "path" | "errorPath" | "fromRoute" | "notFoundPath" | "pendingPath"
|
|
35
35
|
>[];
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -84,12 +84,13 @@ export function buildRouteMetadata(route: ResolvedRoute): BuildRoute {
|
|
|
84
84
|
sourcePath: entry.sourcePath,
|
|
85
85
|
})),
|
|
86
86
|
segmentBoundaries: route.segmentBoundaries.map(
|
|
87
|
-
({ depth, path, errorPath, fromRoute, notFoundPath }) => ({
|
|
87
|
+
({ depth, path, errorPath, fromRoute, notFoundPath, pendingPath }) => ({
|
|
88
88
|
depth,
|
|
89
89
|
path,
|
|
90
90
|
errorPath,
|
|
91
91
|
...(fromRoute ? { fromRoute } : {}),
|
|
92
92
|
notFoundPath,
|
|
93
|
+
pendingPath,
|
|
93
94
|
})
|
|
94
95
|
),
|
|
95
96
|
tags: route.tags,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ErrorComponent } from "../shared/error.ts";
|
|
2
2
|
import type { NotFoundComponent } from "../shared/not-found.ts";
|
|
3
3
|
import type { RemountDeps } from "../shared/page-key.ts";
|
|
4
|
+
import type { PendingComponent, PendingOptions, RoutePending } from "../shared/pending.ts";
|
|
4
5
|
|
|
5
6
|
type ClientComponent = (props: never) => React.ReactNode;
|
|
6
7
|
|
|
@@ -14,17 +15,25 @@ interface ClientRuntimeProps {
|
|
|
14
15
|
|
|
15
16
|
type ClientRuntimeComponent = (props: ClientRuntimeProps) => React.ReactNode;
|
|
16
17
|
|
|
18
|
+
type LoaderDeps = (query: never) => object;
|
|
19
|
+
|
|
17
20
|
interface ClientBuilderState {
|
|
18
21
|
errorComponent: ErrorComponent | undefined;
|
|
22
|
+
loaderDeps: LoaderDeps | undefined;
|
|
19
23
|
notFoundComponent: NotFoundComponent | undefined;
|
|
24
|
+
pending: RoutePending | undefined;
|
|
20
25
|
remountDeps: RemountDeps<never, never> | undefined;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
function createRouteBuilder(state: ClientBuilderState) {
|
|
24
|
-
const { errorComponent, notFoundComponent, remountDeps } = state;
|
|
29
|
+
const { errorComponent, loaderDeps, notFoundComponent, pending, remountDeps } = state;
|
|
25
30
|
return {
|
|
26
|
-
config(options: { remountDeps?: RemountDeps<never, never> }) {
|
|
27
|
-
return createRouteBuilder({
|
|
31
|
+
config(options: { loaderDeps?: LoaderDeps; remountDeps?: RemountDeps<never, never> }) {
|
|
32
|
+
return createRouteBuilder({
|
|
33
|
+
...state,
|
|
34
|
+
loaderDeps: options.loaderDeps,
|
|
35
|
+
remountDeps: options.remountDeps,
|
|
36
|
+
});
|
|
28
37
|
},
|
|
29
38
|
error(component: ErrorComponent) {
|
|
30
39
|
return createRouteBuilder({ ...state, errorComponent: component });
|
|
@@ -37,19 +46,28 @@ function createRouteBuilder(state: ClientBuilderState) {
|
|
|
37
46
|
errorComponent,
|
|
38
47
|
layout: runtimeComponent,
|
|
39
48
|
notFoundComponent,
|
|
49
|
+
pending,
|
|
40
50
|
};
|
|
41
51
|
},
|
|
42
52
|
notFound(component: NotFoundComponent) {
|
|
43
53
|
return createRouteBuilder({ ...state, notFoundComponent: component });
|
|
44
54
|
},
|
|
55
|
+
pending(component: PendingComponent, options?: PendingOptions) {
|
|
56
|
+
return createRouteBuilder({
|
|
57
|
+
...state,
|
|
58
|
+
pending: { component, minMs: options?.minMs, ms: options?.ms },
|
|
59
|
+
});
|
|
60
|
+
},
|
|
45
61
|
page<Component extends ClientComponent>(component: Component) {
|
|
46
62
|
const runtimeComponent = component as unknown as ClientRuntimeComponent;
|
|
47
63
|
return {
|
|
48
64
|
__type: "FURIN_ROUTE" as const,
|
|
49
65
|
component: runtimeComponent,
|
|
50
66
|
errorComponent,
|
|
67
|
+
loaderDeps,
|
|
51
68
|
notFoundComponent,
|
|
52
69
|
page: runtimeComponent,
|
|
70
|
+
pending,
|
|
53
71
|
remountDeps,
|
|
54
72
|
};
|
|
55
73
|
},
|
|
@@ -58,7 +76,9 @@ function createRouteBuilder(state: ClientBuilderState) {
|
|
|
58
76
|
|
|
59
77
|
const EMPTY_BUILDER: ClientBuilderState = {
|
|
60
78
|
errorComponent: undefined,
|
|
79
|
+
loaderDeps: undefined,
|
|
61
80
|
notFoundComponent: undefined,
|
|
81
|
+
pending: undefined,
|
|
62
82
|
remountDeps: undefined,
|
|
63
83
|
};
|
|
64
84
|
|
|
@@ -4,6 +4,8 @@ import type { RequestLoaderContext } from "../../define-route.ts";
|
|
|
4
4
|
import type { ErrorComponent } from "../../shared/error.ts";
|
|
5
5
|
import type { NotFoundComponent } from "../../shared/not-found.ts";
|
|
6
6
|
import type { RemountDeps } from "../../shared/page-key.ts";
|
|
7
|
+
import type { RoutePending } from "../../shared/pending.ts";
|
|
8
|
+
import type { SearchParamsInput } from "../../shared/search-params.ts";
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Loader data after type erasure: field name → value. Each route declares the
|
|
@@ -29,11 +31,15 @@ export interface RuntimeRoute {
|
|
|
29
31
|
errorComponent?: ErrorComponent;
|
|
30
32
|
layout?: React.FC<RuntimeData & { children: React.ReactNode }>;
|
|
31
33
|
loader?: (ctx: RuntimeData) => Awaitable<RuntimeData>;
|
|
34
|
+
/** Page-only: the part of the validated query its loaders read. */
|
|
35
|
+
loaderDeps?: (query: SearchParamsInput) => object;
|
|
32
36
|
mode?: RenderingMode;
|
|
33
37
|
/** TanStack style: `.notFound()` of the route. */
|
|
34
38
|
notFoundComponent?: NotFoundComponent;
|
|
35
39
|
params?: unknown;
|
|
36
40
|
parent?: RuntimeRoute;
|
|
41
|
+
/** TanStack style: `.pending()` of the route. */
|
|
42
|
+
pending?: RoutePending;
|
|
37
43
|
query?: unknown;
|
|
38
44
|
remountDeps?: RemountDeps<object, object>;
|
|
39
45
|
requestLoader?: (ctx: RequestLoaderContext) => Awaitable<object>;
|
|
@@ -52,6 +58,7 @@ export interface RuntimePage {
|
|
|
52
58
|
loader?: (ctx: RuntimeData) => Awaitable<RuntimeData>;
|
|
53
59
|
mode?: RenderingMode;
|
|
54
60
|
notFoundComponent?: NotFoundComponent;
|
|
61
|
+
pending?: RoutePending;
|
|
55
62
|
revalidate?: number;
|
|
56
63
|
staticParams?: RuntimeStaticParams;
|
|
57
64
|
tags?: string[];
|
package/src/client/link.tsx
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import type React from "react";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
createElement,
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useSyncExternalStore,
|
|
11
|
+
} from "react";
|
|
5
12
|
import {
|
|
6
13
|
findSearchDefaultsForRouteTarget,
|
|
7
14
|
type SearchParamsInput,
|
|
@@ -12,6 +19,7 @@ import {
|
|
|
12
19
|
buildHref,
|
|
13
20
|
navigationHrefPolicy,
|
|
14
21
|
normalizeHref,
|
|
22
|
+
resolveTargetSearch,
|
|
15
23
|
shouldInterceptClick,
|
|
16
24
|
} from "./router/link-utils.ts";
|
|
17
25
|
import type {
|
|
@@ -110,6 +118,7 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
110
118
|
replace,
|
|
111
119
|
disabled,
|
|
112
120
|
resetScroll,
|
|
121
|
+
shallow,
|
|
113
122
|
activeProps,
|
|
114
123
|
inactiveProps,
|
|
115
124
|
onClick,
|
|
@@ -129,6 +138,18 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
129
138
|
// logicalHref: route-relative path (no basePath), used for navigation + active state.
|
|
130
139
|
// physicalHref (href): what the browser sees — basePath + logicalHref.
|
|
131
140
|
const { activeHref, logicalHref, href } = resolveLinkHref({ hash, params, search, to }, router);
|
|
141
|
+
// Keyed by `logicalHref`, which encodes `to`, `params` and `search`: inline objects keep one identity.
|
|
142
|
+
const targetSearch = useMemo(
|
|
143
|
+
() =>
|
|
144
|
+
resolveTargetSearch(
|
|
145
|
+
// biome-ignore lint/nursery/useReactCompiler: read through `logicalHref`, see above.
|
|
146
|
+
applyLinkParams(to as string, params as Record<string, string | number> | null | undefined),
|
|
147
|
+
search as SearchParamsInput | null | undefined,
|
|
148
|
+
router.searchRoutes
|
|
149
|
+
),
|
|
150
|
+
// react-doctor-disable-next-line react-doctor/exhaustive-deps
|
|
151
|
+
[logicalHref, router.searchRoutes]
|
|
152
|
+
);
|
|
132
153
|
// Select only this Link's active state so unrelated navigation state
|
|
133
154
|
// (isNavigating, other hrefs, search) does not re-render it.
|
|
134
155
|
const isActive = useSyncExternalStore(
|
|
@@ -158,9 +179,9 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
158
179
|
window.location.pathname
|
|
159
180
|
);
|
|
160
181
|
if (target !== null) {
|
|
161
|
-
prefetch(target, { staleTime: effectiveStaleTime });
|
|
182
|
+
prefetch(target, { search: targetSearch, staleTime: effectiveStaleTime });
|
|
162
183
|
}
|
|
163
|
-
}, [prefetch, effectiveStaleTime, router.basePath]);
|
|
184
|
+
}, [prefetch, effectiveStaleTime, router.basePath, targetSearch]);
|
|
164
185
|
|
|
165
186
|
// "render": preload immediately on mount, and again when the target changes.
|
|
166
187
|
useEffect(() => {
|
|
@@ -235,7 +256,7 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
235
256
|
return;
|
|
236
257
|
}
|
|
237
258
|
// navigate() expects the logical href (no basePath prefix).
|
|
238
|
-
router.navigate(target, { replace, resetScroll:
|
|
259
|
+
router.navigate(target, { replace, resetScroll, search: targetSearch, shallow });
|
|
239
260
|
};
|
|
240
261
|
|
|
241
262
|
const handleMouseEnter = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
@@ -333,6 +354,7 @@ function renderLinkElement<To extends RouteTo>(
|
|
|
333
354
|
preloadStaleTime: _ps,
|
|
334
355
|
replace: _r,
|
|
335
356
|
resetScroll: _rs,
|
|
357
|
+
shallow: _sh,
|
|
336
358
|
onClick: _oc,
|
|
337
359
|
onMouseEnter: _ome,
|
|
338
360
|
onMouseLeave: _oml,
|
|
@@ -31,6 +31,8 @@ export interface RouteElementInput {
|
|
|
31
31
|
data: RuntimeData;
|
|
32
32
|
/** `undefined` when no page matched the URL. */
|
|
33
33
|
page: { component: ElementType; pattern: string } | undefined;
|
|
34
|
+
/** Client navigations only: renders in place of everything below the layout at `depth`. */
|
|
35
|
+
pending?: { component: ElementType; depth: number } | undefined;
|
|
34
36
|
/** Passed to the rendered `error.tsx`. */
|
|
35
37
|
reset: () => void;
|
|
36
38
|
/** The root directory's own conventions, used when the root segment failed. */
|
|
@@ -77,6 +79,30 @@ function wrapLayout(route: RuntimeRoute | undefined, props: RuntimeData, element
|
|
|
77
79
|
return route?.layout ? createElement(route.layout as ElementType, props, element) : element;
|
|
78
80
|
}
|
|
79
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Wraps `element` in the layouts from `depth` up to the root, inside-out: a
|
|
84
|
+
* boundary sits inside the layout at its depth, so it catches that layout's
|
|
85
|
+
* children but not the layout itself.
|
|
86
|
+
*/
|
|
87
|
+
function wrapSegments(
|
|
88
|
+
input: RouteElementInput,
|
|
89
|
+
depth: number,
|
|
90
|
+
props: readonly RuntimeData[],
|
|
91
|
+
fallbackProps: RuntimeData,
|
|
92
|
+
element: ReactNode
|
|
93
|
+
): ReactNode {
|
|
94
|
+
let wrapped = element;
|
|
95
|
+
for (let layout = depth; layout >= 0; layout -= 1) {
|
|
96
|
+
for (const boundary of input.boundaries.toReversed()) {
|
|
97
|
+
if (boundary.depth === layout) {
|
|
98
|
+
wrapped = wrapSegmentBoundaries(wrapped, boundary, input.boundaryOptions);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
wrapped = wrapLayout(input.chain[layout], props[layout] ?? fallbackProps, wrapped);
|
|
102
|
+
}
|
|
103
|
+
return wrapped;
|
|
104
|
+
}
|
|
105
|
+
|
|
80
106
|
function failureElement(
|
|
81
107
|
failure: RouteMatchFailure,
|
|
82
108
|
component: ErrorComponent | NotFoundComponent | undefined,
|
|
@@ -115,9 +141,10 @@ export function resolveRouteElement(input: RouteElementInput): ReactNode {
|
|
|
115
141
|
props.push({ ...inherited, ...context });
|
|
116
142
|
}
|
|
117
143
|
|
|
144
|
+
const { pending } = input;
|
|
118
145
|
const index = matches.findIndex((match) => match.status !== "success");
|
|
119
146
|
const failure = matches[index];
|
|
120
|
-
if (failure && failure.status !== "success") {
|
|
147
|
+
if (failure && failure.status !== "success" && !pending) {
|
|
121
148
|
const { component, depth } = selectRouteBoundary(
|
|
122
149
|
boundaries,
|
|
123
150
|
input.rootBoundary,
|
|
@@ -137,19 +164,18 @@ export function resolveRouteElement(input: RouteElementInput): ReactNode {
|
|
|
137
164
|
const pageProps = Object.fromEntries(
|
|
138
165
|
Object.entries(data).filter(([key]) => !key.startsWith("__furin"))
|
|
139
166
|
);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
167
|
+
// The pending screen keeps the page's tree above it, so shared layouts keep their state.
|
|
168
|
+
const element = pending
|
|
169
|
+
? wrapSegments(input, pending.depth, props, pageProps, createElement(pending.component))
|
|
170
|
+
: wrapSegments(
|
|
171
|
+
input,
|
|
172
|
+
chain.length - 1,
|
|
173
|
+
props,
|
|
174
|
+
pageProps,
|
|
175
|
+
createElement(page.component, {
|
|
176
|
+
...pageProps,
|
|
177
|
+
key: pageKey(page.pattern, pageProps, chain.at(-1)?.remountDeps),
|
|
178
|
+
})
|
|
179
|
+
);
|
|
154
180
|
return withRouteSnapshot(element, page.pattern, pageProps);
|
|
155
181
|
}
|