@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/client/link.js
CHANGED
|
@@ -14,17 +14,18 @@ import {
|
|
|
14
14
|
isAbortError,
|
|
15
15
|
createInvalidationRefresh,
|
|
16
16
|
createSyncCatchUp
|
|
17
|
-
} from "./chunks/client-
|
|
17
|
+
} from "./chunks/client-whph3y67.js";
|
|
18
18
|
import {
|
|
19
19
|
restoreRscSource2
|
|
20
20
|
} from "./chunks/client-k88668k7.js";
|
|
21
21
|
import {
|
|
22
22
|
createSearchStore,
|
|
23
23
|
SearchStoreContext
|
|
24
|
-
} from "./chunks/client-
|
|
24
|
+
} from "./chunks/client-hjqd5m3b.js";
|
|
25
25
|
import {
|
|
26
26
|
physicalPath,
|
|
27
27
|
isWithinPrefix,
|
|
28
|
+
deepEqual,
|
|
28
29
|
findSearchDefaultsForRouteTarget,
|
|
29
30
|
TRAILING_SLASHES_RE,
|
|
30
31
|
navigationHrefPolicy,
|
|
@@ -32,6 +33,7 @@ import {
|
|
|
32
33
|
isSameOriginFetchResult,
|
|
33
34
|
applyLinkParams,
|
|
34
35
|
resolveRouteTarget,
|
|
36
|
+
resolveTargetSearch,
|
|
35
37
|
buildHref2,
|
|
36
38
|
applyRevalidateHeader2,
|
|
37
39
|
applyRevalidateEntries,
|
|
@@ -41,10 +43,17 @@ import {
|
|
|
41
43
|
shouldRefetch2,
|
|
42
44
|
shouldInterceptClick2,
|
|
43
45
|
toLogical2
|
|
44
|
-
} from "./chunks/client-
|
|
46
|
+
} from "./chunks/client-xf7r768c.js";
|
|
45
47
|
|
|
46
48
|
// src/client/link.tsx
|
|
47
|
-
import {
|
|
49
|
+
import {
|
|
50
|
+
createElement as createElement2,
|
|
51
|
+
useCallback as useCallback3,
|
|
52
|
+
useEffect as useEffect6,
|
|
53
|
+
useMemo as useMemo3,
|
|
54
|
+
useRef as useRef3,
|
|
55
|
+
useSyncExternalStore as useSyncExternalStore2
|
|
56
|
+
} from "react";
|
|
48
57
|
|
|
49
58
|
// src/client/router/context.ts
|
|
50
59
|
import { createContext, use, useCallback, useContext, useMemo } from "react";
|
|
@@ -91,6 +100,9 @@ function useRouterStore() {
|
|
|
91
100
|
const value = use(RouterContext) ?? CLIENT_FALLBACK_ROUTER;
|
|
92
101
|
return { getCurrentHref: () => value.currentHref, router: value, subscribe: subscribeNever };
|
|
93
102
|
}
|
|
103
|
+
function targetSearch(target, routes) {
|
|
104
|
+
return resolveTargetSearch(applyLinkParams(target.to, target.params), target.search, routes);
|
|
105
|
+
}
|
|
94
106
|
function useTypedNavigation(context) {
|
|
95
107
|
const { navigate: navigateHref, prefetch: prefetchHref, searchRoutes } = context;
|
|
96
108
|
const navigate = useCallback((next, opts) => {
|
|
@@ -106,8 +118,12 @@ function useTypedNavigation(context) {
|
|
|
106
118
|
if (typeof next === "string") {
|
|
107
119
|
return navigateHref(href, opts);
|
|
108
120
|
}
|
|
109
|
-
|
|
110
|
-
|
|
121
|
+
return navigateHref(href, {
|
|
122
|
+
replace: next.replace,
|
|
123
|
+
resetScroll: next.resetScroll,
|
|
124
|
+
search: targetSearch(next, searchRoutes),
|
|
125
|
+
shallow: next.shallow
|
|
126
|
+
});
|
|
111
127
|
}, [navigateHref, searchRoutes]);
|
|
112
128
|
const prefetch = useCallback((next, opts) => {
|
|
113
129
|
const href = typeof next === "string" ? next : resolveRouteTarget(next, searchRoutes);
|
|
@@ -115,7 +131,7 @@ function useTypedNavigation(context) {
|
|
|
115
131
|
if (policy !== "internal") {
|
|
116
132
|
return;
|
|
117
133
|
}
|
|
118
|
-
prefetchHref(href, typeof next === "string" ? opts : { staleTime: next.staleTime });
|
|
134
|
+
prefetchHref(href, typeof next === "string" ? opts : { search: targetSearch(next, searchRoutes), staleTime: next.staleTime });
|
|
119
135
|
}, [prefetchHref, searchRoutes]);
|
|
120
136
|
return { navigate, prefetch };
|
|
121
137
|
}
|
|
@@ -772,6 +788,18 @@ function selectRouteBoundary(boundaries, rootBoundary, index, kind) {
|
|
|
772
788
|
function wrapLayout(route, props, element) {
|
|
773
789
|
return route?.layout ? createElement(route.layout, props, element) : element;
|
|
774
790
|
}
|
|
791
|
+
function wrapSegments(input, depth, props, fallbackProps, element) {
|
|
792
|
+
let wrapped = element;
|
|
793
|
+
for (let layout = depth;layout >= 0; layout -= 1) {
|
|
794
|
+
for (const boundary of input.boundaries.toReversed()) {
|
|
795
|
+
if (boundary.depth === layout) {
|
|
796
|
+
wrapped = wrapSegmentBoundaries(wrapped, boundary, input.boundaryOptions);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
wrapped = wrapLayout(input.chain[layout], props[layout] ?? fallbackProps, wrapped);
|
|
800
|
+
}
|
|
801
|
+
return wrapped;
|
|
802
|
+
}
|
|
775
803
|
function failureElement(failure, component, reset) {
|
|
776
804
|
if (failure.status === "error") {
|
|
777
805
|
return createElement(component ?? DefaultErrorFallback, {
|
|
@@ -796,9 +824,10 @@ function resolveRouteElement(input) {
|
|
|
796
824
|
inherited = { ...inherited, ...match.loaderData };
|
|
797
825
|
props.push({ ...inherited, ...context });
|
|
798
826
|
}
|
|
827
|
+
const { pending } = input;
|
|
799
828
|
const index = matches.findIndex((match) => match.status !== "success");
|
|
800
829
|
const failure = matches[index];
|
|
801
|
-
if (failure && failure.status !== "success") {
|
|
830
|
+
if (failure && failure.status !== "success" && !pending) {
|
|
802
831
|
const { component, depth } = selectRouteBoundary(boundaries, input.rootBoundary, index, failure.status);
|
|
803
832
|
let element = failureElement(failure, component, input.reset);
|
|
804
833
|
for (let layout = depth;layout >= 0; layout -= 1) {
|
|
@@ -810,18 +839,10 @@ function resolveRouteElement(input) {
|
|
|
810
839
|
throw new Error("[furin] internal invariant: a successful route render requires a page.");
|
|
811
840
|
}
|
|
812
841
|
const pageProps = Object.fromEntries(Object.entries(data).filter(([key]) => !key.startsWith("__furin")));
|
|
813
|
-
|
|
842
|
+
const element = pending ? wrapSegments(input, pending.depth, props, pageProps, createElement(pending.component)) : wrapSegments(input, chain.length - 1, props, pageProps, createElement(page.component, {
|
|
814
843
|
...pageProps,
|
|
815
844
|
key: pageKey(page.pattern, pageProps, chain.at(-1)?.remountDeps)
|
|
816
|
-
});
|
|
817
|
-
for (let layout = chain.length - 1;layout >= 0; layout -= 1) {
|
|
818
|
-
for (const boundary of boundaries.toReversed()) {
|
|
819
|
-
if (boundary.depth === layout) {
|
|
820
|
-
element = wrapSegmentBoundaries(element, boundary, input.boundaryOptions);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
element = wrapLayout(chain[layout], props[layout] ?? pageProps, element);
|
|
824
|
-
}
|
|
845
|
+
}));
|
|
825
846
|
return withRouteSnapshot(element, page.pattern, pageProps);
|
|
826
847
|
}
|
|
827
848
|
|
|
@@ -858,6 +879,9 @@ var SCROLL_STORAGE_KEY = "__furin_scroll__";
|
|
|
858
879
|
function getHistoryKey(state) {
|
|
859
880
|
return state?._furinKey;
|
|
860
881
|
}
|
|
882
|
+
function getHistorySearch(state) {
|
|
883
|
+
return state?._furinSearch;
|
|
884
|
+
}
|
|
861
885
|
function generateHistoryKey() {
|
|
862
886
|
return Math.random().toString(36).slice(2, 9);
|
|
863
887
|
}
|
|
@@ -891,6 +915,16 @@ function isRenderable(result) {
|
|
|
891
915
|
function isExpired(entry) {
|
|
892
916
|
return Date.now() - entry.createdAt > entry.staleTime;
|
|
893
917
|
}
|
|
918
|
+
function pathnameOf(href) {
|
|
919
|
+
return normalizeHref2(new URL(href, "http://furin.local").pathname);
|
|
920
|
+
}
|
|
921
|
+
function sharesLoaderDeps(state, stateHref, href, search) {
|
|
922
|
+
const loaderDeps = state.match?.pageRoute.loaderDeps;
|
|
923
|
+
return loaderDeps !== undefined && pathnameOf(stateHref) === pathnameOf(href) && deepEqual(loaderDeps(state.data.query ?? {}), loaderDeps(search));
|
|
924
|
+
}
|
|
925
|
+
function withSearch(state, search) {
|
|
926
|
+
return { ...state, data: { ...state.data, query: search }, finalHref: undefined };
|
|
927
|
+
}
|
|
894
928
|
function historyStateObject() {
|
|
895
929
|
const value = history.state;
|
|
896
930
|
return value !== null && typeof value === "object" ? value : {};
|
|
@@ -910,6 +944,7 @@ class NavigationController {
|
|
|
910
944
|
#pendingUserNavigation = null;
|
|
911
945
|
#renderedHistoryKey;
|
|
912
946
|
#pendingScroll = null;
|
|
947
|
+
#pendingUntil = 0;
|
|
913
948
|
constructor(options) {
|
|
914
949
|
this.#config = options.config;
|
|
915
950
|
this.#optimistic = options.optimistic;
|
|
@@ -942,14 +977,15 @@ class NavigationController {
|
|
|
942
977
|
return this.navigate(href, {
|
|
943
978
|
beforeCommit: request?.beforeCommit,
|
|
944
979
|
hmrRefresh: request?.hmrRefresh,
|
|
980
|
+
pending: false,
|
|
945
981
|
replace: true,
|
|
946
982
|
resetScroll: request?.resetScroll ?? false,
|
|
947
983
|
shouldCommit: request?.shouldCommit
|
|
948
984
|
});
|
|
949
985
|
};
|
|
950
|
-
prefetch = (href, staleTime) => {
|
|
986
|
+
prefetch = (href, staleTime, search) => {
|
|
951
987
|
const existing = this.#cache.get(href);
|
|
952
|
-
if (existing && !isExpired(existing)) {
|
|
988
|
+
if (existing && !isExpired(existing) || search && (this.#inPlace(href, search, false) || this.#sharedPage(href, search))) {
|
|
953
989
|
return;
|
|
954
990
|
}
|
|
955
991
|
const generation = this.#generation.current;
|
|
@@ -1021,9 +1057,11 @@ class NavigationController {
|
|
|
1021
1057
|
}
|
|
1022
1058
|
adoptHistoryEntry() {
|
|
1023
1059
|
history.scrollRestoration = "manual";
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1060
|
+
history.replaceState({
|
|
1061
|
+
...historyStateObject(),
|
|
1062
|
+
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey(),
|
|
1063
|
+
_furinSearch: this.#snapshot.state.data.query
|
|
1064
|
+
}, "");
|
|
1027
1065
|
this.#renderedHistoryKey = getHistoryKey(history.state);
|
|
1028
1066
|
}
|
|
1029
1067
|
takeScrollInstruction() {
|
|
@@ -1040,10 +1078,50 @@ class NavigationController {
|
|
|
1040
1078
|
}
|
|
1041
1079
|
#setNavigating(isNavigating) {
|
|
1042
1080
|
if (this.#snapshot.isNavigating !== isNavigating) {
|
|
1043
|
-
this.#publish({
|
|
1081
|
+
this.#publish({
|
|
1082
|
+
...this.#snapshot,
|
|
1083
|
+
isNavigating,
|
|
1084
|
+
pending: isNavigating ? this.#snapshot.pending : undefined
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
#schedulePending(href, kind, version) {
|
|
1089
|
+
const startedAt = Date.now();
|
|
1090
|
+
const wanted = kind.type === "pop" || !(kind.request.hmrRefresh || kind.request.pending === false);
|
|
1091
|
+
const screen = wanted ? this.#config.resolvePending({ currentMatch: this.#currentMatch(), href }) : Promise.resolve(undefined);
|
|
1092
|
+
screen.then((resolved) => {
|
|
1093
|
+
const shown = this.#snapshot.pending;
|
|
1094
|
+
if (this.#version !== version || shown && shown.component === resolved?.component && shown.depth === resolved.depth) {
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
if (shown) {
|
|
1098
|
+
this.#publish({ ...this.#snapshot, pending: undefined });
|
|
1099
|
+
}
|
|
1100
|
+
if (!resolved) {
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
setTimeout(() => {
|
|
1104
|
+
if (this.#version === version && this.#snapshot.isNavigating) {
|
|
1105
|
+
this.#pendingUntil = Date.now() + resolved.minMs;
|
|
1106
|
+
this.#publish({ ...this.#snapshot, pending: resolved });
|
|
1107
|
+
}
|
|
1108
|
+
}, startedAt + resolved.ms - Date.now());
|
|
1109
|
+
}).catch((error) => {
|
|
1110
|
+
log.warn({ action: "pending_resolve_failed", error: String(error), href });
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
async#holdPending() {
|
|
1114
|
+
const remaining = this.#snapshot.pending ? this.#pendingUntil - Date.now() : 0;
|
|
1115
|
+
if (remaining > 0) {
|
|
1116
|
+
await new Promise((resolve) => setTimeout(resolve, remaining));
|
|
1044
1117
|
}
|
|
1045
1118
|
}
|
|
1046
1119
|
#store(href, entry) {
|
|
1120
|
+
entry.promise.then((page) => {
|
|
1121
|
+
entry.settled = page;
|
|
1122
|
+
}, () => {
|
|
1123
|
+
return;
|
|
1124
|
+
});
|
|
1047
1125
|
this.#cache.delete(href);
|
|
1048
1126
|
this.#cache.set(href, entry);
|
|
1049
1127
|
if (this.#cache.size > this.#config.maxCacheSize) {
|
|
@@ -1082,6 +1160,12 @@ class NavigationController {
|
|
|
1082
1160
|
this.#committedAbort = controller;
|
|
1083
1161
|
}
|
|
1084
1162
|
async#run(href, kind) {
|
|
1163
|
+
const search = kind.type === "push" ? kind.request.search : getHistorySearch(history.state);
|
|
1164
|
+
const shallow = kind.type === "push" && kind.request.shallow === true;
|
|
1165
|
+
if (search && this.#inPlace(href, search, shallow) && !(kind.type === "push" && kind.request.shouldCommit?.() === false)) {
|
|
1166
|
+
this.#commitInPlace(href, kind, search);
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1085
1169
|
const hmrRefresh = kind.type === "push" && kind.request.hmrRefresh === true;
|
|
1086
1170
|
const finishUserNavigation = hmrRefresh ? undefined : this.#beginUserNavigation();
|
|
1087
1171
|
this.#version += 1;
|
|
@@ -1092,12 +1176,13 @@ class NavigationController {
|
|
|
1092
1176
|
abort.signal.addEventListener("abort", onAbort, { once: true });
|
|
1093
1177
|
let committed = false;
|
|
1094
1178
|
this.#setNavigating(true);
|
|
1179
|
+
this.#schedulePending(href, kind, version);
|
|
1095
1180
|
try {
|
|
1096
1181
|
if (abort.signal.aborted) {
|
|
1097
1182
|
return;
|
|
1098
1183
|
}
|
|
1099
1184
|
committed = await Promise.race([
|
|
1100
|
-
this.#load(href, kind, version, abort.signal),
|
|
1185
|
+
this.#load(href, kind, version, abort.signal, search),
|
|
1101
1186
|
cancelled.promise
|
|
1102
1187
|
]);
|
|
1103
1188
|
} finally {
|
|
@@ -1112,8 +1197,8 @@ class NavigationController {
|
|
|
1112
1197
|
#accepts(kind, version) {
|
|
1113
1198
|
return this.#version === version && (kind.type === "pop" || kind.request.shouldCommit?.() !== false);
|
|
1114
1199
|
}
|
|
1115
|
-
async#load(href, kind, version, signal) {
|
|
1116
|
-
const loaded = await this.#read(href, signal, kind.type === "push" && kind.request.hmrRefresh === true);
|
|
1200
|
+
async#load(href, kind, version, signal, search) {
|
|
1201
|
+
const loaded = await this.#read(href, signal, kind.type === "push" && kind.request.hmrRefresh === true, search);
|
|
1117
1202
|
if (!this.#accepts(kind, version)) {
|
|
1118
1203
|
return false;
|
|
1119
1204
|
}
|
|
@@ -1142,6 +1227,7 @@ class NavigationController {
|
|
|
1142
1227
|
this.#hardNavigate(kind, href);
|
|
1143
1228
|
return false;
|
|
1144
1229
|
}
|
|
1230
|
+
await this.#holdPending();
|
|
1145
1231
|
if (!this.#accepts(kind, version)) {
|
|
1146
1232
|
return false;
|
|
1147
1233
|
}
|
|
@@ -1154,7 +1240,7 @@ class NavigationController {
|
|
|
1154
1240
|
}
|
|
1155
1241
|
window.location.href = this.#config.basePath + href;
|
|
1156
1242
|
}
|
|
1157
|
-
async#read(href, signal, hmrRefresh) {
|
|
1243
|
+
async#read(href, signal, hmrRefresh, search) {
|
|
1158
1244
|
const cached = this.#cache.get(href);
|
|
1159
1245
|
if (cached && !isExpired(cached) && !this.#optimistic.has(href)) {
|
|
1160
1246
|
const page = await cached.promise;
|
|
@@ -1162,8 +1248,47 @@ class NavigationController {
|
|
|
1162
1248
|
return { fetched: false, page };
|
|
1163
1249
|
}
|
|
1164
1250
|
}
|
|
1251
|
+
const shared = search && this.#sharedPage(href, search);
|
|
1252
|
+
if (shared) {
|
|
1253
|
+
return { fetched: false, page: shared };
|
|
1254
|
+
}
|
|
1165
1255
|
return { fetched: true, page: await this.#fetchConfirmed(href, signal, hmrRefresh) };
|
|
1166
1256
|
}
|
|
1257
|
+
#inPlace(href, search, shallow) {
|
|
1258
|
+
const { href: committedHref, state } = this.#snapshot;
|
|
1259
|
+
return state.match !== null && !(state.error || state.notFound) && !this.#optimistic.has(committedHref) && (shallow ? pathnameOf(committedHref) === pathnameOf(href) : sharesLoaderDeps(state, committedHref, href, search));
|
|
1260
|
+
}
|
|
1261
|
+
#sharedPage(href, search) {
|
|
1262
|
+
if (this.#optimistic.has(href)) {
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
for (const [cachedHref, entry] of this.#cache) {
|
|
1266
|
+
const page = entry.settled;
|
|
1267
|
+
if (page?.result.kind === "page" && !isExpired(entry) && this.#isReusable(cachedHref, page) && sharesLoaderDeps(page.result.state, cachedHref, href, search)) {
|
|
1268
|
+
return {
|
|
1269
|
+
...page,
|
|
1270
|
+
result: { ...page.result, state: withSearch(page.result.state, search) }
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
#commitInPlace(href, kind, search) {
|
|
1276
|
+
this.#beginUserNavigation()();
|
|
1277
|
+
this.#version += 1;
|
|
1278
|
+
this.#pendingAbort?.abort();
|
|
1279
|
+
this.#pendingAbort = null;
|
|
1280
|
+
const committedHref = kind.type === "push" ? this.#commitPush({
|
|
1281
|
+
...kind.request,
|
|
1282
|
+
resetScroll: kind.request.resetScroll ?? href.includes("#")
|
|
1283
|
+
}, href, search) : this.#commitPop(kind.key, href, href, search);
|
|
1284
|
+
this.#publish({
|
|
1285
|
+
...this.#snapshot,
|
|
1286
|
+
href: committedHref,
|
|
1287
|
+
isNavigating: false,
|
|
1288
|
+
pending: undefined,
|
|
1289
|
+
state: withSearch(this.#snapshot.state, search)
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1167
1292
|
#isReusable(href, page) {
|
|
1168
1293
|
const { result } = page;
|
|
1169
1294
|
return result.kind === "page" && result.reusable() && this.#optimistic.publishable(href, page.revision ?? this.#optimistic.revision(href)) && this.#generation.isFresh(href, result.state, page.generation);
|
|
@@ -1205,7 +1330,7 @@ class NavigationController {
|
|
|
1205
1330
|
return null;
|
|
1206
1331
|
}
|
|
1207
1332
|
visited.add(href);
|
|
1208
|
-
({ page } = await this.#read(href, signal, false));
|
|
1333
|
+
({ page } = await this.#read(href, signal, false, undefined));
|
|
1209
1334
|
}
|
|
1210
1335
|
return isRenderable(page.result) ? { href, page, result: page.result } : null;
|
|
1211
1336
|
}
|
|
@@ -1221,7 +1346,7 @@ class NavigationController {
|
|
|
1221
1346
|
if (kind.type === "push") {
|
|
1222
1347
|
kind.request.beforeCommit?.();
|
|
1223
1348
|
}
|
|
1224
|
-
const href = kind.type === "push" ? this.#commitPush(kind.request, effective) : this.#commitPop(kind.key, effective, requestedHref);
|
|
1349
|
+
const href = kind.type === "push" ? this.#commitPush(kind.request, effective, state.data.query) : this.#commitPop(kind.key, effective, requestedHref, state.data.query);
|
|
1225
1350
|
this.#publish({
|
|
1226
1351
|
href,
|
|
1227
1352
|
isNavigating: false,
|
|
@@ -1236,7 +1361,7 @@ class NavigationController {
|
|
|
1236
1361
|
}
|
|
1237
1362
|
return true;
|
|
1238
1363
|
}
|
|
1239
|
-
#commitPush(request, effective) {
|
|
1364
|
+
#commitPush(request, effective, search) {
|
|
1240
1365
|
const { basePath } = this.#config;
|
|
1241
1366
|
const physical = basePath + effective;
|
|
1242
1367
|
if (request.resetScroll ?? true) {
|
|
@@ -1245,21 +1370,22 @@ class NavigationController {
|
|
|
1245
1370
|
if (request.replace) {
|
|
1246
1371
|
history.replaceState({
|
|
1247
1372
|
...historyStateObject(),
|
|
1248
|
-
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey()
|
|
1373
|
+
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey(),
|
|
1374
|
+
_furinSearch: search
|
|
1249
1375
|
}, "", physical);
|
|
1250
1376
|
} else {
|
|
1251
1377
|
if (this.#renderedHistoryKey) {
|
|
1252
1378
|
saveScrollPosition(this.#renderedHistoryKey);
|
|
1253
1379
|
}
|
|
1254
|
-
history.pushState({ _furinKey: generateHistoryKey() }, "", physical);
|
|
1380
|
+
history.pushState({ _furinKey: generateHistoryKey(), _furinSearch: search }, "", physical);
|
|
1255
1381
|
}
|
|
1256
1382
|
this.#renderedHistoryKey = getHistoryKey(history.state);
|
|
1257
1383
|
const url = new URL(physical, window.location.origin);
|
|
1258
1384
|
return normalizeHref2(toLogical2(url.pathname, basePath)) + url.search;
|
|
1259
1385
|
}
|
|
1260
|
-
#commitPop(key, effective, requestedHref) {
|
|
1386
|
+
#commitPop(key, effective, requestedHref, search) {
|
|
1261
1387
|
if (effective !== requestedHref) {
|
|
1262
|
-
history.replaceState(
|
|
1388
|
+
history.replaceState({ ...historyStateObject(), _furinSearch: search }, "", this.#config.basePath + effective);
|
|
1263
1389
|
}
|
|
1264
1390
|
this.#renderedHistoryKey = key;
|
|
1265
1391
|
if (key) {
|
|
@@ -2985,6 +3111,35 @@ async function fetchPageState(context, rawLogicalHref, signal, hmrRefresh) {
|
|
|
2985
3111
|
}
|
|
2986
3112
|
}
|
|
2987
3113
|
|
|
3114
|
+
// src/client/router/pending.ts
|
|
3115
|
+
var DEFAULT_PENDING_MS = 1000;
|
|
3116
|
+
var DEFAULT_PENDING_MIN_MS = 500;
|
|
3117
|
+
async function resolvePendingScreen(routes, href, current) {
|
|
3118
|
+
const { pathname } = new URL(href, "http://furin.local");
|
|
3119
|
+
const route = routes.find((candidate) => candidate.regex.test(pathname));
|
|
3120
|
+
if (!(route && current)) {
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
const loaded = await route.load();
|
|
3124
|
+
const target = collectRouteChainFromRoute(loaded.default._route);
|
|
3125
|
+
const committed = collectRouteChainFromRoute(current.pageRoute);
|
|
3126
|
+
let shared = 0;
|
|
3127
|
+
while (shared < target.length - 1 && shared < committed.length - 1 && target[shared]?.layout === committed[shared]?.layout) {
|
|
3128
|
+
shared += 1;
|
|
3129
|
+
}
|
|
3130
|
+
const boundary = (loaded.segmentBoundaries ?? route.segmentBoundaries)?.findLast((candidate) => candidate.pending !== undefined && candidate.depth === shared - 1);
|
|
3131
|
+
if (!boundary?.pending) {
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
const { component, minMs, ms } = boundary.pending;
|
|
3135
|
+
return {
|
|
3136
|
+
component,
|
|
3137
|
+
depth: boundary.depth,
|
|
3138
|
+
minMs: minMs ?? DEFAULT_PENDING_MIN_MS,
|
|
3139
|
+
ms: ms ?? DEFAULT_PENDING_MS
|
|
3140
|
+
};
|
|
3141
|
+
}
|
|
3142
|
+
|
|
2988
3143
|
// src/client/router/use-fetch-interception.ts
|
|
2989
3144
|
import { useEffect } from "react";
|
|
2990
3145
|
|
|
@@ -3371,7 +3526,8 @@ function RouterProvider({
|
|
|
3371
3526
|
routes,
|
|
3372
3527
|
staticMode
|
|
3373
3528
|
}, href, signal, hmrRefresh),
|
|
3374
|
-
maxCacheSize: prefetchCacheSize
|
|
3529
|
+
maxCacheSize: prefetchCacheSize,
|
|
3530
|
+
resolvePending: ({ currentMatch, href }) => resolvePendingScreen(routes, href, currentMatch)
|
|
3375
3531
|
}), [
|
|
3376
3532
|
basePath,
|
|
3377
3533
|
defaultPreloadStaleTime,
|
|
@@ -3393,7 +3549,7 @@ function RouterProvider({
|
|
|
3393
3549
|
const { href: currentHref, isNavigating, resetVersion: boundaryResetVersion, state } = navigation;
|
|
3394
3550
|
const { navigate, refresh, invalidatePath: invalidatePrefetch } = controller;
|
|
3395
3551
|
const prefetch = useCallback2((href, opts) => {
|
|
3396
|
-
controller.prefetch(href, opts?.staleTime);
|
|
3552
|
+
controller.prefetch(href, opts?.staleTime, opts?.search);
|
|
3397
3553
|
}, [controller]);
|
|
3398
3554
|
useLayoutEffect2(() => {
|
|
3399
3555
|
state.hydrateQueries?.(state.querySeeds ?? [], typeof window === "undefined" ? undefined : window.location.origin);
|
|
@@ -3546,6 +3702,7 @@ function RouterProvider({
|
|
|
3546
3702
|
},
|
|
3547
3703
|
chain,
|
|
3548
3704
|
data: renderedData,
|
|
3705
|
+
pending: navigation.pending,
|
|
3549
3706
|
page: state.match ? { component: state.match.component, pattern: state.match.pattern } : undefined,
|
|
3550
3707
|
reset: resetRoute,
|
|
3551
3708
|
rootBoundary: rootBoundaries?.[0]
|
|
@@ -3659,6 +3816,7 @@ function LinkInteractive({
|
|
|
3659
3816
|
replace,
|
|
3660
3817
|
disabled,
|
|
3661
3818
|
resetScroll,
|
|
3819
|
+
shallow,
|
|
3662
3820
|
activeProps,
|
|
3663
3821
|
inactiveProps,
|
|
3664
3822
|
onClick,
|
|
@@ -3674,6 +3832,7 @@ function LinkInteractive({
|
|
|
3674
3832
|
const anchorRef = useRef3(null);
|
|
3675
3833
|
const intentTimerRef = useRef3(null);
|
|
3676
3834
|
const { activeHref, logicalHref, href } = resolveLinkHref({ hash, params, search, to }, router2);
|
|
3835
|
+
const targetSearch = useMemo3(() => resolveTargetSearch(applyLinkParams(to, params), search, router2.searchRoutes), [logicalHref, router2.searchRoutes]);
|
|
3677
3836
|
const isActive = useSyncExternalStore2(store.subscribe, () => activeHref !== undefined && store.getCurrentHref() === activeHref, () => activeHref !== undefined && store.getCurrentHref() === activeHref);
|
|
3678
3837
|
const { resolvedChildren, extraProps } = resolveLinkState({ activeProps, children, inactiveProps }, isActive);
|
|
3679
3838
|
const effectivePreload = preload ?? router2.defaultPreload;
|
|
@@ -3687,9 +3846,9 @@ function LinkInteractive({
|
|
|
3687
3846
|
}
|
|
3688
3847
|
const target = shouldInterceptClick2(anchor, { altKey: false, ctrlKey: false, metaKey: false, shiftKey: false }, router2.basePath, window.location.origin, window.location.pathname);
|
|
3689
3848
|
if (target !== null) {
|
|
3690
|
-
prefetch(target, { staleTime: effectiveStaleTime });
|
|
3849
|
+
prefetch(target, { search: targetSearch, staleTime: effectiveStaleTime });
|
|
3691
3850
|
}
|
|
3692
|
-
}, [prefetch, effectiveStaleTime, router2.basePath]);
|
|
3851
|
+
}, [prefetch, effectiveStaleTime, router2.basePath, targetSearch]);
|
|
3693
3852
|
useEffect6(() => {
|
|
3694
3853
|
if (effectivePreload === "render") {
|
|
3695
3854
|
triggerPrefetch();
|
|
@@ -3739,7 +3898,7 @@ function LinkInteractive({
|
|
|
3739
3898
|
window.location.assign(href);
|
|
3740
3899
|
return;
|
|
3741
3900
|
}
|
|
3742
|
-
router2.navigate(target, { replace, resetScroll:
|
|
3901
|
+
router2.navigate(target, { replace, resetScroll, search: targetSearch, shallow });
|
|
3743
3902
|
};
|
|
3744
3903
|
const handleMouseEnter = (e) => {
|
|
3745
3904
|
onMouseEnter?.(e);
|
|
@@ -3807,6 +3966,7 @@ function renderLinkElement(props, router2) {
|
|
|
3807
3966
|
preloadStaleTime: _ps,
|
|
3808
3967
|
replace: _r,
|
|
3809
3968
|
resetScroll: _rs,
|
|
3969
|
+
shallow: _sh,
|
|
3810
3970
|
onClick: _oc,
|
|
3811
3971
|
onMouseEnter: _ome,
|
|
3812
3972
|
onMouseLeave: _oml,
|
|
@@ -23,6 +23,11 @@ export interface RouteElementInput {
|
|
|
23
23
|
component: ElementType;
|
|
24
24
|
pattern: string;
|
|
25
25
|
} | undefined;
|
|
26
|
+
/** Client navigations only: renders in place of everything below the layout at `depth`. */
|
|
27
|
+
pending?: {
|
|
28
|
+
component: ElementType;
|
|
29
|
+
depth: number;
|
|
30
|
+
} | undefined;
|
|
26
31
|
/** Passed to the rendered `error.tsx`. */
|
|
27
32
|
reset: () => void;
|
|
28
33
|
/** The root directory's own conventions, used when the root segment failed. */
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import type { SearchParamsInput } from "../../shared/search-params.ts";
|
|
1
2
|
export declare const SCROLL_STORAGE_KEY = "__furin_scroll__";
|
|
2
3
|
export declare function getHistoryKey(state: unknown): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Search furin recorded for the page committed at a history entry: the
|
|
6
|
+
* server-validated query, or the typed search an in-place commit was given.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getHistorySearch(state: unknown): SearchParamsInput | undefined;
|
|
3
9
|
export declare function generateHistoryKey(): string;
|
|
4
10
|
export declare function saveScrollPosition(key: string): void;
|
|
5
11
|
/**
|
|
@@ -23,6 +23,13 @@ export interface RuntimeRouteTarget {
|
|
|
23
23
|
to: string;
|
|
24
24
|
}
|
|
25
25
|
export declare function resolveRouteTarget(target: RuntimeRouteTarget, routes: SearchRouteMetadata[]): string;
|
|
26
|
+
/**
|
|
27
|
+
* The validated search a structured destination will read, as far as the
|
|
28
|
+
* client knows it: `search` over the route's schema defaults, empty values
|
|
29
|
+
* dropped like the URL drops them. Undefined when `path` carries its own
|
|
30
|
+
* query string, which only the server parses.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveTargetSearch(path: string, search: object | null | undefined, routes: SearchRouteMetadata[]): SearchParamsInput | undefined;
|
|
26
33
|
/**
|
|
27
34
|
* Builds a full href string from a pathname, optional search params, and optional hash.
|
|
28
35
|
* Null/undefined search values are omitted.
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { type SearchParamsInput } from "../../shared/search-params.ts";
|
|
1
2
|
import type { OptimisticRuntime } from "./optimistic.ts";
|
|
2
3
|
import type { PageResult } from "./page-fetch.ts";
|
|
4
|
+
import type { PendingScreen } from "./pending.ts";
|
|
3
5
|
import type { LoadedClientRoute, RouterState } from "./types.ts";
|
|
4
6
|
/** What React renders: the committed page plus navigation status. */
|
|
5
7
|
export interface NavigationSnapshot {
|
|
6
8
|
/** Logical href (basePath stripped) of the committed page. */
|
|
7
9
|
href: string;
|
|
8
10
|
isNavigating: boolean;
|
|
11
|
+
/** Pending screen shown in place of the committed page while a slow navigation loads. */
|
|
12
|
+
pending?: PendingScreen;
|
|
9
13
|
/** Bumped on every non-error commit so error boundaries reset. */
|
|
10
14
|
resetVersion: number;
|
|
11
15
|
state: RouterState;
|
|
@@ -22,17 +26,31 @@ export interface NavigationControllerConfig {
|
|
|
22
26
|
signal: AbortSignal | undefined;
|
|
23
27
|
}) => Promise<PageResult>;
|
|
24
28
|
maxCacheSize: number;
|
|
29
|
+
/** Pending screen of the route `href` targets, measured against the committed match. */
|
|
30
|
+
resolvePending: (request: {
|
|
31
|
+
currentMatch: LoadedClientRoute | null;
|
|
32
|
+
href: string;
|
|
33
|
+
}) => Promise<PendingScreen | undefined>;
|
|
25
34
|
}
|
|
26
35
|
export interface NavigateRequest {
|
|
27
36
|
/** Runs right before the new snapshot is published (HMR swaps components here). */
|
|
28
37
|
beforeCommit?: () => void;
|
|
29
38
|
hmrRefresh?: boolean;
|
|
39
|
+
/** `false` keeps the current page on screen instead of the target's pending screen. */
|
|
40
|
+
pending?: boolean;
|
|
30
41
|
replace?: boolean;
|
|
31
42
|
resetScroll?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Validated search the destination will read. Only with it can a page
|
|
45
|
+
* already loaded for the same path be reused (see `loaderDeps`, `shallow`).
|
|
46
|
+
*/
|
|
47
|
+
search?: SearchParamsInput;
|
|
48
|
+
/** Same path: commit the new URL and search in place without running loaders. */
|
|
49
|
+
shallow?: boolean;
|
|
32
50
|
/** Returning `false` discards the navigation result instead of committing it. */
|
|
33
51
|
shouldCommit?: () => boolean;
|
|
34
52
|
}
|
|
35
|
-
export type RefreshRequest = Omit<NavigateRequest, "replace">;
|
|
53
|
+
export type RefreshRequest = Omit<NavigateRequest, "replace" | "search" | "shallow">;
|
|
36
54
|
export type ScrollInstruction = {
|
|
37
55
|
type: "restore";
|
|
38
56
|
key: string;
|
|
@@ -60,7 +78,7 @@ export declare class NavigationController {
|
|
|
60
78
|
readonly popState: () => void;
|
|
61
79
|
/** Re-fetches the current URL in place. */
|
|
62
80
|
readonly refresh: (request?: RefreshRequest) => Promise<void>;
|
|
63
|
-
readonly prefetch: (href: string, staleTime: number | undefined) => void;
|
|
81
|
+
readonly prefetch: (href: string, staleTime: number | undefined, search?: SearchParamsInput) => void;
|
|
64
82
|
/** Drops cached pages under `path` and marks in-flight ones stale. */
|
|
65
83
|
readonly invalidatePath: (path: string, type: "page" | "layout") => void;
|
|
66
84
|
/** Access changes must also prevent old navigations and deferred streams from publishing. */
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PendingComponent } from "../../shared/pending.ts";
|
|
2
|
+
import type { ClientRoute, LoadedClientRoute } from "./types.ts";
|
|
3
|
+
/** A pending screen to render inside the committed layout at `depth`. */
|
|
4
|
+
export interface PendingScreen {
|
|
5
|
+
component: PendingComponent;
|
|
6
|
+
depth: number;
|
|
7
|
+
minMs: number;
|
|
8
|
+
ms: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The pending screen a navigation to `href` shows, if any. It renders inside
|
|
12
|
+
* the deepest layout the target shares with the current page, in place of
|
|
13
|
+
* the first segment that changes, as in TanStack Router (only the matches
|
|
14
|
+
* being loaded show their pending) and Next.js (a `loading.tsx` falls back
|
|
15
|
+
* only when its child segment changes). The deepest declaration wins.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolvePendingScreen(routes: readonly ClientRoute[], href: string, current: LoadedClientRoute | null): Promise<PendingScreen | undefined>;
|
|
@@ -14,6 +14,8 @@ export type SetSearchInput<To extends SearchRouteTo> = Partial<ResolvedRouteSear
|
|
|
14
14
|
export interface SetSearchOptions {
|
|
15
15
|
replace?: boolean;
|
|
16
16
|
resetScroll?: boolean;
|
|
17
|
+
/** See `TargetNavigationOptions.shallow`. */
|
|
18
|
+
shallow?: boolean;
|
|
17
19
|
}
|
|
18
20
|
export type SetSearch<To extends SearchRouteTo> = (next: SetSearchInput<To>, opts?: SetSearchOptions) => Promise<void>;
|
|
19
21
|
export declare function useSearch<To extends SearchRouteTo>(_from: To & SearchRouteCheck<NoInfer<To>>): [ResolvedRouteSearch<To>, SetSearch<To>];
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FALLBACK_SEARCH_STORE,
|
|
3
3
|
SearchStoreContext
|
|
4
|
-
} from "../../chunks/client-
|
|
4
|
+
} from "../../chunks/client-hjqd5m3b.js";
|
|
5
5
|
import {
|
|
6
6
|
findSearchDefaultsForRouteTarget,
|
|
7
|
+
resolveTargetSearch,
|
|
7
8
|
buildHref2
|
|
8
|
-
} from "../../chunks/client-
|
|
9
|
+
} from "../../chunks/client-xf7r768c.js";
|
|
9
10
|
|
|
10
11
|
// src/client/router/search/index.ts
|
|
11
12
|
import { useCallback, useContext, useMemo, useSyncExternalStore } from "react";
|
|
@@ -51,7 +52,10 @@ function useSearch(from, selector) {
|
|
|
51
52
|
const pathname = pathnameFromLogicalHref(snapshot.currentHref);
|
|
52
53
|
const searchDefaults = findSearchDefaultsForRouteTarget(pathname, snapshot.searchRoutes);
|
|
53
54
|
const href = buildHref2(pathname, merged, undefined, searchDefaults);
|
|
54
|
-
return snapshot.navigate(href,
|
|
55
|
+
return snapshot.navigate(href, {
|
|
56
|
+
...opts,
|
|
57
|
+
search: resolveTargetSearch(pathname, merged, snapshot.searchRoutes)
|
|
58
|
+
});
|
|
55
59
|
}, [from, store]);
|
|
56
60
|
return [selected, setSearch];
|
|
57
61
|
}
|