@teyik0/furin 0.2.0-alpha.5 → 0.3.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/static.d.ts +1 -1
- package/dist/build/bun-build.d.ts +3 -0
- package/dist/build/entry-template.d.ts +2 -0
- package/dist/build/entry-template.ts +3 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +6944 -5067
- package/dist/build/production-instrumentation.d.ts +1 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/types.d.ts +1 -0
- package/dist/cli/index.js +7874 -5971
- package/dist/client/boundaries.d.ts +4 -4
- package/dist/client/internal/runtime-types.d.ts +30 -0
- package/dist/client/link.d.ts +2 -1
- package/dist/client/link.js +712 -338
- package/dist/client/router/boundary-tree.d.ts +1 -1
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +5 -1
- package/dist/client/router/sync-catch-up.d.ts +4 -4
- package/dist/client/router/types.d.ts +2 -2
- package/dist/client-only.d.ts +1 -0
- package/dist/client-only.js +1 -0
- package/dist/client.d.ts +108 -111
- package/dist/client.js +16 -17
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -2
- package/dist/devtools/devtools-element.d.ts +1 -0
- package/dist/devtools/protocol.d.ts +119 -0
- package/dist/furin.d.ts +7 -6
- package/dist/furin.js +6547 -3187
- 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 +933 -423
- package/dist/plugin/transform-client.d.ts +0 -2
- package/dist/plugin/transform-isomorphic.d.ts +9 -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 +4 -0
- 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 +2 -0
- package/dist/server/internal.js +3 -3
- package/dist/server/lang-detect.d.ts +1 -0
- package/dist/server/render/assemble.d.ts +4 -0
- package/dist/server/render/element.d.ts +1 -1
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +6 -2
- package/dist/server/render/loaders.d.ts +8 -0
- package/dist/server/render/not-found.d.ts +1 -1
- 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/ssr.d.ts +2 -3
- package/dist/server/router/discovery.d.ts +1 -1
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/router/index.d.ts +2 -1
- package/dist/server/router/index.js +23 -23
- package/dist/server/router/index.ts +1 -1
- package/dist/server/router/patterns.d.ts +1 -1
- package/dist/server/router/plugin.d.ts +4 -7
- package/dist/server/router/schema-merge.d.ts +3 -0
- package/dist/server/router/schemas.d.ts +12 -7
- package/dist/server/router/types.d.ts +1 -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 +2868 -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 +16 -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/parser.d.ts +2 -0
- package/dist/shared/route-frame.d.ts +49 -0
- package/dist/shared/utils/index.d.ts +1 -1
- package/package.json +54 -12
- package/src/adapter/bun.ts +73 -16
- package/src/adapter/package.ts +3 -1
- package/src/adapter/static.ts +94 -48
- package/src/build/bun-build.ts +11 -0
- package/src/build/client.ts +22 -24
- package/src/build/entry-template.ts +3 -0
- package/src/build/hydrate.ts +33 -8
- package/src/build/index.ts +12 -0
- package/src/build/production-instrumentation.ts +14 -0
- package/src/build/route-types.ts +7 -8
- package/src/build/scan-server.ts +3 -2
- package/src/build/ssg-cache.ts +7 -2
- package/src/build/types.ts +1 -0
- package/src/cli/index.ts +53 -22
- package/src/client/boundaries.tsx +42 -18
- package/src/client/default-screens.tsx +4 -4
- package/src/client/internal/runtime-types.ts +31 -0
- package/src/client/link.tsx +35 -37
- package/src/client/router/boundary-tree.tsx +2 -2
- package/src/client/router/context.ts +13 -9
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +66 -3
- package/src/client/router/navigation.ts +9 -15
- package/src/client/router/provider.tsx +74 -52
- package/src/client/router/search/index.ts +5 -7
- 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 +2 -2
- package/src/client/sync.ts +3 -2
- package/src/client-only.ts +1 -0
- package/src/client.ts +221 -174
- package/src/devtools/devtools-element.js +884 -0
- package/src/devtools/protocol.ts +139 -0
- package/src/furin.ts +185 -96
- 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/transform-client.ts +237 -273
- package/src/plugin/transform-isomorphic.ts +464 -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/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 +8 -6
- 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 +267 -0
- package/src/server/devtools/request-context.ts +76 -0
- package/src/server/instance.ts +1 -1
- package/src/server/internal.ts +2 -0
- package/src/server/lang-detect.ts +14 -10
- package/src/server/render/assemble.ts +73 -10
- package/src/server/render/element.tsx +11 -8
- package/src/server/render/index.ts +6 -2
- package/src/server/render/isr.ts +154 -110
- package/src/server/render/loaders.ts +259 -45
- package/src/server/render/not-found.ts +10 -15
- 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 +6 -5
- package/src/server/render/ssr.ts +155 -67
- package/src/server/render/template.ts +2 -1
- package/src/server/router/discovery.ts +39 -22
- package/src/server/router/hmr.ts +15 -13
- package/src/server/router/index.ts +1 -1
- package/src/server/router/patterns.ts +16 -15
- package/src/server/router/plugin.ts +151 -158
- package/src/server/router/schema-merge.ts +52 -0
- package/src/server/router/schemas.ts +55 -73
- package/src/server/router/types.ts +1 -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 +15 -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 +141 -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 +4 -4
- package/src/shared/deferred-ndjson.ts +34 -6
- package/src/shared/digest.ts +2 -2
- package/src/shared/parser.ts +5 -0
- package/src/shared/route-frame.ts +429 -0
- package/src/shared/search-params.ts +7 -7
- package/src/shared/utils/index.ts +5 -3
- package/dist/server/dev-inspector.d.ts +0 -89
- package/dist/server/sync/memory-adapter.d.ts +0 -17
- package/src/server/dev-inspector.ts +0 -60
- package/src/server/sync/memory-adapter.ts +0 -196
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
applyRevalidateEntries,
|
|
17
17
|
applyRevalidateHeader,
|
|
18
|
+
decodeHashFragment,
|
|
19
|
+
isSameOriginFetchResult,
|
|
18
20
|
normalizeHref,
|
|
19
21
|
shouldAutoRefreshPath,
|
|
20
22
|
shouldInterceptClick,
|
|
@@ -22,7 +24,7 @@ import {
|
|
|
22
24
|
stripHashFromHref,
|
|
23
25
|
toLogical,
|
|
24
26
|
} from "./link-utils.ts";
|
|
25
|
-
import { createSearchStore,
|
|
27
|
+
import { createSearchStore, SearchStoreContext } from "./search-store.ts";
|
|
26
28
|
import {
|
|
27
29
|
buildDataEndpoint,
|
|
28
30
|
buildNotFoundPageElement,
|
|
@@ -45,6 +47,11 @@ import type {
|
|
|
45
47
|
|
|
46
48
|
const EMPTY_SEARCH: SearchParamsInput = {};
|
|
47
49
|
|
|
50
|
+
function getHistoryStateObject(): object {
|
|
51
|
+
const value = history.state;
|
|
52
|
+
return value !== null && typeof value === "object" ? value : {};
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
export function setPrefetchCacheEntry(
|
|
49
56
|
cache: Map<string, CacheEntry>,
|
|
50
57
|
href: string,
|
|
@@ -81,8 +88,8 @@ export function RouterProvider({
|
|
|
81
88
|
// Initial state. When `initialMatch` is `null`, `initialNotFound` MUST be set —
|
|
82
89
|
// the provider boots into the inline not-found UI.
|
|
83
90
|
const [state, setState] = useState<RouterState>(() => ({
|
|
84
|
-
match: initialMatch,
|
|
85
91
|
data: initialData,
|
|
92
|
+
match: initialMatch,
|
|
86
93
|
notFound: initialNotFound,
|
|
87
94
|
}));
|
|
88
95
|
const [isNavigating, setIsNavigating] = useState(false);
|
|
@@ -124,9 +131,8 @@ export function RouterProvider({
|
|
|
124
131
|
* fetch URL: runtime `/_furin/data` for SSR/ISR/dev, per-route
|
|
125
132
|
* `__furin_data.ndjson` for static exports.
|
|
126
133
|
*/
|
|
127
|
-
const
|
|
134
|
+
const [staticMode] = useState(detectStaticMode);
|
|
128
135
|
const resolvedSearch = (state.data.query as SearchParamsInput | undefined) ?? EMPTY_SEARCH;
|
|
129
|
-
const searchStoreRef = useRef<SearchStore | null>(null);
|
|
130
136
|
|
|
131
137
|
/**
|
|
132
138
|
* Depth-0 boundary (pagesDir root level) for the "no client route matched" 404
|
|
@@ -141,7 +147,6 @@ export function RouterProvider({
|
|
|
141
147
|
return [depth0];
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
|
-
return;
|
|
145
150
|
}, [routes]);
|
|
146
151
|
|
|
147
152
|
/**
|
|
@@ -164,12 +169,12 @@ export function RouterProvider({
|
|
|
164
169
|
}
|
|
165
170
|
const { __furinStatus: _s, __furinNotFound: _n, ...cleanData } = data ?? {};
|
|
166
171
|
return {
|
|
167
|
-
match: currentMatchRef.current,
|
|
168
172
|
data: cleanData,
|
|
169
|
-
title,
|
|
170
173
|
finalHref,
|
|
174
|
+
match: currentMatchRef.current,
|
|
171
175
|
notFound: kind.error,
|
|
172
176
|
notFoundBoundaries: rootBoundaries,
|
|
177
|
+
title,
|
|
173
178
|
};
|
|
174
179
|
},
|
|
175
180
|
[basePath, rootBoundaries]
|
|
@@ -198,7 +203,7 @@ export function RouterProvider({
|
|
|
198
203
|
}
|
|
199
204
|
|
|
200
205
|
// ── NDJSON data endpoint + JS chunk load (parallel) ──────────────────
|
|
201
|
-
const dataEndpoint = buildDataEndpoint(basePath, logicalHref,
|
|
206
|
+
const dataEndpoint = buildDataEndpoint(basePath, logicalHref, staticMode);
|
|
202
207
|
const [res, loadedMod] = await Promise.all([fetch(dataEndpoint, { signal }), match.load()]);
|
|
203
208
|
|
|
204
209
|
// Stale-deploy detection: force a full page reload to pick up the new bundle.
|
|
@@ -217,9 +222,9 @@ export function RouterProvider({
|
|
|
217
222
|
} catch (parseErr) {
|
|
218
223
|
log.warn({
|
|
219
224
|
action: "navigate_server_error",
|
|
225
|
+
error: String(parseErr),
|
|
220
226
|
href: physicalHref,
|
|
221
227
|
status: res.status,
|
|
222
|
-
error: String(parseErr),
|
|
223
228
|
});
|
|
224
229
|
return null;
|
|
225
230
|
}
|
|
@@ -265,11 +270,11 @@ export function RouterProvider({
|
|
|
265
270
|
// Loader threw a non-redirect Response (or an Error).
|
|
266
271
|
if (__furinError) {
|
|
267
272
|
return {
|
|
268
|
-
match: loadedMatch,
|
|
269
273
|
data: {},
|
|
270
|
-
title,
|
|
271
|
-
finalHref,
|
|
272
274
|
error: __furinError,
|
|
275
|
+
finalHref,
|
|
276
|
+
match: loadedMatch,
|
|
277
|
+
title,
|
|
273
278
|
};
|
|
274
279
|
}
|
|
275
280
|
|
|
@@ -280,27 +285,31 @@ export function RouterProvider({
|
|
|
280
285
|
}
|
|
281
286
|
|
|
282
287
|
if (__furinStatus === 404) {
|
|
288
|
+
const notFound =
|
|
289
|
+
__furinNotFound !== null && typeof __furinNotFound === "object"
|
|
290
|
+
? (__furinNotFound as { data?: unknown; message?: string })
|
|
291
|
+
: {};
|
|
283
292
|
return {
|
|
284
|
-
match: loadedMatch,
|
|
285
293
|
data,
|
|
286
|
-
title,
|
|
287
294
|
finalHref,
|
|
288
|
-
|
|
295
|
+
match: loadedMatch,
|
|
296
|
+
notFound,
|
|
297
|
+
title,
|
|
289
298
|
};
|
|
290
299
|
}
|
|
291
300
|
|
|
292
301
|
// Server-side redirect: do not mount the pre-redirect route.
|
|
293
302
|
if (finalHref) {
|
|
294
|
-
return { match: null,
|
|
303
|
+
return { data, finalHref, match: null, title };
|
|
295
304
|
}
|
|
296
305
|
|
|
297
|
-
return { match: loadedMatch,
|
|
306
|
+
return { data, finalHref, match: loadedMatch, title };
|
|
298
307
|
} catch (err: unknown) {
|
|
299
308
|
if (!isAbortError(err)) {
|
|
300
309
|
log.error({
|
|
301
310
|
action: "navigate_failed",
|
|
302
|
-
href: basePath + logicalHref,
|
|
303
311
|
error: String(err),
|
|
312
|
+
href: basePath + logicalHref,
|
|
304
313
|
});
|
|
305
314
|
}
|
|
306
315
|
return null;
|
|
@@ -345,8 +354,8 @@ export function RouterProvider({
|
|
|
345
354
|
prefetchCache.current,
|
|
346
355
|
href,
|
|
347
356
|
{
|
|
348
|
-
promise: fetchPageState(href, undefined),
|
|
349
357
|
createdAt: Date.now(),
|
|
358
|
+
promise: fetchPageState(href, undefined),
|
|
350
359
|
staleTime,
|
|
351
360
|
},
|
|
352
361
|
prefetchCacheSize
|
|
@@ -362,14 +371,14 @@ export function RouterProvider({
|
|
|
362
371
|
signal: AbortSignal | undefined
|
|
363
372
|
): Promise<RouterState | null> {
|
|
364
373
|
const cached = prefetchCache.current.get(redirectLogical);
|
|
365
|
-
const
|
|
374
|
+
const redirectState =
|
|
366
375
|
cached && !shouldRefetch(cached)
|
|
367
376
|
? await cached.promise
|
|
368
377
|
: await fetchPageState(redirectLogical, signal);
|
|
369
378
|
if (navVersion.current !== myVersion) {
|
|
370
379
|
return null;
|
|
371
380
|
}
|
|
372
|
-
return
|
|
381
|
+
return redirectState;
|
|
373
382
|
}
|
|
374
383
|
|
|
375
384
|
const navigate = useCallback(
|
|
@@ -379,7 +388,8 @@ export function RouterProvider({
|
|
|
379
388
|
opts: { replace?: boolean; resetScroll?: boolean } | undefined
|
|
380
389
|
) {
|
|
381
390
|
const logicalHref = normalizeHref(rawLogicalHref);
|
|
382
|
-
|
|
391
|
+
navVersion.current += 1;
|
|
392
|
+
const myVersion = navVersion.current;
|
|
383
393
|
navAbortRef.current?.abort();
|
|
384
394
|
const navAbort = new AbortController();
|
|
385
395
|
navAbortRef.current = navAbort;
|
|
@@ -399,8 +409,8 @@ export function RouterProvider({
|
|
|
399
409
|
prefetchCache.current,
|
|
400
410
|
logicalHref,
|
|
401
411
|
{
|
|
402
|
-
promise: Promise.resolve(newState),
|
|
403
412
|
createdAt: Date.now(),
|
|
413
|
+
promise: Promise.resolve(newState),
|
|
404
414
|
staleTime: defaultPreloadStaleTime,
|
|
405
415
|
},
|
|
406
416
|
prefetchCacheSize
|
|
@@ -423,7 +433,7 @@ export function RouterProvider({
|
|
|
423
433
|
const redirectPhysical = basePath + redirectLogical;
|
|
424
434
|
window.history.replaceState(
|
|
425
435
|
{
|
|
426
|
-
...(
|
|
436
|
+
...getHistoryStateObject(),
|
|
427
437
|
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey(),
|
|
428
438
|
},
|
|
429
439
|
"",
|
|
@@ -450,7 +460,7 @@ export function RouterProvider({
|
|
|
450
460
|
if (opts?.replace) {
|
|
451
461
|
window.history.replaceState(
|
|
452
462
|
{
|
|
453
|
-
...(
|
|
463
|
+
...getHistoryStateObject(),
|
|
454
464
|
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey(),
|
|
455
465
|
},
|
|
456
466
|
"",
|
|
@@ -467,7 +477,7 @@ export function RouterProvider({
|
|
|
467
477
|
const logicalPath = normalizeHref(toLogical(effectiveUrl.pathname, basePath));
|
|
468
478
|
setCurrentHref(logicalPath + effectiveUrl.search);
|
|
469
479
|
if (opts?.resetScroll ?? true) {
|
|
470
|
-
pendingScrollRef.current = { type: "reset"
|
|
480
|
+
pendingScrollRef.current = { href: physicalEffective, type: "reset" };
|
|
471
481
|
}
|
|
472
482
|
} finally {
|
|
473
483
|
if (navVersion.current === myVersion) {
|
|
@@ -478,15 +488,14 @@ export function RouterProvider({
|
|
|
478
488
|
[basePath, fetchPageState, defaultPreloadStaleTime, prefetchCacheSize]
|
|
479
489
|
);
|
|
480
490
|
|
|
481
|
-
|
|
482
|
-
|
|
491
|
+
const [searchStore] = useState(() =>
|
|
492
|
+
createSearchStore({
|
|
483
493
|
currentHref,
|
|
484
494
|
navigate,
|
|
485
495
|
search: resolvedSearch,
|
|
486
496
|
searchRoutes: routes,
|
|
487
|
-
})
|
|
488
|
-
|
|
489
|
-
const searchStore = searchStoreRef.current;
|
|
497
|
+
})
|
|
498
|
+
);
|
|
490
499
|
const searchSnapshot = useMemo(
|
|
491
500
|
() => ({
|
|
492
501
|
currentHref,
|
|
@@ -540,7 +549,8 @@ export function RouterProvider({
|
|
|
540
549
|
const destKey = getHistoryKey(history.state);
|
|
541
550
|
const logicalPath = normalizeHref(toLogical(window.location.pathname, basePath));
|
|
542
551
|
const logicalHref = logicalPath + window.location.search;
|
|
543
|
-
|
|
552
|
+
navVersion.current += 1;
|
|
553
|
+
const myVersion = navVersion.current;
|
|
544
554
|
navAbortRef.current?.abort();
|
|
545
555
|
const navAbort = new AbortController();
|
|
546
556
|
navAbortRef.current = navAbort;
|
|
@@ -597,9 +607,9 @@ export function RouterProvider({
|
|
|
597
607
|
}
|
|
598
608
|
setCurrentHref(normalizeHref(effectiveLogical));
|
|
599
609
|
if (destKey) {
|
|
600
|
-
pendingScrollRef.current = { type: "restore"
|
|
610
|
+
pendingScrollRef.current = { key: destKey, type: "restore" };
|
|
601
611
|
} else {
|
|
602
|
-
window.scrollTo({
|
|
612
|
+
window.scrollTo({ behavior: "instant", top: 0 });
|
|
603
613
|
}
|
|
604
614
|
} finally {
|
|
605
615
|
if (navVersion.current === myVersion) {
|
|
@@ -613,10 +623,7 @@ export function RouterProvider({
|
|
|
613
623
|
useEffect(() => {
|
|
614
624
|
history.scrollRestoration = "manual";
|
|
615
625
|
if (!getHistoryKey(history.state)) {
|
|
616
|
-
history.replaceState(
|
|
617
|
-
{ ...((history.state as object) ?? {}), _furinKey: generateHistoryKey() },
|
|
618
|
-
""
|
|
619
|
-
);
|
|
626
|
+
history.replaceState({ ...getHistoryStateObject(), _furinKey: generateHistoryKey() }, "");
|
|
620
627
|
}
|
|
621
628
|
}, []);
|
|
622
629
|
|
|
@@ -633,22 +640,22 @@ export function RouterProvider({
|
|
|
633
640
|
const raw = sessionStorage.getItem(SCROLL_STORAGE_KEY);
|
|
634
641
|
const positions: Record<string, number> = raw ? JSON.parse(raw) : {};
|
|
635
642
|
const y = positions[instruction.key] ?? 0;
|
|
636
|
-
window.scrollTo({
|
|
643
|
+
window.scrollTo({ behavior: "instant", top: y });
|
|
637
644
|
} catch {
|
|
638
|
-
window.scrollTo({
|
|
645
|
+
window.scrollTo({ behavior: "instant", top: 0 });
|
|
639
646
|
}
|
|
640
647
|
return;
|
|
641
648
|
}
|
|
642
649
|
|
|
643
650
|
const destUrl = new URL(instruction.href, window.location.origin);
|
|
644
651
|
if (destUrl.hash) {
|
|
645
|
-
const id =
|
|
652
|
+
const id = decodeHashFragment(destUrl.hash.slice(1));
|
|
646
653
|
const element = document.getElementById(id);
|
|
647
654
|
if (element) {
|
|
648
655
|
element.scrollIntoView({ behavior: "instant", block: "start" });
|
|
649
656
|
}
|
|
650
657
|
} else {
|
|
651
|
-
window.scrollTo({
|
|
658
|
+
window.scrollTo({ behavior: "instant", top: 0 });
|
|
652
659
|
}
|
|
653
660
|
}, [currentHref]);
|
|
654
661
|
|
|
@@ -688,12 +695,22 @@ export function RouterProvider({
|
|
|
688
695
|
if (logicalHref === null) {
|
|
689
696
|
return;
|
|
690
697
|
}
|
|
698
|
+
// Don't capture a link that matches no local route: it may belong to a
|
|
699
|
+
// sibling furin app mounted under a different basePath. Let the browser
|
|
700
|
+
// navigate; the server routes it to the correct app.
|
|
701
|
+
const logicalPathname = new URL(logicalHref, window.location.origin).pathname;
|
|
702
|
+
const hasConcreteMatch = routes.some(
|
|
703
|
+
(route) => !route.pattern.split("/").includes("*") && route.regex.test(logicalPathname)
|
|
704
|
+
);
|
|
705
|
+
if (!hasConcreteMatch) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
691
708
|
e.preventDefault();
|
|
692
709
|
navigate(logicalHref, { resetScroll: !logicalHref.includes("#") });
|
|
693
710
|
};
|
|
694
711
|
document.addEventListener("click", handler);
|
|
695
712
|
return () => document.removeEventListener("click", handler);
|
|
696
|
-
}, [navigate, basePath]);
|
|
713
|
+
}, [navigate, basePath, routes]);
|
|
697
714
|
|
|
698
715
|
// Intercept all window.fetch calls to auto-process X-Furin-Revalidate headers.
|
|
699
716
|
useEffect(() => {
|
|
@@ -703,6 +720,9 @@ export function RouterProvider({
|
|
|
703
720
|
const originalFetch = window.fetch;
|
|
704
721
|
const wrapped = async (...args: Parameters<typeof fetch>): Promise<Response> => {
|
|
705
722
|
const response = await originalFetch.apply(window, args);
|
|
723
|
+
if (!isSameOriginFetchResult(args[0], response.url, window.location.origin)) {
|
|
724
|
+
return response;
|
|
725
|
+
}
|
|
706
726
|
const invalidated: Array<{ path: string; type: "page" | "layout" }> = [];
|
|
707
727
|
applyRevalidateHeader(response.headers, (path, type) => {
|
|
708
728
|
const resolvedType = type ?? "page";
|
|
@@ -729,6 +749,7 @@ export function RouterProvider({
|
|
|
729
749
|
}, [invalidatePrefetch, invalidationRefresh, autoRefresh, basePath]);
|
|
730
750
|
|
|
731
751
|
// Listen for sync cursor notifications and recover changes over HTTP.
|
|
752
|
+
// react-doctor-disable-next-line react-doctor/effect-needs-cleanup
|
|
732
753
|
useEffect(() => {
|
|
733
754
|
if (!syncStream || typeof window === "undefined" || typeof EventSource === "undefined") {
|
|
734
755
|
return;
|
|
@@ -782,6 +803,7 @@ export function RouterProvider({
|
|
|
782
803
|
}
|
|
783
804
|
});
|
|
784
805
|
};
|
|
806
|
+
const onOpen = () => recover();
|
|
785
807
|
const onSync = (event: MessageEvent) => {
|
|
786
808
|
try {
|
|
787
809
|
const payload = JSON.parse(event.data) as { cursor?: unknown };
|
|
@@ -799,6 +821,7 @@ export function RouterProvider({
|
|
|
799
821
|
return;
|
|
800
822
|
}
|
|
801
823
|
source = new EventSource(streamUrl);
|
|
824
|
+
source.addEventListener("open", onOpen);
|
|
802
825
|
source.addEventListener("furin.sync", onSync);
|
|
803
826
|
};
|
|
804
827
|
|
|
@@ -809,8 +832,6 @@ export function RouterProvider({
|
|
|
809
832
|
return;
|
|
810
833
|
}
|
|
811
834
|
connect();
|
|
812
|
-
// Close the initialization/SSE race using the durable change log.
|
|
813
|
-
recover();
|
|
814
835
|
})
|
|
815
836
|
.catch((error: unknown) => {
|
|
816
837
|
if (disposed) {
|
|
@@ -822,6 +843,7 @@ export function RouterProvider({
|
|
|
822
843
|
});
|
|
823
844
|
return () => {
|
|
824
845
|
disposed = true;
|
|
846
|
+
source?.removeEventListener("open", onOpen);
|
|
825
847
|
source?.removeEventListener("furin.sync", onSync);
|
|
826
848
|
source?.close();
|
|
827
849
|
};
|
|
@@ -856,16 +878,16 @@ export function RouterProvider({
|
|
|
856
878
|
{
|
|
857
879
|
basePath,
|
|
858
880
|
currentHref,
|
|
859
|
-
search: resolvedSearch,
|
|
860
|
-
searchRoutes: routes,
|
|
861
|
-
navigate,
|
|
862
|
-
prefetch,
|
|
863
|
-
refresh,
|
|
864
|
-
invalidatePrefetch,
|
|
865
|
-
isNavigating,
|
|
866
881
|
defaultPreload,
|
|
867
882
|
defaultPreloadDelay,
|
|
868
883
|
defaultPreloadStaleTime,
|
|
884
|
+
invalidatePrefetch,
|
|
885
|
+
isNavigating,
|
|
886
|
+
navigate,
|
|
887
|
+
prefetch,
|
|
888
|
+
refresh,
|
|
889
|
+
search: resolvedSearch,
|
|
890
|
+
searchRoutes: routes,
|
|
869
891
|
},
|
|
870
892
|
pageElement,
|
|
871
893
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RouteManifest as LinkRouteManifest, RouteSearch, RouteTo } from "@teyik0/furin/link";
|
|
2
|
-
import { useCallback, useContext,
|
|
2
|
+
import { useCallback, useContext, useSyncExternalStore } from "react";
|
|
3
3
|
import {
|
|
4
4
|
findSearchDefaultsForRouteTarget,
|
|
5
5
|
type SearchParamsInput,
|
|
@@ -50,16 +50,14 @@ function useSearchSelection<To extends SearchRouteTo, TSelected>(
|
|
|
50
50
|
selector: (search: ResolvedRouteSearch<To>) => TSelected
|
|
51
51
|
): TSelected {
|
|
52
52
|
const store = useContext(SearchStoreContext) ?? FALLBACK_SEARCH_STORE;
|
|
53
|
-
const selectorRef = useRef(selector);
|
|
54
|
-
selectorRef.current = selector;
|
|
55
53
|
|
|
56
54
|
const getSnapshot = useCallback(
|
|
57
|
-
() =>
|
|
58
|
-
[store]
|
|
55
|
+
() => selector(store.getSnapshot().search as ResolvedRouteSearch<To>),
|
|
56
|
+
[selector, store]
|
|
59
57
|
);
|
|
60
58
|
const getServerSnapshot = useCallback(
|
|
61
|
-
() =>
|
|
62
|
-
[store]
|
|
59
|
+
() => selector(store.getServerSnapshot().search as ResolvedRouteSearch<To>),
|
|
60
|
+
[selector, store]
|
|
63
61
|
);
|
|
64
62
|
|
|
65
63
|
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
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
-
import type { RuntimeRoute } from "../../client.ts";
|
|
3
2
|
import type { ErrorComponent } from "../../shared/error.ts";
|
|
4
3
|
import type { NotFoundComponent } from "../../shared/not-found.ts";
|
|
5
4
|
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
5
|
+
import type { RuntimeRoute } from "../internal/runtime-types.ts";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Augment this interface via declaration merging in furin-env.d.ts
|
|
@@ -206,7 +206,7 @@ export interface RouterProviderProps {
|
|
|
206
206
|
root: RuntimeRoute | null;
|
|
207
207
|
routes: ClientRoute[];
|
|
208
208
|
/**
|
|
209
|
-
* Optional internal SSE endpoint emitted by `furin({ sync
|
|
209
|
+
* Optional internal SSE endpoint emitted by `furin({ sync })`.
|
|
210
210
|
* When present, RouterProvider listens for cross-client invalidations.
|
|
211
211
|
*/
|
|
212
212
|
syncStream?: string | undefined;
|
package/src/client/sync.ts
CHANGED
|
@@ -53,8 +53,8 @@ function getResolvedError(result: unknown): unknown | undefined {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const error =
|
|
57
|
-
return error
|
|
56
|
+
const { error } = result as EdenErrorResult;
|
|
57
|
+
return error === null ? undefined : error;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export function useSync<TInput, TResult>(
|
|
@@ -91,6 +91,7 @@ export function useSync<TInput, TResult>(
|
|
|
91
91
|
await onSuccess?.({ idempotencyKey, input, result });
|
|
92
92
|
return result;
|
|
93
93
|
},
|
|
94
|
+
// react-doctor-disable-next-line react-doctor/exhaustive-deps
|
|
94
95
|
[mutation, optimistic, onError, onSuccess]
|
|
95
96
|
);
|
|
96
97
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|