@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
package/dist/plugin/index.js
CHANGED
|
@@ -3687,14 +3687,16 @@ function memberAccessStart(source, object, property) {
|
|
|
3687
3687
|
const separator = accessGap.replace(/\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/g, (comment) => " ".repeat(comment.length)).lastIndexOf(".");
|
|
3688
3688
|
return object.end + separator - (accessGap[separator - 1] === "?" ? 1 : 0);
|
|
3689
3689
|
}
|
|
3690
|
-
function stripServerStage(module, stripped, range,
|
|
3690
|
+
function stripServerStage(module, stripped, range, policies) {
|
|
3691
3691
|
const { removed, source } = module;
|
|
3692
|
-
if (
|
|
3693
|
-
const
|
|
3694
|
-
for (const
|
|
3695
|
-
|
|
3692
|
+
if (policies.length > 0) {
|
|
3693
|
+
const retained = policies.map((policy) => source.slice(policy.start, policy.end));
|
|
3694
|
+
for (const policy of policies) {
|
|
3695
|
+
for (const name of referencedNames(policy, removed)) {
|
|
3696
|
+
stripped.retained.add(name);
|
|
3697
|
+
}
|
|
3696
3698
|
}
|
|
3697
|
-
replaceRange(module, range.start, range.end, `.config({ ${
|
|
3699
|
+
replaceRange(module, range.start, range.end, `.config({ ${retained.join(", ")} })`);
|
|
3698
3700
|
} else {
|
|
3699
3701
|
removeRange(module, range.start, range.end);
|
|
3700
3702
|
}
|
|
@@ -3707,20 +3709,36 @@ function removeChainedServerCalls(module, bindings, chains, stripped) {
|
|
|
3707
3709
|
if (isRemoved(call, module.removed)) {
|
|
3708
3710
|
continue;
|
|
3709
3711
|
}
|
|
3710
|
-
let
|
|
3712
|
+
let policies = [];
|
|
3711
3713
|
if (property.name === "config" && Array.isArray(call.arguments)) {
|
|
3712
3714
|
const config = unwrapped(call.arguments[0]);
|
|
3713
3715
|
if (config?.type === "ObjectExpression" && Array.isArray(config.properties)) {
|
|
3714
3716
|
collectConfigBindings(config, declarations, stripped.configBindings);
|
|
3715
|
-
|
|
3717
|
+
policies = clientPolicies(config, declarations, stripped.configBindings, filename);
|
|
3716
3718
|
}
|
|
3717
3719
|
}
|
|
3718
3720
|
const accessStart = memberAccessStart(source.original, object, property);
|
|
3719
|
-
stripServerStage(module, stripped, { end: call.end, start: accessStart },
|
|
3721
|
+
stripServerStage(module, stripped, { end: call.end, start: accessStart }, policies);
|
|
3720
3722
|
transformed = true;
|
|
3721
3723
|
}
|
|
3722
3724
|
return transformed;
|
|
3723
3725
|
}
|
|
3726
|
+
function clientPolicies(config, declarations, configBindings, filename) {
|
|
3727
|
+
const resolve = (name) => resolveConfigProperty(config, name, declarations, configBindings, new Set);
|
|
3728
|
+
const loaderDeps = resolve("loaderDeps");
|
|
3729
|
+
const remount = resolve("remountDeps");
|
|
3730
|
+
if (remount === UNRESOLVED) {
|
|
3731
|
+
throw new Error(`[furin] ${filename}: route config spreads must resolve to local object literals; declare remountDeps after dynamic spreads.`);
|
|
3732
|
+
}
|
|
3733
|
+
const policies = [];
|
|
3734
|
+
if (loaderDeps !== null && loaderDeps !== UNRESOLVED) {
|
|
3735
|
+
policies.push(loaderDeps);
|
|
3736
|
+
}
|
|
3737
|
+
if (remount !== null) {
|
|
3738
|
+
policies.push(remount);
|
|
3739
|
+
}
|
|
3740
|
+
return policies;
|
|
3741
|
+
}
|
|
3724
3742
|
function declaredInitializer(declaration) {
|
|
3725
3743
|
return declaration?.type === "VariableDeclarator" ? unwrapped(declaration.init) : null;
|
|
3726
3744
|
}
|
|
@@ -3738,28 +3756,29 @@ function collectConfigBindings(config, declarations, names) {
|
|
|
3738
3756
|
}
|
|
3739
3757
|
}
|
|
3740
3758
|
}
|
|
3741
|
-
|
|
3759
|
+
var UNRESOLVED = Symbol("unresolved");
|
|
3760
|
+
function resolveConfigProperty(config, name, declarations, configBindings, visiting) {
|
|
3742
3761
|
if (config?.type === "Identifier" && !visiting.has(config.name)) {
|
|
3743
3762
|
visiting.add(config.name);
|
|
3744
3763
|
configBindings.add(config.name);
|
|
3745
3764
|
const declaration = declarations.get(config.name);
|
|
3746
|
-
const result =
|
|
3765
|
+
const result = resolveConfigProperty(declaredInitializer(declaration), name, declarations, configBindings, visiting);
|
|
3747
3766
|
visiting.delete(config.name);
|
|
3748
3767
|
return result;
|
|
3749
3768
|
}
|
|
3750
3769
|
if (config?.type !== "ObjectExpression" || !Array.isArray(config.properties)) {
|
|
3751
|
-
|
|
3770
|
+
return UNRESOLVED;
|
|
3752
3771
|
}
|
|
3753
3772
|
for (let index = config.properties.length - 1;index >= 0; index -= 1) {
|
|
3754
3773
|
const entry = unwrapped(config.properties[index]);
|
|
3755
3774
|
if (entry?.type === "SpreadElement") {
|
|
3756
|
-
const
|
|
3757
|
-
if (
|
|
3758
|
-
return
|
|
3775
|
+
const property = resolveConfigProperty(unwrapped(entry.argument), name, declarations, configBindings, visiting);
|
|
3776
|
+
if (property) {
|
|
3777
|
+
return property;
|
|
3759
3778
|
}
|
|
3760
3779
|
} else if (entry?.type === "Property") {
|
|
3761
3780
|
const key = unwrapped(entry.key);
|
|
3762
|
-
if (key?.type === "Identifier" && entry.computed !== true && key.name ===
|
|
3781
|
+
if (key?.type === "Identifier" && entry.computed !== true && key.name === name || key?.type === "Literal" && key.value === name) {
|
|
3763
3782
|
return entry;
|
|
3764
3783
|
}
|
|
3765
3784
|
}
|
|
@@ -4303,8 +4322,8 @@ var ELYSIA_FILTER = /^elysia$/;
|
|
|
4303
4322
|
var BUN_BUILTIN_FILTER = /^bun:/;
|
|
4304
4323
|
var ANY_FILTER = /.*/;
|
|
4305
4324
|
var elysiaStub = (typeModule) => `export * as t from ${JSON.stringify(typeModule)};
|
|
4325
|
+
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, InvalidCookie, NotFound, ParseError, ValidationError, problem, status, validationDetail } from ${JSON.stringify(Bun.resolveSync("elysia/error", dirname4(typeModule)))};
|
|
4306
4326
|
export class NotFoundError extends Error { constructor(m) { super(m); this.name = "NotFoundError"; } }
|
|
4307
|
-
export class ValidationError extends Error { constructor(m) { super(m); this.name = "ValidationError"; } }
|
|
4308
4327
|
export default {};
|
|
4309
4328
|
`;
|
|
4310
4329
|
var ELYSIA_STUB_PREFIX = "elysia-stub:";
|
|
@@ -25,11 +25,12 @@ export interface ManifestRoute {
|
|
|
25
25
|
pattern: string;
|
|
26
26
|
sourcePath: string;
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
28
|
+
/** The Next.js-style `error` / `not-found` / `loading` files declared in one directory. */
|
|
29
29
|
export interface ManifestBoundary {
|
|
30
30
|
directory: string;
|
|
31
31
|
errorPath: string | undefined;
|
|
32
32
|
notFoundPath: string | undefined;
|
|
33
|
+
pendingPath: string | undefined;
|
|
33
34
|
}
|
|
34
35
|
export interface RouteManifest {
|
|
35
36
|
/** Directory boundaries, shallow → deep. Always empty in the TanStack style. */
|
|
@@ -4,7 +4,7 @@ import { type RouteChains } from "./route-chains.ts";
|
|
|
4
4
|
export interface StrippedCode {
|
|
5
5
|
/** Config bindings the stripped `.config()` calls referenced. */
|
|
6
6
|
configBindings: Set<string>;
|
|
7
|
-
/** Names the retained
|
|
7
|
+
/** Names the retained client policies reference. */
|
|
8
8
|
retained: Set<string>;
|
|
9
9
|
}
|
|
10
10
|
export declare function removeChainedServerCalls(module: ModuleTransform, bindings: FactoryBindings, chains: RouteChains, stripped: StrippedCode): boolean;
|
package/dist/server/internal.js
CHANGED
|
@@ -3208,6 +3208,18 @@ function applyLinkParams(to, params) {
|
|
|
3208
3208
|
}
|
|
3209
3209
|
return url;
|
|
3210
3210
|
}
|
|
3211
|
+
function resolveTargetSearch(path, search, routes) {
|
|
3212
|
+
if (path.includes("?")) {
|
|
3213
|
+
return;
|
|
3214
|
+
}
|
|
3215
|
+
const resolved = { ...findSearchDefaultsForRouteTarget(path, routes) };
|
|
3216
|
+
for (const [key, value] of Object.entries(search ?? {})) {
|
|
3217
|
+
if (value !== null && value !== undefined) {
|
|
3218
|
+
resolved[key] = value;
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
return resolved;
|
|
3222
|
+
}
|
|
3211
3223
|
function buildHref(to, search, hash, searchDefaults) {
|
|
3212
3224
|
let url = to;
|
|
3213
3225
|
if (search && Object.keys(search).length > 0) {
|
|
@@ -8512,7 +8524,14 @@ function withDocumentState(element, assets, head, data, nonce, jsonCompatible) {
|
|
|
8512
8524
|
|
|
8513
8525
|
// src/client/link.tsx
|
|
8514
8526
|
init_search_params();
|
|
8515
|
-
import {
|
|
8527
|
+
import {
|
|
8528
|
+
createElement as createElement6,
|
|
8529
|
+
useCallback as useCallback3,
|
|
8530
|
+
useEffect as useEffect2,
|
|
8531
|
+
useMemo as useMemo2,
|
|
8532
|
+
useRef,
|
|
8533
|
+
useSyncExternalStore as useSyncExternalStore2
|
|
8534
|
+
} from "react";
|
|
8516
8535
|
|
|
8517
8536
|
// src/client/router/context.ts
|
|
8518
8537
|
init_link_utils();
|
|
@@ -8781,6 +8800,18 @@ function selectRouteBoundary(boundaries, rootBoundary, index, kind) {
|
|
|
8781
8800
|
function wrapLayout(route, props, element) {
|
|
8782
8801
|
return route?.layout ? createElement5(route.layout, props, element) : element;
|
|
8783
8802
|
}
|
|
8803
|
+
function wrapSegments(input, depth, props, fallbackProps, element) {
|
|
8804
|
+
let wrapped = element;
|
|
8805
|
+
for (let layout = depth;layout >= 0; layout -= 1) {
|
|
8806
|
+
for (const boundary of input.boundaries.toReversed()) {
|
|
8807
|
+
if (boundary.depth === layout) {
|
|
8808
|
+
wrapped = wrapSegmentBoundaries(wrapped, boundary, input.boundaryOptions);
|
|
8809
|
+
}
|
|
8810
|
+
}
|
|
8811
|
+
wrapped = wrapLayout(input.chain[layout], props[layout] ?? fallbackProps, wrapped);
|
|
8812
|
+
}
|
|
8813
|
+
return wrapped;
|
|
8814
|
+
}
|
|
8784
8815
|
function failureElement(failure, component, reset) {
|
|
8785
8816
|
if (failure.status === "error") {
|
|
8786
8817
|
return createElement5(component ?? DefaultErrorFallback, {
|
|
@@ -8805,9 +8836,10 @@ function resolveRouteElement(input) {
|
|
|
8805
8836
|
inherited = { ...inherited, ...match.loaderData };
|
|
8806
8837
|
props.push({ ...inherited, ...context });
|
|
8807
8838
|
}
|
|
8839
|
+
const { pending } = input;
|
|
8808
8840
|
const index = matches.findIndex((match) => match.status !== "success");
|
|
8809
8841
|
const failure = matches[index];
|
|
8810
|
-
if (failure && failure.status !== "success") {
|
|
8842
|
+
if (failure && failure.status !== "success" && !pending) {
|
|
8811
8843
|
const { component, depth } = selectRouteBoundary(boundaries, input.rootBoundary, index, failure.status);
|
|
8812
8844
|
let element = failureElement(failure, component, input.reset);
|
|
8813
8845
|
for (let layout = depth;layout >= 0; layout -= 1) {
|
|
@@ -8819,18 +8851,10 @@ function resolveRouteElement(input) {
|
|
|
8819
8851
|
throw new Error("[furin] internal invariant: a successful route render requires a page.");
|
|
8820
8852
|
}
|
|
8821
8853
|
const pageProps = Object.fromEntries(Object.entries(data).filter(([key]) => !key.startsWith("__furin")));
|
|
8822
|
-
|
|
8854
|
+
const element = pending ? wrapSegments(input, pending.depth, props, pageProps, createElement5(pending.component)) : wrapSegments(input, chain.length - 1, props, pageProps, createElement5(page.component, {
|
|
8823
8855
|
...pageProps,
|
|
8824
8856
|
key: pageKey(page.pattern, pageProps, chain.at(-1)?.remountDeps)
|
|
8825
|
-
});
|
|
8826
|
-
for (let layout = chain.length - 1;layout >= 0; layout -= 1) {
|
|
8827
|
-
for (const boundary of boundaries.toReversed()) {
|
|
8828
|
-
if (boundary.depth === layout) {
|
|
8829
|
-
element = wrapSegmentBoundaries(element, boundary, input.boundaryOptions);
|
|
8830
|
-
}
|
|
8831
|
-
}
|
|
8832
|
-
element = wrapLayout(chain[layout], props[layout] ?? pageProps, element);
|
|
8833
|
-
}
|
|
8857
|
+
}));
|
|
8834
8858
|
return withRouteSnapshot(element, page.pattern, pageProps);
|
|
8835
8859
|
}
|
|
8836
8860
|
|
|
@@ -8937,6 +8961,7 @@ function LinkInteractive({
|
|
|
8937
8961
|
replace,
|
|
8938
8962
|
disabled,
|
|
8939
8963
|
resetScroll,
|
|
8964
|
+
shallow,
|
|
8940
8965
|
activeProps,
|
|
8941
8966
|
inactiveProps,
|
|
8942
8967
|
onClick,
|
|
@@ -8952,6 +8977,7 @@ function LinkInteractive({
|
|
|
8952
8977
|
const anchorRef = useRef(null);
|
|
8953
8978
|
const intentTimerRef = useRef(null);
|
|
8954
8979
|
const { activeHref, logicalHref, href } = resolveLinkHref({ hash, params, search, to }, router2);
|
|
8980
|
+
const targetSearch = useMemo2(() => resolveTargetSearch(applyLinkParams(to, params), search, router2.searchRoutes), [logicalHref, router2.searchRoutes]);
|
|
8955
8981
|
const isActive = useSyncExternalStore2(store.subscribe, () => activeHref !== undefined && store.getCurrentHref() === activeHref, () => activeHref !== undefined && store.getCurrentHref() === activeHref);
|
|
8956
8982
|
const { resolvedChildren, extraProps } = resolveLinkState({ activeProps, children, inactiveProps }, isActive);
|
|
8957
8983
|
const effectivePreload = preload ?? router2.defaultPreload;
|
|
@@ -8965,9 +8991,9 @@ function LinkInteractive({
|
|
|
8965
8991
|
}
|
|
8966
8992
|
const target = shouldInterceptClick(anchor, { altKey: false, ctrlKey: false, metaKey: false, shiftKey: false }, router2.basePath, window.location.origin, window.location.pathname);
|
|
8967
8993
|
if (target !== null) {
|
|
8968
|
-
prefetch(target, { staleTime: effectiveStaleTime });
|
|
8994
|
+
prefetch(target, { search: targetSearch, staleTime: effectiveStaleTime });
|
|
8969
8995
|
}
|
|
8970
|
-
}, [prefetch, effectiveStaleTime, router2.basePath]);
|
|
8996
|
+
}, [prefetch, effectiveStaleTime, router2.basePath, targetSearch]);
|
|
8971
8997
|
useEffect2(() => {
|
|
8972
8998
|
if (effectivePreload === "render") {
|
|
8973
8999
|
triggerPrefetch();
|
|
@@ -9017,7 +9043,7 @@ function LinkInteractive({
|
|
|
9017
9043
|
window.location.assign(href);
|
|
9018
9044
|
return;
|
|
9019
9045
|
}
|
|
9020
|
-
router2.navigate(target, { replace, resetScroll:
|
|
9046
|
+
router2.navigate(target, { replace, resetScroll, search: targetSearch, shallow });
|
|
9021
9047
|
};
|
|
9022
9048
|
const handleMouseEnter = (e) => {
|
|
9023
9049
|
onMouseEnter?.(e);
|
|
@@ -9085,6 +9111,7 @@ function renderLinkElement(props, router2) {
|
|
|
9085
9111
|
preloadStaleTime: _ps,
|
|
9086
9112
|
replace: _r,
|
|
9087
9113
|
resetScroll: _rs,
|
|
9114
|
+
shallow: _sh,
|
|
9088
9115
|
onClick: _oc,
|
|
9089
9116
|
onMouseEnter: _ome,
|
|
9090
9117
|
onMouseLeave: _oml,
|
|
@@ -3,6 +3,7 @@ import type { HeadOptions, RenderingMode } from "../../client.ts";
|
|
|
3
3
|
import type { ErrorComponent } from "../../shared/error.ts";
|
|
4
4
|
import type { NotFoundComponent } from "../../shared/not-found.ts";
|
|
5
5
|
import type { RemountDependency } from "../../shared/page-key.ts";
|
|
6
|
+
import type { RoutePending } from "../../shared/pending.ts";
|
|
6
7
|
interface DefinedRouteTerminal {
|
|
7
8
|
__type: "FURIN_ROUTE";
|
|
8
9
|
component: (...args: never[]) => React.ReactNode;
|
|
@@ -11,9 +12,11 @@ interface DefinedRouteTerminal {
|
|
|
11
12
|
head?: (...args: never[]) => HeadOptions;
|
|
12
13
|
layout?: (...args: never[]) => React.ReactNode;
|
|
13
14
|
loader?: (...args: never[]) => unknown;
|
|
15
|
+
loaderDeps?: (query: never) => object;
|
|
14
16
|
mode?: RenderingMode;
|
|
15
17
|
notFoundComponent?: NotFoundComponent;
|
|
16
18
|
page?: (...args: never[]) => React.ReactNode;
|
|
19
|
+
pending?: RoutePending;
|
|
17
20
|
remountDeps?: (context: never) => readonly RemountDependency[];
|
|
18
21
|
requestLoader?: (...args: never[]) => unknown;
|
|
19
22
|
revalidate?: number;
|
|
@@ -34,6 +34,11 @@ export interface SegmentBoundary {
|
|
|
34
34
|
* except the root's, which is the pages directory.
|
|
35
35
|
*/
|
|
36
36
|
path: string;
|
|
37
|
+
/**
|
|
38
|
+
* Module declaring the pending screen: a `loading.tsx`, or the route file
|
|
39
|
+
* of a `fromRoute` boundary. Only the client renders it.
|
|
40
|
+
*/
|
|
41
|
+
pendingPath?: string;
|
|
37
42
|
}
|
|
38
43
|
/** A layout wrapping a page, from the route manifest. */
|
|
39
44
|
export interface ResolvedLayout {
|
|
@@ -59,7 +64,8 @@ export interface ResolvedRoute {
|
|
|
59
64
|
routeChain: RuntimeRoute[];
|
|
60
65
|
/**
|
|
61
66
|
* Per-directory boundary chain, ordered shallow → deep. Only directories
|
|
62
|
-
* that DECLARE at least one of `error.tsx` / `not-found.tsx`
|
|
67
|
+
* that DECLARE at least one of `error.tsx` / `not-found.tsx` / `loading.tsx`
|
|
68
|
+
* (or routes with `.error()` / `.notFound()` / `.pending()`) are included;
|
|
63
69
|
* directories without conventions are skipped. Empty when no conventions
|
|
64
70
|
* exist anywhere in the path.
|
|
65
71
|
*/
|
|
@@ -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/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,
|