@teyik0/furin 0.9.0-alpha.4 → 0.9.0-alpha.5
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/build/index.js +65 -25
- package/dist/build/route-metadata.d.ts +1 -1
- package/dist/cli/index.js +65 -25
- 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/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
|
@@ -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
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type Context, createContext, use, useCallback, useContext, useMemo } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
applyLinkParams,
|
|
4
|
+
navigationHrefPolicy,
|
|
5
|
+
type RuntimeRouteTarget,
|
|
6
|
+
resolveRouteTarget,
|
|
7
|
+
resolveTargetSearch,
|
|
8
|
+
} from "./link-utils.ts";
|
|
3
9
|
import type {
|
|
4
10
|
NavigationOptions,
|
|
5
11
|
Prefetch,
|
|
@@ -8,6 +14,7 @@ import type {
|
|
|
8
14
|
RouterNavigate,
|
|
9
15
|
RouterStore,
|
|
10
16
|
StableRouter,
|
|
17
|
+
TargetNavigationOptions,
|
|
11
18
|
} from "./types.ts";
|
|
12
19
|
|
|
13
20
|
// Duplicate module copies (separate entrypoints, client references) must share
|
|
@@ -80,10 +87,18 @@ export function useRouterStore(): RouterStore {
|
|
|
80
87
|
return { getCurrentHref: () => value.currentHref, router: value, subscribe: subscribeNever };
|
|
81
88
|
}
|
|
82
89
|
|
|
90
|
+
function targetSearch(target: RuntimeRouteTarget, routes: StableRouter["searchRoutes"]) {
|
|
91
|
+
return resolveTargetSearch(
|
|
92
|
+
applyLinkParams(target.to, target.params as Record<string, string | number> | undefined),
|
|
93
|
+
target.search,
|
|
94
|
+
routes
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
83
98
|
export function useTypedNavigation(context: StableRouter): Pick<Router, "navigate" | "prefetch"> {
|
|
84
99
|
const { navigate: navigateHref, prefetch: prefetchHref, searchRoutes } = context;
|
|
85
100
|
const navigate: RouterNavigate = useCallback(
|
|
86
|
-
(next: string | (RuntimeRouteTarget &
|
|
101
|
+
(next: string | (RuntimeRouteTarget & TargetNavigationOptions), opts?: NavigationOptions) => {
|
|
87
102
|
const href = typeof next === "string" ? next : resolveRouteTarget(next, searchRoutes);
|
|
88
103
|
const policy = navigationHrefPolicy(
|
|
89
104
|
href,
|
|
@@ -99,11 +114,12 @@ export function useTypedNavigation(context: StableRouter): Pick<Router, "navigat
|
|
|
99
114
|
if (typeof next === "string") {
|
|
100
115
|
return navigateHref(href, opts);
|
|
101
116
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
return navigateHref(href, {
|
|
118
|
+
replace: next.replace,
|
|
119
|
+
resetScroll: next.resetScroll,
|
|
120
|
+
search: targetSearch(next, searchRoutes),
|
|
121
|
+
shallow: next.shallow,
|
|
122
|
+
});
|
|
107
123
|
},
|
|
108
124
|
[navigateHref, searchRoutes]
|
|
109
125
|
);
|
|
@@ -120,7 +136,12 @@ export function useTypedNavigation(context: StableRouter): Pick<Router, "navigat
|
|
|
120
136
|
if (policy !== "internal") {
|
|
121
137
|
return;
|
|
122
138
|
}
|
|
123
|
-
prefetchHref(
|
|
139
|
+
prefetchHref(
|
|
140
|
+
href,
|
|
141
|
+
typeof next === "string"
|
|
142
|
+
? opts
|
|
143
|
+
: { search: targetSearch(next, searchRoutes), staleTime: next.staleTime }
|
|
144
|
+
);
|
|
124
145
|
},
|
|
125
146
|
[prefetchHref, searchRoutes]
|
|
126
147
|
);
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
import type { SearchParamsInput } from "../../shared/search-params.ts";
|
|
2
|
+
|
|
1
3
|
export const SCROLL_STORAGE_KEY = "__furin_scroll__";
|
|
2
4
|
|
|
3
5
|
export function getHistoryKey(state: unknown): string | undefined {
|
|
4
6
|
return (state as { _furinKey?: string } | null)?._furinKey;
|
|
5
7
|
}
|
|
6
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Search furin recorded for the page committed at a history entry: the
|
|
11
|
+
* server-validated query, or the typed search an in-place commit was given.
|
|
12
|
+
*/
|
|
13
|
+
export function getHistorySearch(state: unknown): SearchParamsInput | undefined {
|
|
14
|
+
return (state as { _furinSearch?: SearchParamsInput } | null)?._furinSearch;
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
export function generateHistoryKey(): string {
|
|
8
18
|
return Math.random().toString(36).slice(2, 9);
|
|
9
19
|
}
|
|
@@ -132,6 +132,29 @@ export function resolveRouteTarget(
|
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* The validated search a structured destination will read, as far as the
|
|
137
|
+
* client knows it: `search` over the route's schema defaults, empty values
|
|
138
|
+
* dropped like the URL drops them. Undefined when `path` carries its own
|
|
139
|
+
* query string, which only the server parses.
|
|
140
|
+
*/
|
|
141
|
+
export function resolveTargetSearch(
|
|
142
|
+
path: string,
|
|
143
|
+
search: object | null | undefined,
|
|
144
|
+
routes: SearchRouteMetadata[]
|
|
145
|
+
): SearchParamsInput | undefined {
|
|
146
|
+
if (path.includes("?")) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const resolved: SearchParamsInput = { ...findSearchDefaultsForRouteTarget(path, routes) };
|
|
150
|
+
for (const [key, value] of Object.entries(search ?? {})) {
|
|
151
|
+
if (value !== null && value !== undefined) {
|
|
152
|
+
resolved[key] = value;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return resolved;
|
|
156
|
+
}
|
|
157
|
+
|
|
135
158
|
/**
|
|
136
159
|
* Builds a full href string from a pathname, optional search params, and optional hash.
|
|
137
160
|
* Null/undefined search values are omitted.
|