@teyik0/furin 0.2.0-alpha.5 → 0.4.0-alpha.1
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/README.md +2 -3
- package/dist/adapter/bun.d.ts +1 -1
- package/dist/adapter/static.d.ts +1 -1
- package/dist/build/bun-build.d.ts +3 -0
- package/dist/build/client.d.ts +2 -2
- package/dist/build/entry-template.d.ts +6 -0
- package/dist/build/entry-template.ts +20 -3
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +9363 -5827
- package/dist/build/production-instrumentation.d.ts +1 -0
- package/dist/build/route-types.d.ts +3 -23
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +2 -1
- package/dist/cli/index.js +9467 -5870
- package/dist/client/boundaries.d.ts +6 -4
- package/dist/client/define-route.d.ts +35 -0
- package/dist/client/document.d.ts +26 -0
- package/dist/client/hmr.d.ts +10 -0
- package/dist/client/internal/runtime-types.d.ts +32 -0
- package/dist/client/link.d.ts +2 -1
- package/dist/client/link.js +1884 -1227
- package/dist/client/router/boundary-tree.d.ts +1 -1
- package/dist/client/router/index.d.ts +2 -2
- package/dist/client/router/link-utils.d.ts +14 -1
- package/dist/client/router/search/index.d.ts +3 -7
- package/dist/client/router/sync-catch-up.d.ts +4 -4
- package/dist/client/router/types.d.ts +34 -26
- package/dist/client-only.d.ts +1 -0
- package/dist/client-only.js +1 -0
- package/dist/client.d.ts +11 -169
- package/dist/client.js +197 -36
- package/dist/config.d.ts +8 -8
- package/dist/config.js +10 -10
- package/dist/define-route.d.ts +1355 -0
- package/dist/devtools/devtools-element.d.ts +1 -0
- package/dist/devtools/protocol.d.ts +119 -0
- package/dist/furin.d.ts +24 -39
- package/dist/furin.js +14432 -7929
- package/dist/isomorphic.d.ts +18 -0
- package/dist/plugin/binding-scope.d.ts +2 -0
- package/dist/plugin/dead-code-elimination.d.ts +3 -0
- package/dist/plugin/index.js +1708 -489
- package/dist/plugin/route-config-autofix.d.ts +31 -0
- package/dist/plugin/routes.d.ts +27 -0
- package/dist/plugin/transform-client.d.ts +0 -2
- package/dist/plugin/transform-isomorphic.d.ts +9 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +1 -0
- package/dist/rsc/build/environment.d.ts +2 -0
- package/dist/rsc/build/index.d.ts +15 -0
- package/dist/rsc/client-codec.d.ts +1 -0
- package/dist/rsc/codec.d.ts +4 -0
- package/dist/rsc/flight-drain.d.ts +11 -0
- package/dist/rsc/render-error.d.ts +17 -0
- package/dist/rsc/server-codec.d.ts +2 -0
- package/dist/rsc/server-codec.js +24 -0
- package/dist/rsc/shared.d.ts +30 -0
- package/dist/rsc/symbols.d.ts +2 -0
- package/dist/rsc/transport-benchmark.d.ts +13 -0
- package/dist/rsc/version.d.ts +7 -0
- package/dist/rsc-client.d.ts +4 -0
- package/dist/rsc-client.js +166 -0
- package/dist/rsc-server.d.ts +11 -0
- package/dist/rsc.d.ts +11 -0
- package/dist/rsc.js +353 -0
- package/dist/server/cache/index.d.ts +2 -2
- package/dist/server/cache/invalidation.d.ts +2 -3
- package/dist/server/cache/isr-ssg.d.ts +5 -1
- package/dist/server/cache/isr.d.ts +9 -0
- package/dist/server/cache/route-cache.d.ts +10 -8
- package/dist/server/cache/store-view.d.ts +7 -7
- package/dist/server/dev-page-plugin.d.ts +11 -5
- package/dist/server/devtools/hub.d.ts +11 -0
- package/dist/server/devtools/instrumentation.d.ts +22 -0
- package/dist/server/devtools/instrumentation.production.d.ts +44 -0
- package/dist/server/devtools/plugin.d.ts +3 -0
- package/dist/server/devtools/request-context.d.ts +6 -0
- package/dist/server/internal.d.ts +5 -0
- package/dist/server/internal.js +3 -3
- package/dist/server/lang-detect.d.ts +1 -0
- package/dist/server/logger.d.ts +4 -0
- package/dist/server/render/assemble.d.ts +4 -9
- package/dist/server/render/document.d.ts +4 -0
- package/dist/server/render/element.d.ts +3 -2
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +6 -3
- package/dist/server/render/isr.d.ts +1 -1
- package/dist/server/render/loaders.d.ts +9 -1
- package/dist/server/render/not-found.d.ts +2 -2
- package/dist/server/render/ppr-route.d.ts +8 -0
- package/dist/server/render/route-frame-transport.d.ts +2 -0
- package/dist/server/render/shell.ts +0 -1
- package/dist/server/render/ssg.d.ts +1 -1
- package/dist/server/render/ssr.d.ts +9 -9
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +24 -0
- package/dist/server/router/discovery.d.ts +1 -1
- package/dist/server/router/hmr.d.ts +17 -9
- package/dist/server/router/patterns.d.ts +7 -1
- package/dist/server/router/plugin.d.ts +8 -10
- package/dist/server/router/schema-merge.d.ts +3 -0
- package/dist/server/router/schemas.d.ts +14 -9
- package/dist/server/router/source-version.d.ts +2 -0
- package/dist/server/router/types.d.ts +2 -1
- package/dist/server/runtime-env.js +2 -2
- package/dist/server/sync/adapter.d.ts +45 -26
- package/dist/server/sync/config.d.ts +5 -9
- package/dist/server/sync/fingerprint.d.ts +2 -1
- package/dist/server/sync/index.d.ts +15 -4
- package/dist/server/sync/index.js +3023 -0
- package/dist/server/sync/notifier.d.ts +18 -0
- package/dist/server/sync/plugin.d.ts +53 -54
- package/dist/server/sync/postgres/index.d.ts +19 -0
- package/dist/server/sync/postgres/index.js +252 -0
- package/dist/server/sync/postgres/migrate.d.ts +2 -0
- package/dist/server/sync/postgres/migrate.js +17 -0
- package/dist/server/sync/postgres/migration.sql +66 -0
- package/dist/server/sync/redis/index.d.ts +30 -0
- package/dist/server/sync/redis/index.js +336 -0
- package/dist/server/sync/redis/scripts.d.ts +4 -0
- package/dist/server/sync/response.d.ts +10 -1
- package/dist/server/sync/runtime.d.ts +6 -0
- package/dist/server/sync/sqlite/index.d.ts +20 -0
- package/dist/server/sync/sqlite/index.js +250 -0
- package/dist/server/sync/stream.d.ts +12 -11
- package/dist/server-only.d.ts +1 -0
- package/dist/server-only.js +1 -0
- package/dist/shared/await.d.ts +6 -7
- package/dist/shared/elysia-contract.d.ts +41 -0
- package/dist/shared/parser.d.ts +2 -0
- package/dist/shared/route-frame.d.ts +49 -0
- package/dist/shared/route-map.d.ts +5 -0
- package/dist/shared/utils/index.d.ts +1 -3
- package/package.json +86 -41
- package/src/adapter/bun.ts +113 -36
- package/src/adapter/package.ts +23 -15
- package/src/adapter/static.ts +97 -50
- package/src/build/bun-build.ts +11 -0
- package/src/build/client.ts +41 -26
- package/src/build/entry-template.ts +20 -3
- package/src/build/hydrate.ts +128 -33
- package/src/build/index.ts +14 -2
- package/src/build/production-instrumentation.ts +14 -0
- package/src/build/route-types.ts +20 -116
- package/src/build/scan-server.ts +3 -2
- package/src/build/shared.ts +1 -1
- package/src/build/ssg-cache.ts +4 -2
- package/src/build/types.ts +2 -1
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +58 -27
- package/src/client/boundaries.tsx +51 -19
- package/src/client/default-screens.tsx +4 -4
- package/src/client/define-route.ts +48 -0
- package/src/client/document.tsx +165 -0
- package/src/client/hmr.ts +40 -0
- package/src/client/internal/runtime-types.ts +33 -0
- package/src/client/link.tsx +51 -38
- package/src/client/router/boundary-tree.tsx +2 -2
- package/src/client/router/context.ts +13 -9
- package/src/client/router/index.ts +4 -0
- package/src/client/router/link-utils.ts +92 -3
- package/src/client/router/navigation.ts +9 -15
- package/src/client/router/provider.tsx +98 -53
- package/src/client/router/search/index.ts +9 -19
- package/src/client/router/search-store.ts +5 -1
- package/src/client/router/spa-response.ts +3 -4
- package/src/client/router/sync-catch-up.ts +9 -8
- package/src/client/router/types.ts +52 -26
- package/src/client/sync.ts +3 -2
- package/src/client-only.ts +1 -0
- package/src/client.ts +28 -283
- package/src/config.ts +10 -10
- package/src/define-route.ts +959 -0
- package/src/devtools/devtools-element.js +885 -0
- package/src/devtools/protocol.ts +139 -0
- package/src/furin.ts +475 -136
- package/src/isomorphic.ts +66 -0
- package/src/plugin/binding-scope.ts +158 -0
- package/src/plugin/dead-code-elimination.ts +202 -0
- package/src/plugin/index.ts +14 -18
- package/src/plugin/route-config-autofix.ts +1140 -0
- package/src/plugin/routes.ts +891 -0
- package/src/plugin/transform-client.ts +160 -330
- package/src/plugin/transform-isomorphic.ts +464 -0
- package/src/routes.ts +6 -0
- package/src/rsc/build/environment.ts +30 -0
- package/src/rsc/build/index.ts +94 -0
- package/src/rsc/client-codec.ts +11 -0
- package/src/rsc/codec.ts +85 -0
- package/src/rsc/flight-drain.ts +68 -0
- package/src/rsc/react-server-dom-webpack.d.ts +23 -0
- package/src/rsc/render-error.ts +120 -0
- package/src/rsc/server-codec.ts +25 -0
- package/src/rsc/shared.tsx +113 -0
- package/src/rsc/symbols.ts +2 -0
- package/src/rsc/transport-benchmark.ts +73 -0
- package/src/rsc/version.ts +57 -0
- package/src/rsc-client.ts +12 -0
- package/src/rsc-server.tsx +91 -0
- package/src/rsc.tsx +75 -0
- package/src/server/auto-invalidate/registry.ts +2 -2
- package/src/server/auto-invalidate/runtime.ts +32 -6
- package/src/server/cache/dev-loader.ts +70 -10
- package/src/server/cache/index.ts +7 -3
- package/src/server/cache/invalidation.ts +33 -15
- package/src/server/cache/isr-ssg.ts +12 -3
- package/src/server/cache/isr.ts +84 -9
- package/src/server/cache/route-cache.ts +49 -36
- package/src/server/cache/store-view.ts +7 -7
- package/src/server/context-logger.ts +7 -7
- package/src/server/dev-page-plugin.ts +38 -17
- package/src/server/devtools/hub.ts +64 -0
- package/src/server/devtools/instrumentation.production.ts +80 -0
- package/src/server/devtools/instrumentation.ts +72 -0
- package/src/server/devtools/plugin.ts +269 -0
- package/src/server/devtools/request-context.ts +76 -0
- package/src/server/instance.ts +4 -4
- package/src/server/internal.ts +5 -0
- package/src/server/lang-detect.ts +14 -10
- package/src/server/logger.ts +21 -0
- package/src/server/render/assemble.ts +58 -36
- package/src/server/render/document.tsx +25 -0
- package/src/server/render/element.tsx +24 -9
- package/src/server/render/index.ts +6 -3
- package/src/server/render/isr.ts +182 -117
- package/src/server/render/loaders.ts +289 -50
- package/src/server/render/not-found.ts +57 -38
- package/src/server/render/ppr-route.ts +146 -0
- package/src/server/render/route-frame-transport.ts +62 -0
- package/src/server/render/shell.ts +0 -1
- package/src/server/render/ssg.ts +7 -6
- package/src/server/render/ssr.ts +412 -166
- package/src/server/render/template.ts +93 -2
- package/src/server/router/defined-route.ts +110 -0
- package/src/server/router/discovery.ts +165 -48
- package/src/server/router/hmr.ts +126 -53
- package/src/server/router/patterns.ts +56 -27
- package/src/server/router/plugin.ts +210 -200
- package/src/server/router/schema-merge.ts +42 -0
- package/src/server/router/schemas.ts +61 -76
- package/src/server/router/source-version.ts +16 -0
- package/src/server/router/types.ts +3 -1
- package/src/server/sync/adapter.ts +44 -28
- package/src/server/sync/config.ts +9 -27
- package/src/server/sync/fingerprint.ts +8 -3
- package/src/server/sync/index.ts +37 -13
- package/src/server/sync/notifier.ts +109 -0
- package/src/server/sync/plugin.ts +184 -89
- package/src/server/sync/postgres/index.ts +301 -0
- package/src/server/sync/postgres/migrate.ts +16 -0
- package/src/server/sync/postgres/migration.sql +66 -0
- package/src/server/sync/redis/index.ts +342 -0
- package/src/server/sync/redis/scripts.ts +74 -0
- package/src/server/sync/response.ts +145 -16
- package/src/server/sync/runtime.ts +27 -0
- package/src/server/sync/sql.d.ts +4 -0
- package/src/server/sync/sqlite/index.ts +337 -0
- package/src/server/sync/sqlite/migration.sql +70 -0
- package/src/server/sync/stream.ts +137 -81
- package/src/server-only.ts +1 -0
- package/src/shared/await.tsx +10 -11
- package/src/shared/deferred-ndjson.ts +34 -6
- package/src/shared/digest.ts +2 -2
- package/src/shared/elysia-contract.ts +63 -0
- package/src/shared/parser.ts +5 -0
- package/src/shared/route-frame.ts +429 -0
- package/src/shared/route-map.ts +37 -0
- package/src/shared/search-params.ts +7 -7
- package/src/shared/utils/index.ts +6 -22
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -30
- package/dist/server/dev-inspector.d.ts +0 -89
- package/dist/server/router/index.d.ts +0 -6
- package/dist/server/router/index.js +0 -27
- package/dist/server/router/index.ts +0 -28
- package/dist/server/sync/memory-adapter.d.ts +0 -17
- package/src/build/server-routes-entry.ts +0 -30
- package/src/server/dev-inspector.ts +0 -60
- package/src/server/router/index.ts +0 -28
- package/src/server/sync/memory-adapter.ts +0 -196
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { log } from "evlog";
|
|
2
2
|
import type React from "react";
|
|
3
3
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import type { HeadOptions } from "../../client.ts";
|
|
4
5
|
import { parseDeferredNdjson } from "../../shared/deferred-ndjson.ts";
|
|
5
6
|
import type { SearchParamsInput } from "../../shared/search-params.ts";
|
|
7
|
+
import { DocumentProvider, useDocumentState } from "../document.tsx";
|
|
6
8
|
import { isAbortError } from "./abort.ts";
|
|
7
9
|
import { buildPageElement, buildRouterTree } from "./boundary-tree.tsx";
|
|
8
10
|
import {
|
|
@@ -15,6 +17,8 @@ import {
|
|
|
15
17
|
import {
|
|
16
18
|
applyRevalidateEntries,
|
|
17
19
|
applyRevalidateHeader,
|
|
20
|
+
decodeHashFragment,
|
|
21
|
+
isSameOriginFetchResult,
|
|
18
22
|
normalizeHref,
|
|
19
23
|
shouldAutoRefreshPath,
|
|
20
24
|
shouldInterceptClick,
|
|
@@ -22,7 +26,7 @@ import {
|
|
|
22
26
|
stripHashFromHref,
|
|
23
27
|
toLogical,
|
|
24
28
|
} from "./link-utils.ts";
|
|
25
|
-
import { createSearchStore,
|
|
29
|
+
import { createSearchStore, SearchStoreContext } from "./search-store.ts";
|
|
26
30
|
import {
|
|
27
31
|
buildDataEndpoint,
|
|
28
32
|
buildNotFoundPageElement,
|
|
@@ -45,6 +49,11 @@ import type {
|
|
|
45
49
|
|
|
46
50
|
const EMPTY_SEARCH: SearchParamsInput = {};
|
|
47
51
|
|
|
52
|
+
function getHistoryStateObject(): object {
|
|
53
|
+
const value = history.state;
|
|
54
|
+
return value !== null && typeof value === "object" ? value : {};
|
|
55
|
+
}
|
|
56
|
+
|
|
48
57
|
export function setPrefetchCacheEntry(
|
|
49
58
|
cache: Map<string, CacheEntry>,
|
|
50
59
|
href: string,
|
|
@@ -78,11 +87,13 @@ export function RouterProvider({
|
|
|
78
87
|
prefetchCacheSize,
|
|
79
88
|
syncStream,
|
|
80
89
|
}: RouterProviderProps): React.ReactElement {
|
|
90
|
+
const initialDocumentState = useDocumentState();
|
|
81
91
|
// Initial state. When `initialMatch` is `null`, `initialNotFound` MUST be set —
|
|
82
92
|
// the provider boots into the inline not-found UI.
|
|
83
93
|
const [state, setState] = useState<RouterState>(() => ({
|
|
84
|
-
match: initialMatch,
|
|
85
94
|
data: initialData,
|
|
95
|
+
head: initialDocumentState?.head,
|
|
96
|
+
match: initialMatch,
|
|
86
97
|
notFound: initialNotFound,
|
|
87
98
|
}));
|
|
88
99
|
const [isNavigating, setIsNavigating] = useState(false);
|
|
@@ -124,9 +135,8 @@ export function RouterProvider({
|
|
|
124
135
|
* fetch URL: runtime `/_furin/data` for SSR/ISR/dev, per-route
|
|
125
136
|
* `__furin_data.ndjson` for static exports.
|
|
126
137
|
*/
|
|
127
|
-
const
|
|
138
|
+
const [staticMode] = useState(detectStaticMode);
|
|
128
139
|
const resolvedSearch = (state.data.query as SearchParamsInput | undefined) ?? EMPTY_SEARCH;
|
|
129
|
-
const searchStoreRef = useRef<SearchStore | null>(null);
|
|
130
140
|
|
|
131
141
|
/**
|
|
132
142
|
* Depth-0 boundary (pagesDir root level) for the "no client route matched" 404
|
|
@@ -141,7 +151,6 @@ export function RouterProvider({
|
|
|
141
151
|
return [depth0];
|
|
142
152
|
}
|
|
143
153
|
}
|
|
144
|
-
return;
|
|
145
154
|
}, [routes]);
|
|
146
155
|
|
|
147
156
|
/**
|
|
@@ -164,12 +173,12 @@ export function RouterProvider({
|
|
|
164
173
|
}
|
|
165
174
|
const { __furinStatus: _s, __furinNotFound: _n, ...cleanData } = data ?? {};
|
|
166
175
|
return {
|
|
167
|
-
match: currentMatchRef.current,
|
|
168
176
|
data: cleanData,
|
|
169
|
-
title,
|
|
170
177
|
finalHref,
|
|
178
|
+
match: currentMatchRef.current,
|
|
171
179
|
notFound: kind.error,
|
|
172
180
|
notFoundBoundaries: rootBoundaries,
|
|
181
|
+
title,
|
|
173
182
|
};
|
|
174
183
|
},
|
|
175
184
|
[basePath, rootBoundaries]
|
|
@@ -198,7 +207,7 @@ export function RouterProvider({
|
|
|
198
207
|
}
|
|
199
208
|
|
|
200
209
|
// ── NDJSON data endpoint + JS chunk load (parallel) ──────────────────
|
|
201
|
-
const dataEndpoint = buildDataEndpoint(basePath, logicalHref,
|
|
210
|
+
const dataEndpoint = buildDataEndpoint(basePath, logicalHref, staticMode);
|
|
202
211
|
const [res, loadedMod] = await Promise.all([fetch(dataEndpoint, { signal }), match.load()]);
|
|
203
212
|
|
|
204
213
|
// Stale-deploy detection: force a full page reload to pick up the new bundle.
|
|
@@ -217,9 +226,9 @@ export function RouterProvider({
|
|
|
217
226
|
} catch (parseErr) {
|
|
218
227
|
log.warn({
|
|
219
228
|
action: "navigate_server_error",
|
|
229
|
+
error: String(parseErr),
|
|
220
230
|
href: physicalHref,
|
|
221
231
|
status: res.status,
|
|
222
|
-
error: String(parseErr),
|
|
223
232
|
});
|
|
224
233
|
return null;
|
|
225
234
|
}
|
|
@@ -232,6 +241,7 @@ export function RouterProvider({
|
|
|
232
241
|
// __furinError — error sentinel (digest, message, status)
|
|
233
242
|
// __furinTitle — document title resolved server-side from head()
|
|
234
243
|
const {
|
|
244
|
+
__furinHead,
|
|
235
245
|
__furinStatus,
|
|
236
246
|
__furinNotFound,
|
|
237
247
|
__furinRedirect,
|
|
@@ -243,6 +253,7 @@ export function RouterProvider({
|
|
|
243
253
|
__furinNotFound?: { data?: unknown; message?: string };
|
|
244
254
|
__furinRedirect?: string;
|
|
245
255
|
__furinError?: { digest: string; message: string; status: number };
|
|
256
|
+
__furinHead?: HeadOptions;
|
|
246
257
|
__furinTitle?: string;
|
|
247
258
|
[key: string]: unknown;
|
|
248
259
|
};
|
|
@@ -265,11 +276,12 @@ export function RouterProvider({
|
|
|
265
276
|
// Loader threw a non-redirect Response (or an Error).
|
|
266
277
|
if (__furinError) {
|
|
267
278
|
return {
|
|
268
|
-
match: loadedMatch,
|
|
269
279
|
data: {},
|
|
270
|
-
title,
|
|
271
|
-
finalHref,
|
|
272
280
|
error: __furinError,
|
|
281
|
+
finalHref,
|
|
282
|
+
head: __furinHead,
|
|
283
|
+
match: loadedMatch,
|
|
284
|
+
title,
|
|
273
285
|
};
|
|
274
286
|
}
|
|
275
287
|
|
|
@@ -280,27 +292,32 @@ export function RouterProvider({
|
|
|
280
292
|
}
|
|
281
293
|
|
|
282
294
|
if (__furinStatus === 404) {
|
|
295
|
+
const notFound =
|
|
296
|
+
__furinNotFound !== null && typeof __furinNotFound === "object"
|
|
297
|
+
? (__furinNotFound as { data?: unknown; message?: string })
|
|
298
|
+
: {};
|
|
283
299
|
return {
|
|
284
|
-
match: loadedMatch,
|
|
285
300
|
data,
|
|
286
|
-
title,
|
|
287
301
|
finalHref,
|
|
288
|
-
|
|
302
|
+
head: __furinHead,
|
|
303
|
+
match: loadedMatch,
|
|
304
|
+
notFound,
|
|
305
|
+
title,
|
|
289
306
|
};
|
|
290
307
|
}
|
|
291
308
|
|
|
292
309
|
// Server-side redirect: do not mount the pre-redirect route.
|
|
293
310
|
if (finalHref) {
|
|
294
|
-
return { match: null,
|
|
311
|
+
return { data, finalHref, match: null, title };
|
|
295
312
|
}
|
|
296
313
|
|
|
297
|
-
return { match: loadedMatch,
|
|
314
|
+
return { data, finalHref, head: __furinHead, match: loadedMatch, title };
|
|
298
315
|
} catch (err: unknown) {
|
|
299
316
|
if (!isAbortError(err)) {
|
|
300
317
|
log.error({
|
|
301
318
|
action: "navigate_failed",
|
|
302
|
-
href: basePath + logicalHref,
|
|
303
319
|
error: String(err),
|
|
320
|
+
href: basePath + logicalHref,
|
|
304
321
|
});
|
|
305
322
|
}
|
|
306
323
|
return null;
|
|
@@ -345,8 +362,8 @@ export function RouterProvider({
|
|
|
345
362
|
prefetchCache.current,
|
|
346
363
|
href,
|
|
347
364
|
{
|
|
348
|
-
promise: fetchPageState(href, undefined),
|
|
349
365
|
createdAt: Date.now(),
|
|
366
|
+
promise: fetchPageState(href, undefined),
|
|
350
367
|
staleTime,
|
|
351
368
|
},
|
|
352
369
|
prefetchCacheSize
|
|
@@ -362,14 +379,14 @@ export function RouterProvider({
|
|
|
362
379
|
signal: AbortSignal | undefined
|
|
363
380
|
): Promise<RouterState | null> {
|
|
364
381
|
const cached = prefetchCache.current.get(redirectLogical);
|
|
365
|
-
const
|
|
382
|
+
const redirectState =
|
|
366
383
|
cached && !shouldRefetch(cached)
|
|
367
384
|
? await cached.promise
|
|
368
385
|
: await fetchPageState(redirectLogical, signal);
|
|
369
386
|
if (navVersion.current !== myVersion) {
|
|
370
387
|
return null;
|
|
371
388
|
}
|
|
372
|
-
return
|
|
389
|
+
return redirectState;
|
|
373
390
|
}
|
|
374
391
|
|
|
375
392
|
const navigate = useCallback(
|
|
@@ -379,7 +396,8 @@ export function RouterProvider({
|
|
|
379
396
|
opts: { replace?: boolean; resetScroll?: boolean } | undefined
|
|
380
397
|
) {
|
|
381
398
|
const logicalHref = normalizeHref(rawLogicalHref);
|
|
382
|
-
|
|
399
|
+
navVersion.current += 1;
|
|
400
|
+
const myVersion = navVersion.current;
|
|
383
401
|
navAbortRef.current?.abort();
|
|
384
402
|
const navAbort = new AbortController();
|
|
385
403
|
navAbortRef.current = navAbort;
|
|
@@ -399,8 +417,8 @@ export function RouterProvider({
|
|
|
399
417
|
prefetchCache.current,
|
|
400
418
|
logicalHref,
|
|
401
419
|
{
|
|
402
|
-
promise: Promise.resolve(newState),
|
|
403
420
|
createdAt: Date.now(),
|
|
421
|
+
promise: Promise.resolve(newState),
|
|
404
422
|
staleTime: defaultPreloadStaleTime,
|
|
405
423
|
},
|
|
406
424
|
prefetchCacheSize
|
|
@@ -423,7 +441,7 @@ export function RouterProvider({
|
|
|
423
441
|
const redirectPhysical = basePath + redirectLogical;
|
|
424
442
|
window.history.replaceState(
|
|
425
443
|
{
|
|
426
|
-
...(
|
|
444
|
+
...getHistoryStateObject(),
|
|
427
445
|
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey(),
|
|
428
446
|
},
|
|
429
447
|
"",
|
|
@@ -450,7 +468,7 @@ export function RouterProvider({
|
|
|
450
468
|
if (opts?.replace) {
|
|
451
469
|
window.history.replaceState(
|
|
452
470
|
{
|
|
453
|
-
...(
|
|
471
|
+
...getHistoryStateObject(),
|
|
454
472
|
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey(),
|
|
455
473
|
},
|
|
456
474
|
"",
|
|
@@ -467,7 +485,7 @@ export function RouterProvider({
|
|
|
467
485
|
const logicalPath = normalizeHref(toLogical(effectiveUrl.pathname, basePath));
|
|
468
486
|
setCurrentHref(logicalPath + effectiveUrl.search);
|
|
469
487
|
if (opts?.resetScroll ?? true) {
|
|
470
|
-
pendingScrollRef.current = { type: "reset"
|
|
488
|
+
pendingScrollRef.current = { href: physicalEffective, type: "reset" };
|
|
471
489
|
}
|
|
472
490
|
} finally {
|
|
473
491
|
if (navVersion.current === myVersion) {
|
|
@@ -478,15 +496,14 @@ export function RouterProvider({
|
|
|
478
496
|
[basePath, fetchPageState, defaultPreloadStaleTime, prefetchCacheSize]
|
|
479
497
|
);
|
|
480
498
|
|
|
481
|
-
|
|
482
|
-
|
|
499
|
+
const [searchStore] = useState(() =>
|
|
500
|
+
createSearchStore({
|
|
483
501
|
currentHref,
|
|
484
502
|
navigate,
|
|
485
503
|
search: resolvedSearch,
|
|
486
504
|
searchRoutes: routes,
|
|
487
|
-
})
|
|
488
|
-
|
|
489
|
-
const searchStore = searchStoreRef.current;
|
|
505
|
+
})
|
|
506
|
+
);
|
|
490
507
|
const searchSnapshot = useMemo(
|
|
491
508
|
() => ({
|
|
492
509
|
currentHref,
|
|
@@ -540,7 +557,8 @@ export function RouterProvider({
|
|
|
540
557
|
const destKey = getHistoryKey(history.state);
|
|
541
558
|
const logicalPath = normalizeHref(toLogical(window.location.pathname, basePath));
|
|
542
559
|
const logicalHref = logicalPath + window.location.search;
|
|
543
|
-
|
|
560
|
+
navVersion.current += 1;
|
|
561
|
+
const myVersion = navVersion.current;
|
|
544
562
|
navAbortRef.current?.abort();
|
|
545
563
|
const navAbort = new AbortController();
|
|
546
564
|
navAbortRef.current = navAbort;
|
|
@@ -597,9 +615,9 @@ export function RouterProvider({
|
|
|
597
615
|
}
|
|
598
616
|
setCurrentHref(normalizeHref(effectiveLogical));
|
|
599
617
|
if (destKey) {
|
|
600
|
-
pendingScrollRef.current = { type: "restore"
|
|
618
|
+
pendingScrollRef.current = { key: destKey, type: "restore" };
|
|
601
619
|
} else {
|
|
602
|
-
window.scrollTo({
|
|
620
|
+
window.scrollTo({ behavior: "instant", top: 0 });
|
|
603
621
|
}
|
|
604
622
|
} finally {
|
|
605
623
|
if (navVersion.current === myVersion) {
|
|
@@ -613,16 +631,14 @@ export function RouterProvider({
|
|
|
613
631
|
useEffect(() => {
|
|
614
632
|
history.scrollRestoration = "manual";
|
|
615
633
|
if (!getHistoryKey(history.state)) {
|
|
616
|
-
history.replaceState(
|
|
617
|
-
{ ...((history.state as object) ?? {}), _furinKey: generateHistoryKey() },
|
|
618
|
-
""
|
|
619
|
-
);
|
|
634
|
+
history.replaceState({ ...getHistoryStateObject(), _furinKey: generateHistoryKey() }, "");
|
|
620
635
|
}
|
|
621
636
|
}, []);
|
|
622
637
|
|
|
623
638
|
// Render-synchronous scroll restoration.
|
|
624
639
|
useLayoutEffect(() => {
|
|
625
640
|
const instruction = pendingScrollRef.current;
|
|
641
|
+
// biome-ignore lint/suspicious/noUnnecessaryConditions: the ref is null until navigation schedules scrolling
|
|
626
642
|
if (!instruction) {
|
|
627
643
|
return;
|
|
628
644
|
}
|
|
@@ -633,22 +649,22 @@ export function RouterProvider({
|
|
|
633
649
|
const raw = sessionStorage.getItem(SCROLL_STORAGE_KEY);
|
|
634
650
|
const positions: Record<string, number> = raw ? JSON.parse(raw) : {};
|
|
635
651
|
const y = positions[instruction.key] ?? 0;
|
|
636
|
-
window.scrollTo({
|
|
652
|
+
window.scrollTo({ behavior: "instant", top: y });
|
|
637
653
|
} catch {
|
|
638
|
-
window.scrollTo({
|
|
654
|
+
window.scrollTo({ behavior: "instant", top: 0 });
|
|
639
655
|
}
|
|
640
656
|
return;
|
|
641
657
|
}
|
|
642
658
|
|
|
643
659
|
const destUrl = new URL(instruction.href, window.location.origin);
|
|
644
660
|
if (destUrl.hash) {
|
|
645
|
-
const id =
|
|
661
|
+
const id = decodeHashFragment(destUrl.hash.slice(1));
|
|
646
662
|
const element = document.getElementById(id);
|
|
647
663
|
if (element) {
|
|
648
664
|
element.scrollIntoView({ behavior: "instant", block: "start" });
|
|
649
665
|
}
|
|
650
666
|
} else {
|
|
651
|
-
window.scrollTo({
|
|
667
|
+
window.scrollTo({ behavior: "instant", top: 0 });
|
|
652
668
|
}
|
|
653
669
|
}, [currentHref]);
|
|
654
670
|
|
|
@@ -688,12 +704,22 @@ export function RouterProvider({
|
|
|
688
704
|
if (logicalHref === null) {
|
|
689
705
|
return;
|
|
690
706
|
}
|
|
707
|
+
// Don't capture a link that matches no local route: it may belong to a
|
|
708
|
+
// sibling furin app mounted under a different basePath. Let the browser
|
|
709
|
+
// navigate; the server routes it to the correct app.
|
|
710
|
+
const logicalPathname = new URL(logicalHref, window.location.origin).pathname;
|
|
711
|
+
const hasConcreteMatch = routes.some(
|
|
712
|
+
(route) => !route.pattern.split("/").includes("*") && route.regex.test(logicalPathname)
|
|
713
|
+
);
|
|
714
|
+
if (!hasConcreteMatch) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
691
717
|
e.preventDefault();
|
|
692
718
|
navigate(logicalHref, { resetScroll: !logicalHref.includes("#") });
|
|
693
719
|
};
|
|
694
720
|
document.addEventListener("click", handler);
|
|
695
721
|
return () => document.removeEventListener("click", handler);
|
|
696
|
-
}, [navigate, basePath]);
|
|
722
|
+
}, [navigate, basePath, routes]);
|
|
697
723
|
|
|
698
724
|
// Intercept all window.fetch calls to auto-process X-Furin-Revalidate headers.
|
|
699
725
|
useEffect(() => {
|
|
@@ -703,6 +729,9 @@ export function RouterProvider({
|
|
|
703
729
|
const originalFetch = window.fetch;
|
|
704
730
|
const wrapped = async (...args: Parameters<typeof fetch>): Promise<Response> => {
|
|
705
731
|
const response = await originalFetch.apply(window, args);
|
|
732
|
+
if (!isSameOriginFetchResult(args[0], response.url, window.location.origin)) {
|
|
733
|
+
return response;
|
|
734
|
+
}
|
|
706
735
|
const invalidated: Array<{ path: string; type: "page" | "layout" }> = [];
|
|
707
736
|
applyRevalidateHeader(response.headers, (path, type) => {
|
|
708
737
|
const resolvedType = type ?? "page";
|
|
@@ -729,6 +758,7 @@ export function RouterProvider({
|
|
|
729
758
|
}, [invalidatePrefetch, invalidationRefresh, autoRefresh, basePath]);
|
|
730
759
|
|
|
731
760
|
// Listen for sync cursor notifications and recover changes over HTTP.
|
|
761
|
+
// react-doctor-disable-next-line react-doctor/effect-needs-cleanup
|
|
732
762
|
useEffect(() => {
|
|
733
763
|
if (!syncStream || typeof window === "undefined" || typeof EventSource === "undefined") {
|
|
734
764
|
return;
|
|
@@ -782,6 +812,7 @@ export function RouterProvider({
|
|
|
782
812
|
}
|
|
783
813
|
});
|
|
784
814
|
};
|
|
815
|
+
const onOpen = () => recover();
|
|
785
816
|
const onSync = (event: MessageEvent) => {
|
|
786
817
|
try {
|
|
787
818
|
const payload = JSON.parse(event.data) as { cursor?: unknown };
|
|
@@ -799,6 +830,7 @@ export function RouterProvider({
|
|
|
799
830
|
return;
|
|
800
831
|
}
|
|
801
832
|
source = new EventSource(streamUrl);
|
|
833
|
+
source.addEventListener("open", onOpen);
|
|
802
834
|
source.addEventListener("furin.sync", onSync);
|
|
803
835
|
};
|
|
804
836
|
|
|
@@ -809,8 +841,6 @@ export function RouterProvider({
|
|
|
809
841
|
return;
|
|
810
842
|
}
|
|
811
843
|
connect();
|
|
812
|
-
// Close the initialization/SSE race using the durable change log.
|
|
813
|
-
recover();
|
|
814
844
|
})
|
|
815
845
|
.catch((error: unknown) => {
|
|
816
846
|
if (disposed) {
|
|
@@ -822,6 +852,7 @@ export function RouterProvider({
|
|
|
822
852
|
});
|
|
823
853
|
return () => {
|
|
824
854
|
disposed = true;
|
|
855
|
+
source?.removeEventListener("open", onOpen);
|
|
825
856
|
source?.removeEventListener("furin.sync", onSync);
|
|
826
857
|
source?.close();
|
|
827
858
|
};
|
|
@@ -850,26 +881,27 @@ export function RouterProvider({
|
|
|
850
881
|
);
|
|
851
882
|
}
|
|
852
883
|
|
|
853
|
-
|
|
884
|
+
const routerTree = (
|
|
854
885
|
<SearchStoreContext.Provider value={searchStore}>
|
|
855
886
|
{buildRouterTree(
|
|
856
887
|
{
|
|
857
888
|
basePath,
|
|
858
889
|
currentHref,
|
|
859
|
-
search: resolvedSearch,
|
|
860
|
-
searchRoutes: routes,
|
|
861
|
-
navigate,
|
|
862
|
-
prefetch,
|
|
863
|
-
refresh,
|
|
864
|
-
invalidatePrefetch,
|
|
865
|
-
isNavigating,
|
|
866
890
|
defaultPreload,
|
|
867
891
|
defaultPreloadDelay,
|
|
868
892
|
defaultPreloadStaleTime,
|
|
893
|
+
invalidatePrefetch,
|
|
894
|
+
isNavigating,
|
|
895
|
+
navigate,
|
|
896
|
+
prefetch,
|
|
897
|
+
refresh,
|
|
898
|
+
search: resolvedSearch,
|
|
899
|
+
searchRoutes: routes,
|
|
869
900
|
},
|
|
870
901
|
pageElement,
|
|
871
902
|
{
|
|
872
903
|
digest: initialDigest,
|
|
904
|
+
document: initialDocumentState !== null,
|
|
873
905
|
onReset: () => {
|
|
874
906
|
refresh(undefined).catch((err: unknown) => {
|
|
875
907
|
log.error({ action: "boundary_reset_failed", error: String(err) });
|
|
@@ -880,4 +912,17 @@ export function RouterProvider({
|
|
|
880
912
|
)}
|
|
881
913
|
</SearchStoreContext.Provider>
|
|
882
914
|
);
|
|
915
|
+
if (initialDocumentState === null) {
|
|
916
|
+
return routerTree;
|
|
917
|
+
}
|
|
918
|
+
return (
|
|
919
|
+
<DocumentProvider
|
|
920
|
+
value={{
|
|
921
|
+
...initialDocumentState,
|
|
922
|
+
head: state.head,
|
|
923
|
+
}}
|
|
924
|
+
>
|
|
925
|
+
{routerTree}
|
|
926
|
+
</DocumentProvider>
|
|
927
|
+
);
|
|
883
928
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RouteManifest
|
|
2
|
-
import { useCallback, useContext,
|
|
1
|
+
import type { RouteManifest, RouteSearch, RouteTo } from "@teyik0/furin/link";
|
|
2
|
+
import { useCallback, useContext, useSyncExternalStore } from "react";
|
|
3
3
|
import {
|
|
4
4
|
findSearchDefaultsForRouteTarget,
|
|
5
5
|
type SearchParamsInput,
|
|
@@ -7,19 +7,11 @@ import {
|
|
|
7
7
|
import { buildHref } from "../link-utils.ts";
|
|
8
8
|
import { FALLBACK_SEARCH_STORE, SearchStoreContext } from "../search-store.ts";
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
export type SearchRouteTo = keyof LinkRouteManifest extends never
|
|
10
|
+
export type SearchRouteTo = keyof RouteManifest extends never
|
|
13
11
|
? RouteTo
|
|
14
|
-
: (string & {}) | keyof
|
|
12
|
+
: (string & {}) | keyof RouteManifest;
|
|
15
13
|
|
|
16
|
-
type SearchRouteSearch<To extends SearchRouteTo> =
|
|
17
|
-
? RouteSearch<To & RouteTo>
|
|
18
|
-
: To extends keyof LinkRouteManifest
|
|
19
|
-
? LinkRouteManifest[To] extends { search?: infer S }
|
|
20
|
-
? S
|
|
21
|
-
: undefined
|
|
22
|
-
: undefined;
|
|
14
|
+
type SearchRouteSearch<To extends SearchRouteTo> = RouteSearch<To & RouteTo>;
|
|
23
15
|
|
|
24
16
|
export type EmptyRouteSearch = Record<PropertyKey, never>;
|
|
25
17
|
|
|
@@ -50,16 +42,14 @@ function useSearchSelection<To extends SearchRouteTo, TSelected>(
|
|
|
50
42
|
selector: (search: ResolvedRouteSearch<To>) => TSelected
|
|
51
43
|
): TSelected {
|
|
52
44
|
const store = useContext(SearchStoreContext) ?? FALLBACK_SEARCH_STORE;
|
|
53
|
-
const selectorRef = useRef(selector);
|
|
54
|
-
selectorRef.current = selector;
|
|
55
45
|
|
|
56
46
|
const getSnapshot = useCallback(
|
|
57
|
-
() =>
|
|
58
|
-
[store]
|
|
47
|
+
() => selector(store.getSnapshot().search as ResolvedRouteSearch<To>),
|
|
48
|
+
[selector, store]
|
|
59
49
|
);
|
|
60
50
|
const getServerSnapshot = useCallback(
|
|
61
|
-
() =>
|
|
62
|
-
[store]
|
|
51
|
+
() => selector(store.getServerSnapshot().search as ResolvedRouteSearch<To>),
|
|
52
|
+
[selector, store]
|
|
63
53
|
);
|
|
64
54
|
|
|
65
55
|
return useSyncExternalStore(store.subscribe, getSnapshot, getServerSnapshot);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext } from "react";
|
|
2
2
|
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
3
|
+
import { navigationHrefPolicy } from "./link-utils.ts";
|
|
3
4
|
import type { RouterContextValue } from "./types.ts";
|
|
4
5
|
|
|
5
6
|
export interface SearchStoreSnapshot {
|
|
@@ -51,7 +52,7 @@ export function createSearchStore(initialSnapshot: SearchStoreSnapshot): SearchS
|
|
|
51
52
|
return;
|
|
52
53
|
}
|
|
53
54
|
snapshot = next;
|
|
54
|
-
version
|
|
55
|
+
version += 1;
|
|
55
56
|
},
|
|
56
57
|
subscribe: (listener) => {
|
|
57
58
|
listeners.add(listener);
|
|
@@ -75,6 +76,9 @@ export const FALLBACK_SEARCH_STORE = createSearchStore({
|
|
|
75
76
|
currentHref: "/",
|
|
76
77
|
navigate: (href, _opts) => {
|
|
77
78
|
if (typeof window !== "undefined") {
|
|
79
|
+
if (navigationHrefPolicy(href, window.location.origin) === "blocked") {
|
|
80
|
+
return Promise.reject(new Error("[furin] Unsafe navigation URL."));
|
|
81
|
+
}
|
|
78
82
|
window.location.href = href;
|
|
79
83
|
}
|
|
80
84
|
return Promise.resolve();
|
|
@@ -36,11 +36,11 @@ export function classifySpaResponse(
|
|
|
36
36
|
return { kind: "bail" };
|
|
37
37
|
}
|
|
38
38
|
if (isFurinErrorPayload(data.__furinError)) {
|
|
39
|
-
return { kind: "error"
|
|
39
|
+
return { error: data.__furinError, kind: "error" };
|
|
40
40
|
}
|
|
41
41
|
if (((status >= 200 && status < 300) || status === 404) && data.__furinStatus === 404) {
|
|
42
42
|
const notFound = data.__furinNotFound as { data?: unknown; message?: string } | undefined;
|
|
43
|
-
return {
|
|
43
|
+
return { error: notFound ?? {}, kind: "not-found" };
|
|
44
44
|
}
|
|
45
45
|
if (status >= 200 && status < 300) {
|
|
46
46
|
return { kind: "ok" };
|
|
@@ -59,13 +59,12 @@ export function pickDeepestNotFound(
|
|
|
59
59
|
if (!boundaries) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
for (let i = boundaries.length - 1; i >= 0; i
|
|
62
|
+
for (let i = boundaries.length - 1; i >= 0; i -= 1) {
|
|
63
63
|
const seg = boundaries[i];
|
|
64
64
|
if (seg?.notFound) {
|
|
65
65
|
return seg.notFound;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
return;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
const DefaultClientNotFoundFallback: NotFoundComponent = ({ error }) =>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// biome-ignore-all lint/performance/noAwaitInLoops: sync catch-up pages must be fetched sequentially by cursor
|
|
1
2
|
export interface SyncChangePayload {
|
|
2
3
|
cursor: string;
|
|
3
4
|
invalidations: readonly string[];
|
|
@@ -16,9 +17,9 @@ interface SyncCatchUpOptions {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export interface SyncCatchUp {
|
|
19
|
-
catchUp()
|
|
20
|
-
cursor()
|
|
21
|
-
initialize()
|
|
20
|
+
catchUp: () => Promise<void>;
|
|
21
|
+
cursor: () => string | undefined;
|
|
22
|
+
initialize: () => Promise<void>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
interface InvalidationRefreshOptions {
|
|
@@ -27,7 +28,7 @@ interface InvalidationRefreshOptions {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export interface InvalidationRefresh {
|
|
30
|
-
run()
|
|
31
|
+
run: () => Promise<void>;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export function createInvalidationRefresh(
|
|
@@ -93,10 +94,6 @@ export function createSyncCatchUp(options: SyncCatchUpOptions): SyncCatchUp {
|
|
|
93
94
|
};
|
|
94
95
|
|
|
95
96
|
return {
|
|
96
|
-
async initialize() {
|
|
97
|
-
const page = await options.fetchPage(undefined);
|
|
98
|
-
currentCursor = page.cursor;
|
|
99
|
-
},
|
|
100
97
|
catchUp() {
|
|
101
98
|
requested = true;
|
|
102
99
|
if (!running) {
|
|
@@ -107,6 +104,10 @@ export function createSyncCatchUp(options: SyncCatchUpOptions): SyncCatchUp {
|
|
|
107
104
|
return running;
|
|
108
105
|
},
|
|
109
106
|
cursor: () => currentCursor,
|
|
107
|
+
async initialize() {
|
|
108
|
+
const page = await options.fetchPage(undefined);
|
|
109
|
+
currentCursor = page.cursor;
|
|
110
|
+
},
|
|
110
111
|
};
|
|
111
112
|
}
|
|
112
113
|
|