@teyik0/furin 0.5.0-alpha.2 → 0.7.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/dist/adapter/runtime-build.d.ts +3 -1
- package/dist/build/client.d.ts +4 -1
- package/dist/build/entry-template.d.ts +5 -0
- package/dist/build/entry-template.ts +9 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +9589 -6685
- package/dist/build/preload-manifest.d.ts +17 -0
- package/dist/build/request-keys.d.ts +4 -0
- package/dist/build/types.d.ts +6 -0
- package/dist/cli/index.js +9539 -6644
- package/dist/client/browser-events-runtime.d.ts +2 -1
- package/dist/client/client-module.d.ts +26 -0
- package/dist/client/define-route.d.ts +9 -1
- package/dist/client/dev-error-overlay.ts +1 -0
- package/dist/client/document.d.ts +3 -0
- package/dist/client/hmr.d.ts +1 -1
- package/dist/client/internal/runtime-types.d.ts +2 -0
- package/dist/client/link.js +1011 -157
- package/dist/client/mutation.d.ts +38 -0
- package/dist/client/query-store.d.ts +85 -0
- package/dist/client/query.d.ts +14 -0
- package/dist/client/route-api.d.ts +11 -0
- package/dist/client/router/context.d.ts +3 -2
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +8 -1
- package/dist/client/router/navigation.d.ts +2 -9
- package/dist/client/router/optimistic.d.ts +41 -0
- package/dist/client/router/search/index.d.ts +3 -3
- package/dist/client/router/search-store.d.ts +1 -0
- package/dist/client/router/sync-catch-up.d.ts +3 -0
- package/dist/client/router/types.d.ts +49 -7
- package/dist/client/sync.d.ts +39 -22
- package/dist/client.d.ts +11 -33
- package/dist/client.js +1222 -57
- package/dist/config.d.ts +7 -0
- package/dist/config.js +1 -0
- package/dist/define-route.d.ts +231 -123
- package/dist/env.d.ts +2 -2
- package/dist/furin.d.ts +4 -2
- package/dist/furin.js +9717 -6796
- package/dist/plugin/hmr-dependencies.d.ts +2 -0
- package/dist/plugin/index.js +811 -145
- package/dist/plugin/transform-client-module.d.ts +16 -0
- package/dist/plugin/transform-client.d.ts +2 -0
- package/dist/plugin/transform-dev-page.d.ts +7 -0
- package/dist/plugin/transform-isomorphic.d.ts +1 -1
- package/dist/routes.d.ts +6 -0
- package/dist/rsc-client.js +87 -16
- package/dist/rsc.js +87 -16
- package/dist/server/auto-invalidate/registry.d.ts +5 -2
- package/dist/server/auto-invalidate/types.d.ts +2 -0
- package/dist/server/browser-events/plugin.d.ts +3 -0
- package/dist/server/cache/isr.d.ts +2 -4
- package/dist/server/cache/route-cache.d.ts +5 -0
- package/dist/server/dev/graph.d.ts +1 -0
- package/dist/server/dev/runtime.production.d.ts +1 -0
- package/dist/server/dev-page-plugin.d.ts +6 -19
- package/dist/server/internal.d.ts +5 -0
- package/dist/server/internal.js +105 -57
- package/dist/server/production-server.js +104 -56
- package/dist/server/render/assemble.d.ts +6 -6
- package/dist/server/render/document.d.ts +1 -1
- package/dist/server/render/element.d.ts +1 -1
- package/dist/server/render/loaders.d.ts +15 -5
- package/dist/server/render/mixed-cache.d.ts +6 -0
- package/dist/server/render/react-stream.d.ts +3 -0
- package/dist/server/render/ssr.d.ts +5 -4
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +2 -0
- package/dist/server/router/discovery.d.ts +1 -0
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/router/patterns.d.ts +3 -0
- package/dist/server/router/plugin.d.ts +3 -0
- package/dist/server/router/types.d.ts +4 -0
- package/dist/server/security/csp.d.ts +12 -0
- package/dist/server/sync/adapter.d.ts +25 -4
- package/dist/server/sync/atomic.d.ts +25 -0
- package/dist/server/sync/drizzle/index.d.ts +45 -0
- package/dist/server/sync/drizzle/index.js +540 -0
- package/dist/server/sync/execution-error.d.ts +2 -0
- package/dist/server/sync/index.d.ts +2 -1
- package/dist/server/sync/index.js +580 -124
- package/dist/server/sync/mutation-handler.d.ts +4 -0
- package/dist/server/sync/plugin.d.ts +34 -11
- package/dist/server/sync/postgres/execute.d.ts +3 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +42 -13
- package/dist/server/sync/postgres/sql.d.ts +8 -0
- package/dist/server/sync/prisma/index.d.ts +24 -0
- package/dist/server/sync/prisma/index.js +340 -0
- package/dist/server/sync/queries.d.ts +21 -0
- package/dist/server/sync/query-context.d.ts +5 -0
- package/dist/server/sync/redis/index.js +3 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/response.d.ts +1 -0
- package/dist/server/sync/sqlite/index.d.ts +3 -0
- package/dist/server/sync/sqlite/index.js +10 -4
- package/dist/server/sync/stream.d.ts +2 -5
- package/dist/server/sync/validation.d.ts +4 -0
- package/dist/shared/defer.d.ts +31 -0
- package/dist/shared/error.d.ts +2 -2
- package/dist/shared/page-key.d.ts +7 -0
- package/dist/shared/query-bindings.d.ts +12 -0
- package/dist/shared/route-frame.d.ts +1 -0
- package/dist/shared/sync-query.d.ts +40 -0
- package/package.json +40 -16
- package/src/adapter/README.md +3 -0
- package/src/adapter/bun.ts +3 -0
- package/src/adapter/package.ts +16 -2
- package/src/adapter/runtime-build.ts +99 -14
- package/src/adapter/static.ts +17 -6
- package/src/adapter/vercel.ts +33 -23
- package/src/build/client.ts +23 -5
- package/src/build/entry-template.ts +9 -0
- package/src/build/hydrate.ts +18 -3
- package/src/build/preload-manifest.ts +100 -0
- package/src/build/production-instrumentation.ts +6 -3
- package/src/build/request-keys.ts +93 -0
- package/src/build/ssg-cache.ts +9 -4
- package/src/build/types.ts +4 -0
- package/src/cli/index.ts +1 -0
- package/src/client/boundaries.tsx +1 -1
- package/src/client/browser-events-runtime.ts +73 -16
- package/src/client/client-module.ts +57 -0
- package/src/client/define-route.ts +11 -2
- package/src/client/dev-error-overlay.ts +1 -0
- package/src/client/document.tsx +47 -20
- package/src/client/hmr.ts +4 -2
- package/src/client/internal/runtime-types.ts +2 -0
- package/src/client/link.tsx +8 -8
- package/src/client/mutation.ts +136 -0
- package/src/client/query-store.ts +418 -0
- package/src/client/query.tsx +67 -0
- package/src/client/route-api.tsx +75 -0
- package/src/client/router/boundary-tree.tsx +10 -6
- package/src/client/router/context.ts +57 -4
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +29 -1
- package/src/client/router/navigation.ts +3 -50
- package/src/client/router/optimistic.ts +233 -0
- package/src/client/router/provider.tsx +404 -96
- package/src/client/router/search/index.ts +37 -17
- package/src/client/router/search-store.ts +4 -0
- package/src/client/router/sync-catch-up.ts +7 -0
- package/src/client/router/types.ts +71 -9
- package/src/client/sync.ts +438 -65
- package/src/client.ts +20 -60
- package/src/config.ts +5 -0
- package/src/define-route.ts +442 -155
- package/src/env.d.ts +2 -2
- package/src/furin.ts +213 -38
- package/src/plugin/hmr-dependencies.ts +58 -0
- package/src/plugin/index.ts +38 -2
- package/src/plugin/route-config-autofix.ts +2 -2
- package/src/plugin/routes.ts +19 -8
- package/src/plugin/transform-client-module.ts +123 -0
- package/src/plugin/transform-client.ts +293 -13
- package/src/plugin/transform-dev-page.ts +231 -0
- package/src/plugin/transform-isomorphic.ts +11 -5
- package/src/routes.ts +8 -0
- package/src/rsc/shared.tsx +104 -18
- package/src/rsc/version.ts +5 -0
- package/src/server/auto-invalidate/registry.ts +56 -24
- package/src/server/auto-invalidate/runtime.ts +17 -0
- package/src/server/auto-invalidate/types.ts +6 -0
- package/src/server/browser-events/plugin.ts +112 -1
- package/src/server/cache/dev-loader.ts +1 -1
- package/src/server/cache/invalidation.ts +2 -0
- package/src/server/cache/isr-ssg.ts +1 -1
- package/src/server/cache/isr.ts +6 -34
- package/src/server/cache/route-cache.ts +40 -4
- package/src/server/cache/ssg.ts +1 -1
- package/src/server/dev/diagnostics.ts +4 -2
- package/src/server/dev/error.ts +2 -1
- package/src/server/dev/graph.ts +70 -7
- package/src/server/dev/runtime.production.ts +4 -0
- package/src/server/dev/symbolicate.ts +2 -0
- package/src/server/dev-page-plugin.ts +160 -63
- package/src/server/evlog.ts +1 -1
- package/src/server/internal.ts +5 -0
- package/src/server/render/assemble.ts +15 -11
- package/src/server/render/document.tsx +13 -2
- package/src/server/render/element.tsx +11 -6
- package/src/server/render/isr.ts +71 -33
- package/src/server/render/loaders.ts +328 -70
- package/src/server/render/mixed-cache.ts +327 -0
- package/src/server/render/not-found.ts +14 -11
- package/src/server/render/ppr-document.ts +47 -11
- package/src/server/render/ppr-route.ts +54 -20
- package/src/server/render/react-stream.ts +17 -0
- package/src/server/render/route-frame-transport.ts +3 -0
- package/src/server/render/ssg.ts +53 -19
- package/src/server/render/ssr.ts +105 -36
- package/src/server/render/static-params.ts +1 -1
- package/src/server/render/template.ts +23 -0
- package/src/server/router/defined-route.ts +3 -0
- package/src/server/router/discovery.ts +14 -0
- package/src/server/router/hmr.ts +109 -18
- package/src/server/router/patterns.ts +27 -0
- package/src/server/router/plugin.ts +94 -19
- package/src/server/router/source-version.ts +20 -2
- package/src/server/router/types.ts +4 -0
- package/src/server/security/csp.ts +44 -0
- package/src/server/sync/adapter.ts +41 -4
- package/src/server/sync/atomic.ts +303 -0
- package/src/server/sync/drizzle/index.ts +145 -0
- package/src/server/sync/execution-error.ts +1 -0
- package/src/server/sync/fingerprint.ts +2 -6
- package/src/server/sync/index.ts +6 -0
- package/src/server/sync/mutation-handler.ts +69 -0
- package/src/server/sync/plugin.ts +177 -60
- package/src/server/sync/postgres/execute.ts +20 -0
- package/src/server/sync/postgres/index.ts +60 -16
- package/src/server/sync/postgres/sql.ts +20 -0
- package/src/server/sync/prisma/index.ts +70 -0
- package/src/server/sync/queries.ts +75 -0
- package/src/server/sync/query-context.ts +85 -0
- package/src/server/sync/redis/index.ts +7 -3
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/response.ts +21 -0
- package/src/server/sync/sqlite/index.ts +19 -8
- package/src/server/sync/stream.ts +14 -22
- package/src/server/sync/validation.ts +34 -0
- package/src/shared/defer.ts +48 -0
- package/src/shared/error.ts +2 -2
- package/src/shared/page-key.ts +36 -0
- package/src/shared/query-bindings.ts +138 -0
- package/src/shared/route-frame.ts +13 -1
- package/src/shared/route-map.ts +12 -2
- package/src/shared/sync-query.ts +138 -0
package/dist/client/link.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/client/link.tsx
|
|
3
|
-
import { createElement as
|
|
3
|
+
import { createElement as createElement7, useCallback as useCallback4, useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
4
4
|
|
|
5
5
|
// src/shared/search-params.ts
|
|
6
6
|
function routeSegmentSpecificity(segment) {
|
|
@@ -127,7 +127,7 @@ function findSearchDefaultsForRouteTarget(to, routes) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// src/client/router/context.ts
|
|
130
|
-
import { createContext, useContext } from "react";
|
|
130
|
+
import { createContext, useCallback, useContext, useMemo } from "react";
|
|
131
131
|
|
|
132
132
|
// src/client/router/link-utils.ts
|
|
133
133
|
var HASH_FRAGMENT_RE = /#.*$/;
|
|
@@ -190,6 +190,10 @@ function applyLinkParams(to, params) {
|
|
|
190
190
|
}
|
|
191
191
|
return url;
|
|
192
192
|
}
|
|
193
|
+
function resolveRouteTarget(target, routes) {
|
|
194
|
+
const path = applyLinkParams(target.to, target.params);
|
|
195
|
+
return buildHref(path, target.search, target.hash, findSearchDefaultsForRouteTarget(path, routes));
|
|
196
|
+
}
|
|
193
197
|
function buildHref(to, search, hash, searchDefaults) {
|
|
194
198
|
let url = to;
|
|
195
199
|
if (search && Object.keys(search).length > 0) {
|
|
@@ -320,13 +324,66 @@ var CLIENT_FALLBACK_ROUTER = {
|
|
|
320
324
|
search: {},
|
|
321
325
|
searchRoutes: []
|
|
322
326
|
};
|
|
323
|
-
function
|
|
327
|
+
function useRouterContext() {
|
|
324
328
|
const ctx = useContext(RouterContext);
|
|
325
329
|
return ctx ?? CLIENT_FALLBACK_ROUTER;
|
|
326
330
|
}
|
|
331
|
+
function useRouter() {
|
|
332
|
+
const context = useRouterContext();
|
|
333
|
+
const navigate = useCallback((next, opts) => {
|
|
334
|
+
const href = typeof next === "string" ? next : resolveRouteTarget(next, context.searchRoutes);
|
|
335
|
+
const policy = navigationHrefPolicy(href, typeof window === "undefined" ? undefined : window.location.origin);
|
|
336
|
+
if (policy === "blocked") {
|
|
337
|
+
return Promise.reject(new Error("[furin] Unsafe navigation URL."));
|
|
338
|
+
}
|
|
339
|
+
if (policy === "external" && typeof window !== "undefined") {
|
|
340
|
+
window.location.assign(href);
|
|
341
|
+
return Promise.resolve();
|
|
342
|
+
}
|
|
343
|
+
if (typeof next === "string") {
|
|
344
|
+
return context.navigate(href, opts);
|
|
345
|
+
}
|
|
346
|
+
const options = next.replace === undefined && next.resetScroll === undefined ? undefined : { replace: next.replace, resetScroll: next.resetScroll };
|
|
347
|
+
return context.navigate(href, options);
|
|
348
|
+
}, [context.navigate, context.searchRoutes]);
|
|
349
|
+
const prefetch = useCallback((next, opts) => {
|
|
350
|
+
const href = typeof next === "string" ? next : resolveRouteTarget(next, context.searchRoutes);
|
|
351
|
+
const policy = navigationHrefPolicy(href, typeof window === "undefined" ? undefined : window.location.origin);
|
|
352
|
+
if (policy !== "internal") {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
context.prefetch(href, typeof next === "string" ? opts : { staleTime: next.staleTime });
|
|
356
|
+
}, [context.prefetch, context.searchRoutes]);
|
|
357
|
+
return useMemo(() => ({ ...context, navigate, prefetch }), [context, navigate, prefetch]);
|
|
358
|
+
}
|
|
327
359
|
|
|
328
360
|
// src/client/router/boundary-tree.tsx
|
|
329
|
-
import { createElement as
|
|
361
|
+
import { createElement as createElement3 } from "react";
|
|
362
|
+
|
|
363
|
+
// src/shared/page-key.ts
|
|
364
|
+
function identityValue(value) {
|
|
365
|
+
return Object.is(value, -0) ? "-0" : String(value);
|
|
366
|
+
}
|
|
367
|
+
function pageKey(pattern, data, remountDeps) {
|
|
368
|
+
const { params, query } = data;
|
|
369
|
+
if (remountDeps) {
|
|
370
|
+
const deps = remountDeps({ params: params ?? {}, query: query ?? {} });
|
|
371
|
+
return JSON.stringify([pattern, deps.map((value) => [typeof value, identityValue(value)])]);
|
|
372
|
+
}
|
|
373
|
+
const entries = Object.entries(params ?? {}).sort(([left], [right]) => {
|
|
374
|
+
if (left < right) {
|
|
375
|
+
return -1;
|
|
376
|
+
}
|
|
377
|
+
return left > right ? 1 : 0;
|
|
378
|
+
});
|
|
379
|
+
return JSON.stringify([
|
|
380
|
+
pattern,
|
|
381
|
+
entries.map(([name, value]) => [
|
|
382
|
+
name,
|
|
383
|
+
Array.isArray(value) ? value.map(identityValue) : identityValue(value)
|
|
384
|
+
])
|
|
385
|
+
]);
|
|
386
|
+
}
|
|
330
387
|
|
|
331
388
|
// src/client/boundaries.tsx
|
|
332
389
|
import { Component, Fragment as Fragment2 } from "react";
|
|
@@ -667,6 +724,7 @@ var DefaultNotFoundFallback = ({ error }) => /* @__PURE__ */ jsxDEV(DefaultNotFo
|
|
|
667
724
|
|
|
668
725
|
// src/client/document.tsx
|
|
669
726
|
import { createContext as createContext2, createElement, useContext as useContext2 } from "react";
|
|
727
|
+
import { preloadModule } from "react-dom";
|
|
670
728
|
import { jsxDEV as jsxDEV2, Fragment } from "react/jsx-dev-runtime";
|
|
671
729
|
var DocumentContext = createContext2(null);
|
|
672
730
|
function serializeJson(value) {
|
|
@@ -684,34 +742,45 @@ function DocumentProvider({
|
|
|
684
742
|
function useDocumentState() {
|
|
685
743
|
return useContext2(DocumentContext);
|
|
686
744
|
}
|
|
687
|
-
function renderMeta(meta,
|
|
745
|
+
function renderMeta(meta, key) {
|
|
688
746
|
if ("title" in meta) {
|
|
689
747
|
return /* @__PURE__ */ jsxDEV2("title", {
|
|
690
748
|
children: meta.title
|
|
691
|
-
},
|
|
749
|
+
}, key, false, undefined, this);
|
|
692
750
|
}
|
|
693
751
|
if ("script:ld+json" in meta) {
|
|
694
752
|
return /* @__PURE__ */ jsxDEV2("script", {
|
|
695
753
|
dangerouslySetInnerHTML: { __html: serializeJson(meta["script:ld+json"]) },
|
|
696
754
|
type: "application/ld+json"
|
|
697
|
-
},
|
|
755
|
+
}, key, false, undefined, this);
|
|
698
756
|
}
|
|
699
757
|
if ("tagName" in meta) {
|
|
700
758
|
const { tagName, ...attributes } = meta;
|
|
701
|
-
return createElement(tagName, { ...attributes, key
|
|
759
|
+
return createElement(tagName, { ...attributes, key });
|
|
702
760
|
}
|
|
703
|
-
return createElement("meta", { ...meta, key
|
|
761
|
+
return createElement("meta", { ...meta, key });
|
|
704
762
|
}
|
|
705
763
|
function HeadContent() {
|
|
706
764
|
const state = useContext2(DocumentContext);
|
|
707
765
|
if (state === null) {
|
|
708
766
|
throw new Error("[furin] <HeadContent /> must be rendered inside the root layout.");
|
|
709
767
|
}
|
|
768
|
+
for (const href of state.assets.modulePreloads ?? []) {
|
|
769
|
+
preloadModule(href, { as: "script", nonce: state.nonce });
|
|
770
|
+
}
|
|
771
|
+
const occurrences = new Map;
|
|
772
|
+
const descriptorKey = (descriptor) => {
|
|
773
|
+
const identity = JSON.stringify(descriptor);
|
|
774
|
+
const occurrence = occurrences.get(identity) ?? 0;
|
|
775
|
+
occurrences.set(identity, occurrence + 1);
|
|
776
|
+
return `${identity}:${occurrence}`;
|
|
777
|
+
};
|
|
710
778
|
return /* @__PURE__ */ jsxDEV2(Fragment, {
|
|
711
779
|
children: [
|
|
712
780
|
state.assets.extensionErrorFilterScript === undefined ? null : /* @__PURE__ */ jsxDEV2("script", {
|
|
713
781
|
dangerouslySetInnerHTML: { __html: state.assets.extensionErrorFilterScript },
|
|
714
|
-
"data-furin-extension-error-filter": ""
|
|
782
|
+
"data-furin-extension-error-filter": "",
|
|
783
|
+
nonce: state.nonce
|
|
715
784
|
}, undefined, false, undefined, this),
|
|
716
785
|
/* @__PURE__ */ jsxDEV2("meta", {
|
|
717
786
|
charSet: "utf-8",
|
|
@@ -738,18 +807,20 @@ function HeadContent() {
|
|
|
738
807
|
href,
|
|
739
808
|
rel: "stylesheet"
|
|
740
809
|
}, href, false, undefined, this)),
|
|
741
|
-
state.head?.meta?.map(renderMeta),
|
|
742
|
-
state.head?.links?.map((link
|
|
810
|
+
state.head?.meta?.map((meta) => renderMeta(meta, descriptorKey(meta))),
|
|
811
|
+
state.head?.links?.map((link) => /* @__PURE__ */ jsxDEV2("link", {
|
|
743
812
|
...link
|
|
744
|
-
},
|
|
745
|
-
state.head?.scripts?.map(({ children, ...attributes }
|
|
813
|
+
}, descriptorKey(link), false, undefined, this)),
|
|
814
|
+
state.head?.scripts?.map(({ children, ...attributes }) => /* @__PURE__ */ jsxDEV2("script", {
|
|
746
815
|
...attributes,
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
816
|
+
nonce: state.nonce ?? attributes.nonce,
|
|
817
|
+
children
|
|
818
|
+
}, descriptorKey({ children, ...attributes }), false, undefined, this)),
|
|
819
|
+
state.head?.styles?.map(({ children, type }) => /* @__PURE__ */ jsxDEV2("style", {
|
|
750
820
|
dangerouslySetInnerHTML: { __html: children },
|
|
821
|
+
nonce: state.nonce,
|
|
751
822
|
type
|
|
752
|
-
},
|
|
823
|
+
}, descriptorKey({ children, type }), false, undefined, this))
|
|
753
824
|
]
|
|
754
825
|
}, undefined, true, undefined, this);
|
|
755
826
|
}
|
|
@@ -786,12 +857,14 @@ function Scripts() {
|
|
|
786
857
|
state.assets.frameworkModules.map((src) => /* @__PURE__ */ jsxDEV2("script", {
|
|
787
858
|
crossOrigin: "",
|
|
788
859
|
"data-furin-framework-module": "",
|
|
860
|
+
nonce: state.nonce,
|
|
789
861
|
src,
|
|
790
862
|
type: "module"
|
|
791
863
|
}, src, false, undefined, this)),
|
|
792
864
|
state.assets.entryModule === undefined ? null : /* @__PURE__ */ jsxDEV2("script", {
|
|
793
865
|
crossOrigin: "",
|
|
794
866
|
"data-furin-entry": "",
|
|
867
|
+
nonce: state.nonce,
|
|
795
868
|
src: state.assets.entryModule,
|
|
796
869
|
type: "module"
|
|
797
870
|
}, undefined, false, undefined, this)
|
|
@@ -874,7 +947,7 @@ class FurinErrorBoundary extends Component {
|
|
|
874
947
|
}
|
|
875
948
|
componentDidUpdate(prevProps) {
|
|
876
949
|
if (prevProps.resetKey !== this.props.resetKey && this.state.error) {
|
|
877
|
-
this.
|
|
950
|
+
this.setState((state) => ({ digest: null, epoch: state.epoch + 1, error: null }));
|
|
878
951
|
}
|
|
879
952
|
}
|
|
880
953
|
reset = () => {
|
|
@@ -956,6 +1029,31 @@ function wrapSegmentBoundaries(inner, segment, options) {
|
|
|
956
1029
|
return wrapped;
|
|
957
1030
|
}
|
|
958
1031
|
|
|
1032
|
+
// src/client/route-api.tsx
|
|
1033
|
+
import { createContext as createContext3, createElement as createElement2, useContext as useContext3 } from "react";
|
|
1034
|
+
var RESERVED_RENDER_KEYS = new Set([
|
|
1035
|
+
"catch",
|
|
1036
|
+
"children",
|
|
1037
|
+
"finally",
|
|
1038
|
+
"key",
|
|
1039
|
+
"ref",
|
|
1040
|
+
"then",
|
|
1041
|
+
"toJSON"
|
|
1042
|
+
]);
|
|
1043
|
+
var ROUTE_CONTEXT = Symbol.for("furin.route.context.v1");
|
|
1044
|
+
var contextGlobal = globalThis;
|
|
1045
|
+
var RouteContext = contextGlobal[ROUTE_CONTEXT] ??= createContext3(null);
|
|
1046
|
+
function withRouteSnapshot(element, pattern, props) {
|
|
1047
|
+
const {
|
|
1048
|
+
params,
|
|
1049
|
+
path: _path,
|
|
1050
|
+
query: _query,
|
|
1051
|
+
...data
|
|
1052
|
+
} = props;
|
|
1053
|
+
const loaderData = Object.fromEntries(Object.entries(data).filter(([key]) => !(RESERVED_RENDER_KEYS.has(key) || key.startsWith("__furin"))));
|
|
1054
|
+
return createElement2(RouteContext.Provider, { value: { data: loaderData, params: params ?? {}, pattern } }, element);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
959
1057
|
// src/client/router/boundary-tree.tsx
|
|
960
1058
|
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
961
1059
|
function buildRouterTree(context, pageElement, options) {
|
|
@@ -973,7 +1071,10 @@ function RouteErrorThrower({
|
|
|
973
1071
|
throw new FurinServerError(error);
|
|
974
1072
|
}
|
|
975
1073
|
function buildPageElement(match, root, data, options, error) {
|
|
976
|
-
let element = error ?
|
|
1074
|
+
let element = error ? createElement3(RouteErrorThrower, { error }) : createElement3(match.component, {
|
|
1075
|
+
...data,
|
|
1076
|
+
key: pageKey(match.pattern, data, match.pageRoute.remountDeps)
|
|
1077
|
+
});
|
|
977
1078
|
const chain = [];
|
|
978
1079
|
let current = match.pageRoute;
|
|
979
1080
|
while (current) {
|
|
@@ -989,16 +1090,16 @@ function buildPageElement(match, root, data, options, error) {
|
|
|
989
1090
|
element = wrapSegmentBoundaries(element, byDepth.get(i), options);
|
|
990
1091
|
const Layout = chain[i]?.layout;
|
|
991
1092
|
if (Layout) {
|
|
992
|
-
element =
|
|
1093
|
+
element = createElement3(Layout, data, element);
|
|
993
1094
|
}
|
|
994
1095
|
}
|
|
995
1096
|
if (root) {
|
|
996
1097
|
element = wrapSegmentBoundaries(element, byDepth.get(0), options);
|
|
997
1098
|
if (root.layout) {
|
|
998
|
-
element =
|
|
1099
|
+
element = createElement3(root.layout, data, element);
|
|
999
1100
|
}
|
|
1000
1101
|
}
|
|
1001
|
-
return element;
|
|
1102
|
+
return error ? element : withRouteSnapshot(element, match.pattern, data);
|
|
1002
1103
|
}
|
|
1003
1104
|
// src/client/router/history.ts
|
|
1004
1105
|
var SCROLL_STORAGE_KEY = "__furin_scroll__";
|
|
@@ -1030,25 +1131,10 @@ function isStaleDeployResponse(res) {
|
|
|
1030
1131
|
return Boolean(clientBuildId && serverBuildId !== clientBuildId);
|
|
1031
1132
|
}
|
|
1032
1133
|
// src/client/router/navigation.ts
|
|
1033
|
-
import { useCallback } from "react";
|
|
1034
1134
|
function useNavigate() {
|
|
1035
|
-
|
|
1036
|
-
return useCallback((next) => {
|
|
1037
|
-
const searchDefaults = findSearchDefaultsForRouteTarget(next.to, router.searchRoutes);
|
|
1038
|
-
const href = buildHref(next.to, next.search, next.hash, searchDefaults);
|
|
1039
|
-
const policy = navigationHrefPolicy(href, typeof window === "undefined" ? undefined : window.location.origin);
|
|
1040
|
-
if (policy === "blocked") {
|
|
1041
|
-
return Promise.reject(new Error("[furin] Unsafe navigation URL."));
|
|
1042
|
-
}
|
|
1043
|
-
if (policy === "external" && typeof window !== "undefined") {
|
|
1044
|
-
window.location.assign(href);
|
|
1045
|
-
return Promise.resolve();
|
|
1046
|
-
}
|
|
1047
|
-
const opts = next.replace === undefined && next.resetScroll === undefined ? undefined : { replace: next.replace, resetScroll: next.resetScroll };
|
|
1048
|
-
return router.navigate(href, opts);
|
|
1049
|
-
}, [router]);
|
|
1135
|
+
return useRouter().navigate;
|
|
1050
1136
|
}
|
|
1051
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
1137
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/utils.mjs
|
|
1052
1138
|
function formatDuration(ms) {
|
|
1053
1139
|
if (ms < 1000)
|
|
1054
1140
|
return `${Math.round(ms)}ms`;
|
|
@@ -1175,7 +1261,7 @@ function isoNow() {
|
|
|
1175
1261
|
return `${_isoCachedPrefix}.${String(now % 1000).padStart(3, "0")}Z`;
|
|
1176
1262
|
}
|
|
1177
1263
|
|
|
1178
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
1264
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/redact-C7FmdhwI.mjs
|
|
1179
1265
|
var DEFAULT_REPLACEMENT = "[REDACTED]";
|
|
1180
1266
|
function normalizeRedactPathPattern(pattern) {
|
|
1181
1267
|
if (!pattern.includes("*") && !pattern.includes("."))
|
|
@@ -1478,7 +1564,7 @@ function applyMaskers(value, maskers) {
|
|
|
1478
1564
|
return result;
|
|
1479
1565
|
}
|
|
1480
1566
|
|
|
1481
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
1567
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/globalRegistry-Bh3bIGwA.mjs
|
|
1482
1568
|
function logPluginError(name, hook, err) {
|
|
1483
1569
|
console.error(`[evlog/${name}] ${hook} failed:`, err);
|
|
1484
1570
|
}
|
|
@@ -1636,7 +1722,7 @@ function getRegistry() {
|
|
|
1636
1722
|
}
|
|
1637
1723
|
var globalConfig = getRegistry().config;
|
|
1638
1724
|
|
|
1639
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
1725
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/pretty-error-D8rlWNL1.mjs
|
|
1640
1726
|
var snippetReader = null;
|
|
1641
1727
|
var PRETTY_ERROR_TREE_SPACER = "__EVLOG_TREE_SPACER__";
|
|
1642
1728
|
function pushTreeSpacer(children) {
|
|
@@ -1937,7 +2023,7 @@ function buildErrorEntries(error, options = {}) {
|
|
|
1937
2023
|
}];
|
|
1938
2024
|
}
|
|
1939
2025
|
|
|
1940
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
2026
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/dev-terminal-Brarc6vc.mjs
|
|
1941
2027
|
var DEV_PRESETS = {
|
|
1942
2028
|
evlog: {
|
|
1943
2029
|
frameworkOverlay: false,
|
|
@@ -1986,7 +2072,7 @@ function resolveDevTerminal(input = {}) {
|
|
|
1986
2072
|
};
|
|
1987
2073
|
}
|
|
1988
2074
|
|
|
1989
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
2075
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/wideEventChannel-BUDW48oP.mjs
|
|
1990
2076
|
var publisher = null;
|
|
1991
2077
|
function publishWideEvent(event) {
|
|
1992
2078
|
if (!publisher)
|
|
@@ -1998,13 +2084,13 @@ function publishWideEvent(event) {
|
|
|
1998
2084
|
}
|
|
1999
2085
|
}
|
|
2000
2086
|
|
|
2001
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
2087
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/error-brand-D0-DCPvr.mjs
|
|
2002
2088
|
var evlogErrorBrand = Symbol.for("evlog.error.brand");
|
|
2003
2089
|
function isEvlogError(error) {
|
|
2004
2090
|
return typeof error === "object" && error !== null && error[evlogErrorBrand] === true;
|
|
2005
2091
|
}
|
|
2006
2092
|
|
|
2007
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
2093
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/error.mjs
|
|
2008
2094
|
var evlogErrorInternalKey = Symbol.for("evlog.error.internal");
|
|
2009
2095
|
var evlogErrorDataKey = Symbol.for("evlog.error.data");
|
|
2010
2096
|
var EvlogError = class EvlogError extends Error {
|
|
@@ -2108,7 +2194,7 @@ Object.defineProperty(EvlogError.prototype, evlogErrorBrand, {
|
|
|
2108
2194
|
enumerable: false
|
|
2109
2195
|
});
|
|
2110
2196
|
|
|
2111
|
-
// ../../node_modules/.bun/evlog@2.29.0+
|
|
2197
|
+
// ../../node_modules/.bun/evlog@2.29.0+e419d84a67dec76a/node_modules/evlog/dist/audit-C8euLMvu.mjs
|
|
2112
2198
|
var nativeStdoutWrite = typeof process !== "undefined" && typeof process.stdout?.write === "function" ? process.stdout.write.bind(process.stdout) : undefined;
|
|
2113
2199
|
function writePrettyStdout(text) {
|
|
2114
2200
|
(globalThis.__evlogNativeStdoutWrite ?? nativeStdoutWrite)?.(text);
|
|
@@ -2782,7 +2868,16 @@ function finalizeAudit(event) {
|
|
|
2782
2868
|
_testCollector?.(decorated, event);
|
|
2783
2869
|
}
|
|
2784
2870
|
// src/client/router/provider.tsx
|
|
2785
|
-
import {
|
|
2871
|
+
import {
|
|
2872
|
+
createElement as createElement6,
|
|
2873
|
+
useCallback as useCallback3,
|
|
2874
|
+
useEffect as useEffect2,
|
|
2875
|
+
useLayoutEffect,
|
|
2876
|
+
useMemo as useMemo2,
|
|
2877
|
+
useRef,
|
|
2878
|
+
useState,
|
|
2879
|
+
useSyncExternalStore as useSyncExternalStore2
|
|
2880
|
+
} from "react";
|
|
2786
2881
|
|
|
2787
2882
|
// ../../node_modules/.bun/seroval@1.6.7/node_modules/seroval/dist/dev/index.js
|
|
2788
2883
|
var SYM_ASYNC_ITERATOR = Symbol.asyncIterator;
|
|
@@ -3838,7 +3933,7 @@ function parseCompactJsonLine(value) {
|
|
|
3838
3933
|
import {
|
|
3839
3934
|
Children,
|
|
3840
3935
|
cloneElement,
|
|
3841
|
-
createElement as
|
|
3936
|
+
createElement as createElement4,
|
|
3842
3937
|
isValidElement,
|
|
3843
3938
|
use
|
|
3844
3939
|
} from "react";
|
|
@@ -3871,7 +3966,7 @@ function decodeFlightBytes(bytes) {
|
|
|
3871
3966
|
}));
|
|
3872
3967
|
}
|
|
3873
3968
|
function createRenderableSource(state) {
|
|
3874
|
-
const element =
|
|
3969
|
+
const element = createElement4(RscNode, { state });
|
|
3875
3970
|
return new Proxy(element, {
|
|
3876
3971
|
get(target, property, receiver) {
|
|
3877
3972
|
if (property === RSC_SOURCE) {
|
|
@@ -3889,6 +3984,50 @@ function restoreRscSource(kind, bytes) {
|
|
|
3889
3984
|
return kind === "renderable" ? createRenderableSource(state) : { [RSC_SOURCE]: state };
|
|
3890
3985
|
}
|
|
3891
3986
|
|
|
3987
|
+
// src/shared/sync-query.ts
|
|
3988
|
+
function mergeQuerySeeds(target, incoming) {
|
|
3989
|
+
for (const seed of incoming) {
|
|
3990
|
+
const index = target.findIndex((existing) => existing.url === seed.url);
|
|
3991
|
+
const previous = target[index];
|
|
3992
|
+
const bindings = [...seed.bindings ?? []];
|
|
3993
|
+
if (previous?.identity.session === seed.identity.session && queryTag(previous.identity) === queryTag(seed.identity)) {
|
|
3994
|
+
for (const binding of previous.bindings ?? []) {
|
|
3995
|
+
if (!bindings.some((next) => JSON.stringify(next.target) === JSON.stringify(binding.target))) {
|
|
3996
|
+
bindings.push(binding);
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
const merged = { ...seed, bindings };
|
|
4001
|
+
if (index < 0) {
|
|
4002
|
+
target.push(merged);
|
|
4003
|
+
} else {
|
|
4004
|
+
target[index] = merged;
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
}
|
|
4008
|
+
var PREFIX = "__furin.query:";
|
|
4009
|
+
function queryTag(identity) {
|
|
4010
|
+
for (const [key, value] of Object.entries(identity.scope)) {
|
|
4011
|
+
if (value === undefined) {
|
|
4012
|
+
throw new Error(`[furin] Query scope "${key}" is undefined for "${identity.id}".`);
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
return PREFIX + JSON.stringify([
|
|
4016
|
+
identity.id,
|
|
4017
|
+
Object.entries(identity.scope).sort(([a], [b]) => {
|
|
4018
|
+
if (a === b) {
|
|
4019
|
+
return 0;
|
|
4020
|
+
}
|
|
4021
|
+
return a < b ? -1 : 1;
|
|
4022
|
+
})
|
|
4023
|
+
]);
|
|
4024
|
+
}
|
|
4025
|
+
function queryUrl(url, origin) {
|
|
4026
|
+
const parsed = new URL(url, origin);
|
|
4027
|
+
parsed.searchParams.sort();
|
|
4028
|
+
return (parsed.origin === origin ? "" : parsed.origin) + parsed.pathname + parsed.search;
|
|
4029
|
+
}
|
|
4030
|
+
|
|
3892
4031
|
// src/shared/route-frame.ts
|
|
3893
4032
|
var FRAME_VERSION = 3;
|
|
3894
4033
|
var MAX_FRAME_BYTES = 1024 * 1024;
|
|
@@ -3999,6 +4138,10 @@ async function parseRouteFrameLines(firstLine, readLine) {
|
|
|
3999
4138
|
const { frame } = envelope;
|
|
4000
4139
|
if (frame.type === "data") {
|
|
4001
4140
|
dataValue = fromCrossJSON(frame.value, {});
|
|
4141
|
+
if (frame.deferredKeys.length > 0 && dataValue && typeof dataValue === "object") {
|
|
4142
|
+
const data = dataValue;
|
|
4143
|
+
data.__furinQueries ??= [];
|
|
4144
|
+
}
|
|
4002
4145
|
for (const key of frame.deferredKeys) {
|
|
4003
4146
|
deferredPromises[key] = new Promise((resolve, reject) => {
|
|
4004
4147
|
resolvers.set(key, { reject, resolve });
|
|
@@ -4033,6 +4176,10 @@ async function parseRouteFrameLines(firstLine, readLine) {
|
|
|
4033
4176
|
} else if (frame.type === "rsc-error") {
|
|
4034
4177
|
throw new Error(`[furin] RSC stream failed (${frame.digest})`);
|
|
4035
4178
|
} else if (frame.type === "defer-resolve") {
|
|
4179
|
+
if (frame.queries && dataValue && typeof dataValue === "object") {
|
|
4180
|
+
const data = dataValue;
|
|
4181
|
+
mergeQuerySeeds(data.__furinQueries ??= [], fromCrossJSON(frame.queries, {}));
|
|
4182
|
+
}
|
|
4036
4183
|
const value = fromCrossJSON(frame.value, {});
|
|
4037
4184
|
const ids = new Set;
|
|
4038
4185
|
collectRscDescriptorIds(value, ids);
|
|
@@ -4284,6 +4431,87 @@ async function readDeferredLines(readLine, resolvers) {
|
|
|
4284
4431
|
}
|
|
4285
4432
|
}
|
|
4286
4433
|
|
|
4434
|
+
// src/shared/query-bindings.ts
|
|
4435
|
+
function isContainer(value) {
|
|
4436
|
+
if (!value || typeof value !== "object") {
|
|
4437
|
+
return false;
|
|
4438
|
+
}
|
|
4439
|
+
const prototype = Object.getPrototypeOf(value);
|
|
4440
|
+
return Array.isArray(value) || prototype === Object.prototype || prototype === null;
|
|
4441
|
+
}
|
|
4442
|
+
function replace(value, path, next) {
|
|
4443
|
+
const [key, ...rest] = path;
|
|
4444
|
+
if (key === undefined) {
|
|
4445
|
+
return next;
|
|
4446
|
+
}
|
|
4447
|
+
if (!(isContainer(value) && Object.hasOwn(value, key))) {
|
|
4448
|
+
return value;
|
|
4449
|
+
}
|
|
4450
|
+
const child = replace(value[key], rest, next);
|
|
4451
|
+
if (child === value[key]) {
|
|
4452
|
+
return value;
|
|
4453
|
+
}
|
|
4454
|
+
const copy = Array.isArray(value) ? [...value] : { ...value };
|
|
4455
|
+
Object.defineProperty(copy, key, {
|
|
4456
|
+
configurable: true,
|
|
4457
|
+
enumerable: true,
|
|
4458
|
+
value: child,
|
|
4459
|
+
writable: true
|
|
4460
|
+
});
|
|
4461
|
+
return copy;
|
|
4462
|
+
}
|
|
4463
|
+
function isDeferredTarget(data, target) {
|
|
4464
|
+
const [key] = target;
|
|
4465
|
+
return key !== undefined && isContainer(data) && data[key] instanceof Promise;
|
|
4466
|
+
}
|
|
4467
|
+
function projectQueryData(data, seeds, read) {
|
|
4468
|
+
let projected = data;
|
|
4469
|
+
for (const seed of seeds) {
|
|
4470
|
+
const snapshot = read(seed);
|
|
4471
|
+
if (snapshot === undefined) {
|
|
4472
|
+
continue;
|
|
4473
|
+
}
|
|
4474
|
+
for (const binding of seed.bindings ?? []) {
|
|
4475
|
+
if (isDeferredTarget(data, binding.target)) {
|
|
4476
|
+
continue;
|
|
4477
|
+
}
|
|
4478
|
+
let value = snapshot;
|
|
4479
|
+
for (const key of binding.source) {
|
|
4480
|
+
value = isContainer(value) && Object.hasOwn(value, key) ? value[key] : undefined;
|
|
4481
|
+
}
|
|
4482
|
+
projected = replace(projected, binding.target, value);
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
return projected;
|
|
4486
|
+
}
|
|
4487
|
+
function projectDeferredQueryData(data, seeds, read, resolved) {
|
|
4488
|
+
let base = data;
|
|
4489
|
+
const deferred = new Map;
|
|
4490
|
+
for (const [key, promise] of Object.entries(data)) {
|
|
4491
|
+
if (!(promise instanceof Promise)) {
|
|
4492
|
+
continue;
|
|
4493
|
+
}
|
|
4494
|
+
const state = resolved.get(promise);
|
|
4495
|
+
if (state) {
|
|
4496
|
+
deferred.set(key, { promise, state });
|
|
4497
|
+
base = replace(base, [key], state.value);
|
|
4498
|
+
}
|
|
4499
|
+
}
|
|
4500
|
+
let projected = projectQueryData(base, seeds, read);
|
|
4501
|
+
for (const [key, { promise, state }] of deferred) {
|
|
4502
|
+
const value = isContainer(projected) ? projected[key] : undefined;
|
|
4503
|
+
if (value === state.value) {
|
|
4504
|
+
projected = replace(projected, [key], promise);
|
|
4505
|
+
continue;
|
|
4506
|
+
}
|
|
4507
|
+
if (!state.projection || state.projection.value !== value) {
|
|
4508
|
+
state.projection = { value, promise: Promise.resolve(value) };
|
|
4509
|
+
}
|
|
4510
|
+
projected = replace(projected, [key], state.projection.promise);
|
|
4511
|
+
}
|
|
4512
|
+
return projected;
|
|
4513
|
+
}
|
|
4514
|
+
|
|
4287
4515
|
// src/client/browser-events.ts
|
|
4288
4516
|
var BROWSER_EVENT_RUNTIME_KEY = Symbol.for("furin.browser-events.runtime");
|
|
4289
4517
|
function subscribeBrowserEvent(channel, listener) {
|
|
@@ -4291,15 +4519,425 @@ function subscribeBrowserEvent(channel, listener) {
|
|
|
4291
4519
|
return runtime?.subscribe(channel, listener);
|
|
4292
4520
|
}
|
|
4293
4521
|
|
|
4522
|
+
// src/client/query.tsx
|
|
4523
|
+
import {
|
|
4524
|
+
createContext as createContext4,
|
|
4525
|
+
useCallback as useCallback2,
|
|
4526
|
+
useContext as useContext4,
|
|
4527
|
+
useEffect,
|
|
4528
|
+
useSyncExternalStore
|
|
4529
|
+
} from "react";
|
|
4530
|
+
|
|
4531
|
+
// src/client/query-store.ts
|
|
4532
|
+
var QUERY_REFERENCE = Symbol.for("furin.query.reference.v1");
|
|
4533
|
+
var SERVER_ENVIRONMENT = Symbol.for("furin.query.environment.v1");
|
|
4534
|
+
class QueryStore {
|
|
4535
|
+
entries = new Map;
|
|
4536
|
+
listeners = new Set;
|
|
4537
|
+
revisionValue = 0;
|
|
4538
|
+
projections = new Set;
|
|
4539
|
+
session;
|
|
4540
|
+
epoch = 0;
|
|
4541
|
+
origin;
|
|
4542
|
+
constructor(origin) {
|
|
4543
|
+
this.origin = origin;
|
|
4544
|
+
}
|
|
4545
|
+
key(url) {
|
|
4546
|
+
const absolute = new URL(url, this.origin).href;
|
|
4547
|
+
return queryUrl(absolute, undefined);
|
|
4548
|
+
}
|
|
4549
|
+
entry(url) {
|
|
4550
|
+
const key = this.key(url);
|
|
4551
|
+
let entry = this.entries.get(key);
|
|
4552
|
+
if (!entry) {
|
|
4553
|
+
entry = {
|
|
4554
|
+
base: undefined,
|
|
4555
|
+
listeners: new Set,
|
|
4556
|
+
snapshot: { data: undefined, error: null, isFetching: false },
|
|
4557
|
+
stale: true,
|
|
4558
|
+
version: 0
|
|
4559
|
+
};
|
|
4560
|
+
this.entries.set(key, entry);
|
|
4561
|
+
}
|
|
4562
|
+
return entry;
|
|
4563
|
+
}
|
|
4564
|
+
publish(entry) {
|
|
4565
|
+
let data = entry.base;
|
|
4566
|
+
for (const projection of this.projections) {
|
|
4567
|
+
const transform = projection.transforms.get(entry);
|
|
4568
|
+
if (transform && data !== undefined) {
|
|
4569
|
+
data = transform(data);
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
entry.snapshot = { ...entry.snapshot, data };
|
|
4573
|
+
for (const listener of entry.listeners) {
|
|
4574
|
+
listener();
|
|
4575
|
+
}
|
|
4576
|
+
this.revisionValue += 1;
|
|
4577
|
+
for (const listener of this.listeners) {
|
|
4578
|
+
listener();
|
|
4579
|
+
}
|
|
4580
|
+
}
|
|
4581
|
+
revision = () => this.revisionValue;
|
|
4582
|
+
subscribeAll = (listener) => {
|
|
4583
|
+
this.listeners.add(listener);
|
|
4584
|
+
return () => this.listeners.delete(listener);
|
|
4585
|
+
};
|
|
4586
|
+
observe(url, result, epoch, version) {
|
|
4587
|
+
const existing = this.entries.get(this.key(url));
|
|
4588
|
+
if (epoch !== this.epoch || result.error !== null || existing && (this.pending(existing) || version !== undefined && existing.version !== version)) {
|
|
4589
|
+
return;
|
|
4590
|
+
}
|
|
4591
|
+
const header = result.response?.headers.get("x-furin-query");
|
|
4592
|
+
const identity = result.identity ?? (header ? JSON.parse(header) : undefined);
|
|
4593
|
+
if (identity) {
|
|
4594
|
+
this.setSession(identity.session);
|
|
4595
|
+
}
|
|
4596
|
+
const entry = this.entry(url);
|
|
4597
|
+
entry.base = result.data;
|
|
4598
|
+
entry.version += 1;
|
|
4599
|
+
entry.identity = identity;
|
|
4600
|
+
entry.local = result.local ?? result.response?.url === "";
|
|
4601
|
+
entry.stale = false;
|
|
4602
|
+
entry.snapshot = { data: result.data, error: null, isFetching: false };
|
|
4603
|
+
for (const projection of this.projections) {
|
|
4604
|
+
if (!projection.pending) {
|
|
4605
|
+
projection.transforms.delete(entry);
|
|
4606
|
+
if (projection.transforms.size === 0) {
|
|
4607
|
+
this.projections.delete(projection);
|
|
4608
|
+
projection.onRemove?.();
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
}
|
|
4612
|
+
this.publish(entry);
|
|
4613
|
+
if (this.entries.size > 100) {
|
|
4614
|
+
const oldest = [...this.entries].find(([, item]) => item !== entry && item.listeners.size === 0 && !item.promise && !this.pending(item));
|
|
4615
|
+
if (oldest) {
|
|
4616
|
+
this.entries.delete(oldest[0]);
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
setSession(session) {
|
|
4621
|
+
if (this.session !== undefined && this.session !== session) {
|
|
4622
|
+
this.epoch += 1;
|
|
4623
|
+
for (const projection of this.projections) {
|
|
4624
|
+
projection.onRemove?.();
|
|
4625
|
+
}
|
|
4626
|
+
this.projections.clear();
|
|
4627
|
+
for (const entry of this.entries.values()) {
|
|
4628
|
+
entry.base = undefined;
|
|
4629
|
+
entry.identity = undefined;
|
|
4630
|
+
entry.stale = true;
|
|
4631
|
+
entry.version += 1;
|
|
4632
|
+
entry.snapshot = { data: undefined, error: null, isFetching: false };
|
|
4633
|
+
this.publish(entry);
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
this.session = session;
|
|
4637
|
+
}
|
|
4638
|
+
generation() {
|
|
4639
|
+
return this.epoch;
|
|
4640
|
+
}
|
|
4641
|
+
version(url) {
|
|
4642
|
+
return this.entry(url).version;
|
|
4643
|
+
}
|
|
4644
|
+
snapshot(url) {
|
|
4645
|
+
return this.entry(url).snapshot;
|
|
4646
|
+
}
|
|
4647
|
+
subscribe(url, listener) {
|
|
4648
|
+
const entry = this.entry(url);
|
|
4649
|
+
entry.listeners.add(listener);
|
|
4650
|
+
return () => entry.listeners.delete(listener);
|
|
4651
|
+
}
|
|
4652
|
+
bind(url, load, client) {
|
|
4653
|
+
const entry = this.entry(url);
|
|
4654
|
+
if (client && entry.client && client !== entry.client) {
|
|
4655
|
+
entry.base = undefined;
|
|
4656
|
+
entry.identity = undefined;
|
|
4657
|
+
entry.stale = true;
|
|
4658
|
+
entry.version += 1;
|
|
4659
|
+
entry.snapshot = { data: undefined, error: null, isFetching: false };
|
|
4660
|
+
for (const projection of this.projections) {
|
|
4661
|
+
projection.transforms.delete(entry);
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
entry.client = client ?? entry.client;
|
|
4665
|
+
entry.load = load;
|
|
4666
|
+
}
|
|
4667
|
+
pending(entry) {
|
|
4668
|
+
return [...this.projections].some((projection) => projection.pending && projection.transforms.has(entry));
|
|
4669
|
+
}
|
|
4670
|
+
fetch(url) {
|
|
4671
|
+
const entry = this.entry(url);
|
|
4672
|
+
if (entry.promise) {
|
|
4673
|
+
return entry.promise;
|
|
4674
|
+
}
|
|
4675
|
+
if (!(entry.stale && entry.load) || this.pending(entry)) {
|
|
4676
|
+
return Promise.resolve();
|
|
4677
|
+
}
|
|
4678
|
+
const { version } = entry;
|
|
4679
|
+
const { epoch } = this;
|
|
4680
|
+
entry.snapshot = { ...entry.snapshot, isFetching: true };
|
|
4681
|
+
this.publish(entry);
|
|
4682
|
+
entry.promise = Promise.resolve().then(() => entry.load?.()).then((result) => {
|
|
4683
|
+
if (!result || epoch !== this.epoch || version !== entry.version || this.pending(entry)) {
|
|
4684
|
+
return;
|
|
4685
|
+
}
|
|
4686
|
+
if (result.error === null) {
|
|
4687
|
+
this.observe(url, result, epoch);
|
|
4688
|
+
} else {
|
|
4689
|
+
entry.snapshot = { ...entry.snapshot, error: result.error };
|
|
4690
|
+
}
|
|
4691
|
+
}).catch((error) => {
|
|
4692
|
+
if (epoch === this.epoch && version === entry.version) {
|
|
4693
|
+
entry.snapshot = { ...entry.snapshot, error };
|
|
4694
|
+
}
|
|
4695
|
+
}).finally(() => {
|
|
4696
|
+
entry.promise = undefined;
|
|
4697
|
+
entry.snapshot = { ...entry.snapshot, isFetching: false };
|
|
4698
|
+
this.publish(entry);
|
|
4699
|
+
if (entry.stale && version !== entry.version && entry.listeners.size > 0) {
|
|
4700
|
+
this.fetch(url);
|
|
4701
|
+
}
|
|
4702
|
+
});
|
|
4703
|
+
return entry.promise;
|
|
4704
|
+
}
|
|
4705
|
+
invalidate(identities) {
|
|
4706
|
+
const tags = new Set(identities.map(queryTag));
|
|
4707
|
+
let affected = false;
|
|
4708
|
+
for (const [url, entry] of this.entries) {
|
|
4709
|
+
if (entry.identity && tags.has(queryTag(entry.identity))) {
|
|
4710
|
+
affected = true;
|
|
4711
|
+
this.invalidateEntry(url, entry);
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
return affected;
|
|
4715
|
+
}
|
|
4716
|
+
invalidateEntry(url, entry) {
|
|
4717
|
+
entry.stale = true;
|
|
4718
|
+
entry.version += 1;
|
|
4719
|
+
if (entry.listeners.size > 0) {
|
|
4720
|
+
this.fetch(url);
|
|
4721
|
+
}
|
|
4722
|
+
}
|
|
4723
|
+
invalidateAll() {
|
|
4724
|
+
for (const [url, entry] of this.entries) {
|
|
4725
|
+
this.invalidateEntry(url, entry);
|
|
4726
|
+
}
|
|
4727
|
+
}
|
|
4728
|
+
begin() {
|
|
4729
|
+
return { pending: true, transforms: new Map };
|
|
4730
|
+
}
|
|
4731
|
+
update(projection, url, transform) {
|
|
4732
|
+
const entry = this.entries.get(this.key(url));
|
|
4733
|
+
if (!entry || entry.base === undefined) {
|
|
4734
|
+
return;
|
|
4735
|
+
}
|
|
4736
|
+
const previous = projection.transforms.get(entry);
|
|
4737
|
+
projection.transforms.set(entry, previous ? (data) => transform(previous(data)) : transform);
|
|
4738
|
+
entry.version += 1;
|
|
4739
|
+
this.projections.add(projection);
|
|
4740
|
+
this.publish(entry);
|
|
4741
|
+
}
|
|
4742
|
+
finish(projection, outcome) {
|
|
4743
|
+
projection.pending = false;
|
|
4744
|
+
const entries = [...projection.transforms.keys()];
|
|
4745
|
+
if (outcome === "error") {
|
|
4746
|
+
this.projections.delete(projection);
|
|
4747
|
+
projection.onRemove?.();
|
|
4748
|
+
}
|
|
4749
|
+
for (const entry of entries) {
|
|
4750
|
+
this.publish(entry);
|
|
4751
|
+
if (outcome !== "error") {
|
|
4752
|
+
entry.stale = true;
|
|
4753
|
+
}
|
|
4754
|
+
const url = [...this.entries].find(([, candidate]) => candidate === entry)?.[0];
|
|
4755
|
+
if (url && entry.stale) {
|
|
4756
|
+
this.fetch(url);
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
}
|
|
4760
|
+
dehydrate() {
|
|
4761
|
+
return [...this.entries].flatMap(([url, entry]) => entry.identity && entry.base !== undefined ? [{ url, data: entry.base, identity: entry.identity, local: entry.local }] : []);
|
|
4762
|
+
}
|
|
4763
|
+
seedUrl(seed, localOrigin) {
|
|
4764
|
+
const original = new URL(seed.url, this.origin);
|
|
4765
|
+
return seed.local && localOrigin ? new URL(original.pathname + original.search, localOrigin).href : original.href;
|
|
4766
|
+
}
|
|
4767
|
+
captureHydration() {
|
|
4768
|
+
const { epoch } = this;
|
|
4769
|
+
const versions = new Map([...this.entries].map(([key, entry]) => [key, entry.version]));
|
|
4770
|
+
return (seeds, localOrigin) => {
|
|
4771
|
+
if (epoch === this.epoch) {
|
|
4772
|
+
this.hydrate(seeds.filter((seed) => {
|
|
4773
|
+
const url = this.seedUrl(seed, localOrigin);
|
|
4774
|
+
return this.version(url) === (versions.get(this.key(url)) ?? 0);
|
|
4775
|
+
}), localOrigin);
|
|
4776
|
+
}
|
|
4777
|
+
};
|
|
4778
|
+
}
|
|
4779
|
+
hydrate(seeds, localOrigin) {
|
|
4780
|
+
for (const seed of seeds) {
|
|
4781
|
+
const url = this.seedUrl(seed, localOrigin);
|
|
4782
|
+
this.observe(url, {
|
|
4783
|
+
data: seed.data,
|
|
4784
|
+
error: null,
|
|
4785
|
+
identity: seed.identity,
|
|
4786
|
+
local: seed.local ?? false
|
|
4787
|
+
}, this.epoch);
|
|
4788
|
+
}
|
|
4789
|
+
}
|
|
4790
|
+
}
|
|
4791
|
+
|
|
4792
|
+
// src/client/query.tsx
|
|
4793
|
+
var QUERY_CONTEXT = Symbol.for("furin.query.context.v1");
|
|
4794
|
+
var contextGlobal2 = globalThis;
|
|
4795
|
+
var QueryStoreContext = contextGlobal2[QUERY_CONTEXT] ??= createContext4(null);
|
|
4796
|
+
|
|
4294
4797
|
// src/client/router/abort.ts
|
|
4295
4798
|
function isAbortError(error) {
|
|
4296
4799
|
return error !== null && typeof error === "object" && "name" in error && error.name === "AbortError";
|
|
4297
4800
|
}
|
|
4298
4801
|
|
|
4802
|
+
// src/client/router/optimistic.ts
|
|
4803
|
+
var SYNC_REQUEST = Symbol.for("furin.sync.request.v1");
|
|
4804
|
+
function identity(href) {
|
|
4805
|
+
const url = new URL(href, "http://furin.local");
|
|
4806
|
+
url.searchParams.sort();
|
|
4807
|
+
return url.pathname + url.search;
|
|
4808
|
+
}
|
|
4809
|
+
var RUNTIMES = Symbol.for("furin.optimistic.runtimes.v1");
|
|
4810
|
+
var runtimeGlobal = globalThis;
|
|
4811
|
+
var runtimes = runtimeGlobal[RUNTIMES] ??= new Set;
|
|
4812
|
+
function registerOptimisticRuntime(runtime) {
|
|
4813
|
+
runtimes.add(runtime);
|
|
4814
|
+
return () => {
|
|
4815
|
+
runtimes.delete(runtime);
|
|
4816
|
+
};
|
|
4817
|
+
}
|
|
4818
|
+
function createOptimisticRuntime(options) {
|
|
4819
|
+
const operations = new Set;
|
|
4820
|
+
const listeners = new Set;
|
|
4821
|
+
const revisions = new Map;
|
|
4822
|
+
let version = 0;
|
|
4823
|
+
const notify = (operation) => {
|
|
4824
|
+
version += 1;
|
|
4825
|
+
for (const { href } of operation.transforms) {
|
|
4826
|
+
revisions.set(href, (revisions.get(href) ?? 0) + 1);
|
|
4827
|
+
}
|
|
4828
|
+
if (operation.queryHref) {
|
|
4829
|
+
revisions.set(operation.queryHref, (revisions.get(operation.queryHref) ?? 0) + 1);
|
|
4830
|
+
}
|
|
4831
|
+
for (const listener of listeners) {
|
|
4832
|
+
listener();
|
|
4833
|
+
}
|
|
4834
|
+
};
|
|
4835
|
+
const pending = (href) => [...operations].some((operation) => operation.pending && (operation.queryHref === identity(href) || operation.transforms.some((transform) => transform.href === identity(href))));
|
|
4836
|
+
return {
|
|
4837
|
+
basePath: options.basePath,
|
|
4838
|
+
queries: options.queries,
|
|
4839
|
+
begin(optimistic, onRemove, hasQueries) {
|
|
4840
|
+
const operation = { onRemove, pending: true, transforms: [] };
|
|
4841
|
+
const cache = {
|
|
4842
|
+
update(target, transform) {
|
|
4843
|
+
const snapshot = options.snapshot();
|
|
4844
|
+
const path = typeof target === "string" ? target : buildHref(target.path, target.search, undefined);
|
|
4845
|
+
const href = identity(typeof target === "string" && target === snapshot.pattern ? snapshot.href : path);
|
|
4846
|
+
if (snapshot.loaded && href === identity(snapshot.href)) {
|
|
4847
|
+
operation.transforms.push({ href, transform });
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4850
|
+
};
|
|
4851
|
+
optimistic?.(cache);
|
|
4852
|
+
if (hasQueries?.() && options.snapshot().loaded) {
|
|
4853
|
+
operation.queryHref = identity(options.snapshot().href);
|
|
4854
|
+
}
|
|
4855
|
+
if (operation.transforms.length > 0 || operation.queryHref !== undefined) {
|
|
4856
|
+
operations.add(operation);
|
|
4857
|
+
notify(operation);
|
|
4858
|
+
}
|
|
4859
|
+
return operation;
|
|
4860
|
+
},
|
|
4861
|
+
commit(href) {
|
|
4862
|
+
for (const operation of operations) {
|
|
4863
|
+
if (!operation.pending) {
|
|
4864
|
+
if (operation.queryHref === identity(href)) {
|
|
4865
|
+
operation.queryHref = undefined;
|
|
4866
|
+
}
|
|
4867
|
+
operation.transforms = operation.transforms.filter((transform) => transform.href !== identity(href));
|
|
4868
|
+
if (operation.transforms.length === 0 && operation.queryHref === undefined) {
|
|
4869
|
+
operations.delete(operation);
|
|
4870
|
+
operation.onRemove?.();
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
}
|
|
4874
|
+
},
|
|
4875
|
+
finish(operation, outcome, response) {
|
|
4876
|
+
operation.pending = false;
|
|
4877
|
+
if (outcome === "error") {
|
|
4878
|
+
operations.delete(operation);
|
|
4879
|
+
}
|
|
4880
|
+
if (outcome === "error" || operation.transforms.length === 0 && operation.queryHref === undefined) {
|
|
4881
|
+
operation.onRemove?.();
|
|
4882
|
+
}
|
|
4883
|
+
if (operation.transforms.length > 0 || operation.queryHref !== undefined) {
|
|
4884
|
+
notify(operation);
|
|
4885
|
+
}
|
|
4886
|
+
options.onResponse(response, outcome !== "error" && (operation.transforms.length > 0 || operation.queryHref !== undefined));
|
|
4887
|
+
},
|
|
4888
|
+
has: (href) => [...operations].some((operation) => operation.queryHref === identity(href) || operation.transforms.some((transform) => transform.href === identity(href))),
|
|
4889
|
+
project(data, href) {
|
|
4890
|
+
let projected = data;
|
|
4891
|
+
for (const operation of operations) {
|
|
4892
|
+
for (const transformation of operation.transforms) {
|
|
4893
|
+
if (transformation.href === identity(href)) {
|
|
4894
|
+
projected = { ...projected, ...transformation.transform(projected) };
|
|
4895
|
+
}
|
|
4896
|
+
}
|
|
4897
|
+
}
|
|
4898
|
+
return projected;
|
|
4899
|
+
},
|
|
4900
|
+
publishable: (href, revision) => !pending(href) && (revisions.get(identity(href)) ?? 0) === revision,
|
|
4901
|
+
revision: (href) => href === undefined ? version : revisions.get(identity(href)) ?? 0,
|
|
4902
|
+
subscribe(listener) {
|
|
4903
|
+
listeners.add(listener);
|
|
4904
|
+
return () => {
|
|
4905
|
+
listeners.delete(listener);
|
|
4906
|
+
};
|
|
4907
|
+
},
|
|
4908
|
+
wait(href, signal) {
|
|
4909
|
+
if (signal?.aborted) {
|
|
4910
|
+
return Promise.reject(signal.reason);
|
|
4911
|
+
}
|
|
4912
|
+
if (!pending(href)) {
|
|
4913
|
+
return Promise.resolve();
|
|
4914
|
+
}
|
|
4915
|
+
return new Promise((resolve, reject) => {
|
|
4916
|
+
const cleanup = () => {
|
|
4917
|
+
listeners.delete(check);
|
|
4918
|
+
signal?.removeEventListener("abort", abort);
|
|
4919
|
+
};
|
|
4920
|
+
const abort = () => {
|
|
4921
|
+
cleanup();
|
|
4922
|
+
reject(signal?.reason);
|
|
4923
|
+
};
|
|
4924
|
+
const check = () => {
|
|
4925
|
+
if (!pending(href)) {
|
|
4926
|
+
cleanup();
|
|
4927
|
+
resolve();
|
|
4928
|
+
}
|
|
4929
|
+
};
|
|
4930
|
+
listeners.add(check);
|
|
4931
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
4932
|
+
});
|
|
4933
|
+
}
|
|
4934
|
+
};
|
|
4935
|
+
}
|
|
4936
|
+
|
|
4299
4937
|
// src/client/router/search-store.ts
|
|
4300
|
-
import { createContext as
|
|
4938
|
+
import { createContext as createContext5 } from "react";
|
|
4301
4939
|
function searchSnapshotChanged(a, b) {
|
|
4302
|
-
return a.currentHref !== b.currentHref || a.navigate !== b.navigate || a.search !== b.search || a.searchRoutes !== b.searchRoutes;
|
|
4940
|
+
return a.currentHref !== b.currentHref || a.currentPattern !== b.currentPattern || a.navigate !== b.navigate || a.search !== b.search || a.searchRoutes !== b.searchRoutes;
|
|
4303
4941
|
}
|
|
4304
4942
|
function createSearchStore(initialSnapshot) {
|
|
4305
4943
|
let snapshot = initialSnapshot;
|
|
@@ -4336,6 +4974,7 @@ function createSearchStore(initialSnapshot) {
|
|
|
4336
4974
|
function searchSnapshotFromRouterContext(context) {
|
|
4337
4975
|
return {
|
|
4338
4976
|
currentHref: context.currentHref,
|
|
4977
|
+
currentPattern: context.currentPattern,
|
|
4339
4978
|
navigate: context.navigate,
|
|
4340
4979
|
search: context.search,
|
|
4341
4980
|
searchRoutes: context.searchRoutes
|
|
@@ -4343,6 +4982,7 @@ function searchSnapshotFromRouterContext(context) {
|
|
|
4343
4982
|
}
|
|
4344
4983
|
var FALLBACK_SEARCH_STORE = createSearchStore({
|
|
4345
4984
|
currentHref: "/",
|
|
4985
|
+
currentPattern: undefined,
|
|
4346
4986
|
navigate: (href, _opts) => {
|
|
4347
4987
|
if (typeof window !== "undefined") {
|
|
4348
4988
|
if (navigationHrefPolicy(href, window.location.origin) === "blocked") {
|
|
@@ -4355,10 +4995,10 @@ var FALLBACK_SEARCH_STORE = createSearchStore({
|
|
|
4355
4995
|
search: {},
|
|
4356
4996
|
searchRoutes: []
|
|
4357
4997
|
});
|
|
4358
|
-
var SearchStoreContext =
|
|
4998
|
+
var SearchStoreContext = createContext5(null);
|
|
4359
4999
|
|
|
4360
5000
|
// src/client/router/spa-response.ts
|
|
4361
|
-
import { createElement as
|
|
5001
|
+
import { createElement as createElement5 } from "react";
|
|
4362
5002
|
function isFurinErrorPayload(value) {
|
|
4363
5003
|
if (!value || typeof value !== "object") {
|
|
4364
5004
|
return false;
|
|
@@ -4393,10 +5033,10 @@ function pickDeepestNotFound(boundaries) {
|
|
|
4393
5033
|
}
|
|
4394
5034
|
}
|
|
4395
5035
|
}
|
|
4396
|
-
var DefaultClientNotFoundFallback = ({ error }) =>
|
|
5036
|
+
var DefaultClientNotFoundFallback = ({ error }) => createElement5(DefaultNotFoundScreen, { message: error.message });
|
|
4397
5037
|
function buildNotFoundPageElement(boundaries, error) {
|
|
4398
5038
|
const Fallback = pickDeepestNotFound(boundaries) ?? DefaultClientNotFoundFallback;
|
|
4399
|
-
return
|
|
5039
|
+
return createElement5(Fallback, { error });
|
|
4400
5040
|
}
|
|
4401
5041
|
async function parsePageResponse(res, basePath) {
|
|
4402
5042
|
let finalHref;
|
|
@@ -4469,12 +5109,16 @@ function createSyncCatchUp(options) {
|
|
|
4469
5109
|
do {
|
|
4470
5110
|
page = await options.fetchPage(currentCursor ?? "0");
|
|
4471
5111
|
if (page.reset) {
|
|
5112
|
+
options.onReset?.();
|
|
4472
5113
|
options.onInvalidations(["/:layout"]);
|
|
4473
5114
|
currentCursor = page.cursor;
|
|
4474
5115
|
break;
|
|
4475
5116
|
}
|
|
4476
5117
|
for (const change of page.changes) {
|
|
4477
5118
|
options.onInvalidations(change.invalidations);
|
|
5119
|
+
if (change.queries) {
|
|
5120
|
+
options.onQueries?.(change.queries);
|
|
5121
|
+
}
|
|
4478
5122
|
}
|
|
4479
5123
|
currentCursor = page.cursor;
|
|
4480
5124
|
} while (page.hasMore);
|
|
@@ -4500,6 +5144,9 @@ function createSyncCatchUp(options) {
|
|
|
4500
5144
|
// src/client/router/provider.tsx
|
|
4501
5145
|
import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
|
|
4502
5146
|
var EMPTY_SEARCH = {};
|
|
5147
|
+
function isRedirectState(state) {
|
|
5148
|
+
return Boolean(state?.finalHref && !state.match && !state.notFound);
|
|
5149
|
+
}
|
|
4503
5150
|
function getHistoryStateObject() {
|
|
4504
5151
|
const value = history.state;
|
|
4505
5152
|
return value !== null && typeof value === "object" ? value : {};
|
|
@@ -4553,8 +5200,15 @@ function RouterProvider({
|
|
|
4553
5200
|
syncPath
|
|
4554
5201
|
}) {
|
|
4555
5202
|
const initialDocumentState = useDocumentState();
|
|
5203
|
+
const [queries] = useState(() => {
|
|
5204
|
+
const store = new QueryStore(typeof window === "undefined" ? undefined : window.location.origin);
|
|
5205
|
+
store.hydrate(initialData.__furinQueries ?? [], typeof window === "undefined" ? undefined : window.location.origin);
|
|
5206
|
+
return store;
|
|
5207
|
+
});
|
|
4556
5208
|
const [state, setState] = useState(() => ({
|
|
4557
|
-
data: initialData,
|
|
5209
|
+
data: Object.fromEntries(Object.entries(initialData).filter(([key]) => key !== "__furinQueries")),
|
|
5210
|
+
querySeeds: initialData.__furinQueries,
|
|
5211
|
+
hydrateQueries: queries.captureHydration(),
|
|
4558
5212
|
error: initialError ? {
|
|
4559
5213
|
...initialError,
|
|
4560
5214
|
message: initialError.message || "Something went wrong"
|
|
@@ -4564,6 +5218,42 @@ function RouterProvider({
|
|
|
4564
5218
|
notFound: initialNotFound
|
|
4565
5219
|
}));
|
|
4566
5220
|
const [boundaryResetVersion, setBoundaryResetVersion] = useState(0);
|
|
5221
|
+
const currentState = useRef(state);
|
|
5222
|
+
useLayoutEffect(() => {
|
|
5223
|
+
currentState.current = state;
|
|
5224
|
+
}, [state]);
|
|
5225
|
+
useLayoutEffect(() => {
|
|
5226
|
+
state.hydrateQueries?.(state.querySeeds ?? [], typeof window === "undefined" ? undefined : window.location.origin);
|
|
5227
|
+
}, [state.hydrateQueries, state.querySeeds]);
|
|
5228
|
+
const resolvedQueries = useRef(new WeakMap);
|
|
5229
|
+
const [deferredRevision, setDeferredRevision] = useState(0);
|
|
5230
|
+
useEffect2(() => {
|
|
5231
|
+
const snapshot = currentState.current;
|
|
5232
|
+
const hydrated = new Set(snapshot.querySeeds?.map((seed) => seed.url));
|
|
5233
|
+
let disposed = false;
|
|
5234
|
+
for (const promise of Object.values(state.data)) {
|
|
5235
|
+
if (!(promise instanceof Promise)) {
|
|
5236
|
+
continue;
|
|
5237
|
+
}
|
|
5238
|
+
promise.then((value) => {
|
|
5239
|
+
if (disposed) {
|
|
5240
|
+
return;
|
|
5241
|
+
}
|
|
5242
|
+
resolvedQueries.current.set(promise, { value });
|
|
5243
|
+
const seeds = (snapshot.querySeeds ?? []).filter((seed) => !hydrated.has(seed.url));
|
|
5244
|
+
snapshot.hydrateQueries?.(seeds, window.location.origin);
|
|
5245
|
+
for (const seed of seeds) {
|
|
5246
|
+
hydrated.add(seed.url);
|
|
5247
|
+
}
|
|
5248
|
+
setDeferredRevision((revision) => revision + 1);
|
|
5249
|
+
}, () => {
|
|
5250
|
+
return;
|
|
5251
|
+
});
|
|
5252
|
+
}
|
|
5253
|
+
return () => {
|
|
5254
|
+
disposed = true;
|
|
5255
|
+
};
|
|
5256
|
+
}, [queries, state.data]);
|
|
4567
5257
|
const [isNavigating, setIsNavigating] = useState(false);
|
|
4568
5258
|
const [currentHref, setCurrentHref] = useState(() => {
|
|
4569
5259
|
if (typeof window === "undefined") {
|
|
@@ -4571,6 +5261,29 @@ function RouterProvider({
|
|
|
4571
5261
|
}
|
|
4572
5262
|
return normalizeHref(toLogical(window.location.pathname, basePath)) + window.location.search;
|
|
4573
5263
|
});
|
|
5264
|
+
const optimisticSnapshot = useRef({
|
|
5265
|
+
href: currentHref,
|
|
5266
|
+
loaded: state.match !== null,
|
|
5267
|
+
pattern: state.match?.pattern
|
|
5268
|
+
});
|
|
5269
|
+
useLayoutEffect(() => {
|
|
5270
|
+
optimisticSnapshot.current = {
|
|
5271
|
+
href: currentHref,
|
|
5272
|
+
loaded: state.match !== null && !(state.error || state.notFound),
|
|
5273
|
+
pattern: state.match?.pattern
|
|
5274
|
+
};
|
|
5275
|
+
}, [currentHref, state.match, state.error, state.notFound]);
|
|
5276
|
+
const syncResponse = useRef(undefined);
|
|
5277
|
+
const [optimisticRuntime] = useState(() => createOptimisticRuntime({
|
|
5278
|
+
basePath,
|
|
5279
|
+
queries,
|
|
5280
|
+
snapshot: () => optimisticSnapshot.current,
|
|
5281
|
+
onResponse: (response, optimistic) => syncResponse.current?.(response, optimistic)
|
|
5282
|
+
}));
|
|
5283
|
+
useSyncExternalStore2(optimisticRuntime.subscribe, optimisticRuntime.revision, () => 0);
|
|
5284
|
+
const queryRevision = useSyncExternalStore2(queries.subscribeAll, queries.revision, () => 0);
|
|
5285
|
+
useEffect2(() => registerOptimisticRuntime(optimisticRuntime), [optimisticRuntime]);
|
|
5286
|
+
const snapshotVersions = useRef(new WeakMap);
|
|
4574
5287
|
const prefetchCache = useRef(new Map);
|
|
4575
5288
|
const navVersion = useRef(0);
|
|
4576
5289
|
const hmrVersion = useRef(0);
|
|
@@ -4578,10 +5291,11 @@ function RouterProvider({
|
|
|
4578
5291
|
const pendingUserNavigation = useRef(null);
|
|
4579
5292
|
const navAbortRef = useRef(null);
|
|
4580
5293
|
const pendingScrollRef = useRef(null);
|
|
5294
|
+
const renderedHistoryKey = useRef(undefined);
|
|
4581
5295
|
const currentMatchRef = useRef(initialMatch);
|
|
4582
5296
|
const [staticMode] = useState(detectStaticMode);
|
|
4583
5297
|
const resolvedSearch = state.data.query ?? EMPTY_SEARCH;
|
|
4584
|
-
const rootBoundaries =
|
|
5298
|
+
const rootBoundaries = useMemo2(() => {
|
|
4585
5299
|
for (const route of routes) {
|
|
4586
5300
|
const depth0 = route.segmentBoundaries?.find((b) => b.depth === 0);
|
|
4587
5301
|
if (depth0) {
|
|
@@ -4589,10 +5303,9 @@ function RouterProvider({
|
|
|
4589
5303
|
}
|
|
4590
5304
|
}
|
|
4591
5305
|
}, [routes]);
|
|
4592
|
-
const resolveNoMatchState =
|
|
5306
|
+
const resolveNoMatchState = useCallback3(async (physicalHref, signal) => {
|
|
4593
5307
|
const res = await fetch(physicalHref, { signal });
|
|
4594
5308
|
if (isStaleDeployResponse(res)) {
|
|
4595
|
-
window.location.href = physicalHref;
|
|
4596
5309
|
return null;
|
|
4597
5310
|
}
|
|
4598
5311
|
const { data, finalHref, title } = await parsePageResponse(res, basePath);
|
|
@@ -4610,7 +5323,8 @@ function RouterProvider({
|
|
|
4610
5323
|
title
|
|
4611
5324
|
};
|
|
4612
5325
|
}, [basePath, rootBoundaries]);
|
|
4613
|
-
const fetchPageState =
|
|
5326
|
+
const fetchPageState = useCallback3(async (rawLogicalHref, signal, hmrRefresh) => {
|
|
5327
|
+
const hydrateQueries = queries.captureHydration();
|
|
4614
5328
|
const logicalHref = normalizeHref(rawLogicalHref);
|
|
4615
5329
|
try {
|
|
4616
5330
|
const physicalHref = basePath + logicalHref;
|
|
@@ -4625,12 +5339,16 @@ function RouterProvider({
|
|
|
4625
5339
|
const [res, loadedMod] = await Promise.all([
|
|
4626
5340
|
fetch(dataEndpoint, {
|
|
4627
5341
|
headers: hmrRefresh ? { "x-furin-hmr-refresh": "1" } : undefined,
|
|
5342
|
+
redirect: "manual",
|
|
4628
5343
|
signal
|
|
4629
5344
|
}),
|
|
4630
5345
|
loadedModule
|
|
4631
5346
|
]);
|
|
4632
5347
|
if (isStaleDeployResponse(res)) {
|
|
4633
|
-
|
|
5348
|
+
return null;
|
|
5349
|
+
}
|
|
5350
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
5351
|
+
if (!(staticMode || contentType.includes("application/x-ndjson") || contentType.includes("application/x-furin-route"))) {
|
|
4634
5352
|
return null;
|
|
4635
5353
|
}
|
|
4636
5354
|
const body = res.body ?? new ReadableStream({ start: (c) => c.close() });
|
|
@@ -4654,9 +5372,24 @@ function RouterProvider({
|
|
|
4654
5372
|
__furinRedirect,
|
|
4655
5373
|
__furinError,
|
|
4656
5374
|
__furinTitle,
|
|
5375
|
+
__furinQueries,
|
|
4657
5376
|
...cleanSyncData
|
|
4658
5377
|
} = syncData;
|
|
4659
|
-
|
|
5378
|
+
if (typeof __furinRedirect === "string") {
|
|
5379
|
+
const target = new URL(__furinRedirect, window.location.origin);
|
|
5380
|
+
const isLogicalPath = __furinRedirect.startsWith("/") && !__furinRedirect.startsWith("//");
|
|
5381
|
+
const withinMount = isLogicalPath || basePath === "" || target.pathname === basePath || target.pathname.startsWith(`${basePath}/`);
|
|
5382
|
+
const targetPath = isLogicalPath ? target.pathname : toLogical(target.pathname, basePath);
|
|
5383
|
+
if (target.origin !== window.location.origin || !withinMount || !routes.some((route) => route.regex.test(targetPath))) {
|
|
5384
|
+
return null;
|
|
5385
|
+
}
|
|
5386
|
+
return {
|
|
5387
|
+
data: {},
|
|
5388
|
+
finalHref: targetPath + target.search + target.hash,
|
|
5389
|
+
match: null,
|
|
5390
|
+
title: ""
|
|
5391
|
+
};
|
|
5392
|
+
}
|
|
4660
5393
|
const data = { ...cleanSyncData, ...deferredPromises };
|
|
4661
5394
|
const title = typeof __furinTitle === "string" ? __furinTitle : "";
|
|
4662
5395
|
const loadedMatch = loadedMod ? {
|
|
@@ -4672,7 +5405,6 @@ function RouterProvider({
|
|
|
4672
5405
|
return {
|
|
4673
5406
|
data,
|
|
4674
5407
|
error: __furinError,
|
|
4675
|
-
finalHref,
|
|
4676
5408
|
head: __furinHead,
|
|
4677
5409
|
match: loadedMatch,
|
|
4678
5410
|
title
|
|
@@ -4686,17 +5418,20 @@ function RouterProvider({
|
|
|
4686
5418
|
const notFound = __furinNotFound !== null && typeof __furinNotFound === "object" ? __furinNotFound : {};
|
|
4687
5419
|
return {
|
|
4688
5420
|
data,
|
|
4689
|
-
finalHref,
|
|
4690
5421
|
head: __furinHead,
|
|
4691
5422
|
match: loadedMatch,
|
|
4692
5423
|
notFound,
|
|
4693
5424
|
title
|
|
4694
5425
|
};
|
|
4695
5426
|
}
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
5427
|
+
return {
|
|
5428
|
+
data,
|
|
5429
|
+
head: __furinHead,
|
|
5430
|
+
match: loadedMatch,
|
|
5431
|
+
querySeeds: __furinQueries,
|
|
5432
|
+
hydrateQueries,
|
|
5433
|
+
title
|
|
5434
|
+
};
|
|
4700
5435
|
} catch (err) {
|
|
4701
5436
|
if (!isAbortError(err)) {
|
|
4702
5437
|
_log.error({
|
|
@@ -4707,26 +5442,38 @@ function RouterProvider({
|
|
|
4707
5442
|
}
|
|
4708
5443
|
return null;
|
|
4709
5444
|
}
|
|
4710
|
-
}, [routes, basePath, resolveNoMatchState]);
|
|
4711
|
-
const
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
5445
|
+
}, [routes, basePath, resolveNoMatchState, queries]);
|
|
5446
|
+
const fetchConfirmedPageState = useCallback3(async (href, signal, hmrRefresh) => {
|
|
5447
|
+
for (;; ) {
|
|
5448
|
+
try {
|
|
5449
|
+
await optimisticRuntime.wait(href, signal);
|
|
5450
|
+
} catch (error) {
|
|
5451
|
+
if (signal?.aborted) {
|
|
5452
|
+
return null;
|
|
4717
5453
|
}
|
|
5454
|
+
throw error;
|
|
5455
|
+
}
|
|
5456
|
+
const version = optimisticRuntime.revision(href);
|
|
5457
|
+
const snapshot = await fetchPageState(href, signal, hmrRefresh);
|
|
5458
|
+
if (optimisticRuntime.publishable(href, version)) {
|
|
5459
|
+
if (snapshot) {
|
|
5460
|
+
snapshotVersions.current.set(snapshot, version);
|
|
5461
|
+
}
|
|
5462
|
+
return snapshot;
|
|
4718
5463
|
}
|
|
4719
|
-
return;
|
|
4720
5464
|
}
|
|
4721
|
-
|
|
5465
|
+
}, [fetchPageState, optimisticRuntime]);
|
|
5466
|
+
const invalidatePrefetch = useCallback3((path, type) => {
|
|
5467
|
+
const normalizedPath = normalizeHref(new URL(path, "http://furin.local").pathname);
|
|
4722
5468
|
for (const key of [...prefetchCache.current.keys()]) {
|
|
4723
|
-
|
|
4724
|
-
|
|
5469
|
+
if (shouldAutoRefreshPath(normalizeHref(stripHashFromHref(key)), [
|
|
5470
|
+
{ path: normalizedPath, type }
|
|
5471
|
+
])) {
|
|
4725
5472
|
prefetchCache.current.delete(key);
|
|
4726
5473
|
}
|
|
4727
5474
|
}
|
|
4728
5475
|
}, []);
|
|
4729
|
-
const prefetch =
|
|
5476
|
+
const prefetch = useCallback3((href, opts) => {
|
|
4730
5477
|
const staleTime = opts?.staleTime ?? defaultPreloadStaleTime;
|
|
4731
5478
|
const existing = prefetchCache.current.get(href);
|
|
4732
5479
|
if (existing && !shouldRefetch(existing)) {
|
|
@@ -4740,14 +5487,37 @@ function RouterProvider({
|
|
|
4740
5487
|
}, [fetchPageState, defaultPreloadStaleTime, prefetchCacheSize]);
|
|
4741
5488
|
async function resolveRedirectState(redirectLogical, myVersion, signal) {
|
|
4742
5489
|
const cached = prefetchCache.current.get(redirectLogical);
|
|
4743
|
-
const
|
|
5490
|
+
const useCached = cached !== undefined && !shouldRefetch(cached) && !optimisticRuntime.has(redirectLogical);
|
|
5491
|
+
let redirectState = useCached && cached ? await cached.promise : await fetchConfirmedPageState(redirectLogical, signal, false);
|
|
4744
5492
|
if (navVersion.current !== myVersion) {
|
|
4745
5493
|
return null;
|
|
4746
5494
|
}
|
|
4747
|
-
|
|
5495
|
+
if (useCached && (isRedirectState(redirectState) || redirectState && !optimisticRuntime.publishable(redirectLogical, snapshotVersions.current.get(redirectState) ?? optimisticRuntime.revision(redirectLogical)))) {
|
|
5496
|
+
redirectState = await fetchConfirmedPageState(redirectLogical, signal, false);
|
|
5497
|
+
}
|
|
5498
|
+
return navVersion.current === myVersion ? redirectState : null;
|
|
4748
5499
|
}
|
|
4749
|
-
|
|
5500
|
+
async function followRedirects(initialState, initialHref, myVersion, signal) {
|
|
5501
|
+
let redirectState = initialState;
|
|
5502
|
+
let href = initialHref;
|
|
5503
|
+
const visited = new Set([href]);
|
|
5504
|
+
for (let count = 0;isRedirectState(redirectState); count += 1) {
|
|
5505
|
+
href = normalizeHref(redirectState.finalHref);
|
|
5506
|
+
if (count >= 10 || visited.has(href)) {
|
|
5507
|
+
return null;
|
|
5508
|
+
}
|
|
5509
|
+
visited.add(href);
|
|
5510
|
+
const next = await resolveRedirectState(href, myVersion, signal);
|
|
5511
|
+
if (!next) {
|
|
5512
|
+
return null;
|
|
5513
|
+
}
|
|
5514
|
+
redirectState = next;
|
|
5515
|
+
}
|
|
5516
|
+
return { href, state: redirectState };
|
|
5517
|
+
}
|
|
5518
|
+
const navigate = useCallback3(async function navigateTo(rawLogicalHref, opts) {
|
|
4750
5519
|
const logicalHref = normalizeHref(rawLogicalHref);
|
|
5520
|
+
const beforeCommit = opts?.beforeCommit;
|
|
4751
5521
|
const finishUserNavigation = opts?.hmrRefresh === true ? undefined : beginUserNavigation(pendingUserNavigation);
|
|
4752
5522
|
navVersion.current += 1;
|
|
4753
5523
|
const myVersion = navVersion.current;
|
|
@@ -4758,11 +5528,16 @@ function RouterProvider({
|
|
|
4758
5528
|
setIsNavigating(true);
|
|
4759
5529
|
try {
|
|
4760
5530
|
const cached = prefetchCache.current.get(logicalHref);
|
|
4761
|
-
|
|
5531
|
+
const useCached = cached !== undefined && !shouldRefetch(cached) && !optimisticRuntime.has(logicalHref);
|
|
5532
|
+
let newState = useCached && cached ? await cached.promise : await fetchConfirmedPageState(logicalHref, navSignal, opts?.hmrRefresh === true);
|
|
5533
|
+
const cachedRedirect = useCached && (isRedirectState(newState) || newState && !optimisticRuntime.publishable(logicalHref, snapshotVersions.current.get(newState) ?? optimisticRuntime.revision(logicalHref)));
|
|
5534
|
+
if (cachedRedirect) {
|
|
5535
|
+
newState = await fetchConfirmedPageState(logicalHref, navSignal, opts?.hmrRefresh === true);
|
|
5536
|
+
}
|
|
4762
5537
|
if (navVersion.current !== myVersion || opts?.shouldCommit?.() === false) {
|
|
4763
5538
|
return;
|
|
4764
5539
|
}
|
|
4765
|
-
if (newState && (!
|
|
5540
|
+
if (newState && (!useCached || cachedRedirect)) {
|
|
4766
5541
|
setPrefetchCacheEntry(prefetchCache.current, logicalHref, {
|
|
4767
5542
|
createdAt: Date.now(),
|
|
4768
5543
|
promise: Promise.resolve(newState),
|
|
@@ -4778,28 +5553,33 @@ function RouterProvider({
|
|
|
4778
5553
|
window.location.href = basePath + logicalHref;
|
|
4779
5554
|
return;
|
|
4780
5555
|
}
|
|
4781
|
-
|
|
4782
|
-
if (
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
}, "", redirectPhysical);
|
|
4789
|
-
setCurrentHref(redirectLogical);
|
|
4790
|
-
const redirectState = await resolveRedirectState(redirectLogical, myVersion, navSignal);
|
|
4791
|
-
if (!redirectState) {
|
|
4792
|
-
if (navVersion.current === myVersion) {
|
|
4793
|
-
window.location.href = redirectPhysical;
|
|
4794
|
-
}
|
|
4795
|
-
return;
|
|
5556
|
+
const resolved = await followRedirects(newState, logicalHref, myVersion, navSignal);
|
|
5557
|
+
if (navVersion.current !== myVersion) {
|
|
5558
|
+
return;
|
|
5559
|
+
}
|
|
5560
|
+
if (!resolved) {
|
|
5561
|
+
if (navVersion.current === myVersion) {
|
|
5562
|
+
window.location.href = basePath + logicalHref;
|
|
4796
5563
|
}
|
|
4797
|
-
|
|
5564
|
+
return;
|
|
4798
5565
|
}
|
|
5566
|
+
newState = resolved.state;
|
|
4799
5567
|
if (opts?.shouldCommit?.() === false) {
|
|
4800
5568
|
return;
|
|
4801
5569
|
}
|
|
4802
|
-
|
|
5570
|
+
const publicationHref = newState.finalHref ?? resolved.href;
|
|
5571
|
+
if (!optimisticRuntime.publishable(publicationHref, snapshotVersions.current.get(newState) ?? optimisticRuntime.revision(publicationHref))) {
|
|
5572
|
+
return;
|
|
5573
|
+
}
|
|
5574
|
+
if (!(newState.error || newState.notFound)) {
|
|
5575
|
+
optimisticRuntime.commit(publicationHref);
|
|
5576
|
+
}
|
|
5577
|
+
beforeCommit?.();
|
|
5578
|
+
const effectiveLogical = newState.finalHref ?? resolved.href;
|
|
5579
|
+
const physicalEffective = basePath + effectiveLogical;
|
|
5580
|
+
if (opts?.resetScroll ?? true) {
|
|
5581
|
+
pendingScrollRef.current = { href: physicalEffective, type: "reset" };
|
|
5582
|
+
}
|
|
4803
5583
|
currentMatchRef.current = newState.match;
|
|
4804
5584
|
if (!newState.error) {
|
|
4805
5585
|
setBoundaryResetVersion((version) => version + 1);
|
|
@@ -4808,50 +5588,54 @@ function RouterProvider({
|
|
|
4808
5588
|
if (newState.title) {
|
|
4809
5589
|
document.title = newState.title;
|
|
4810
5590
|
}
|
|
4811
|
-
const effectiveLogical = newState.finalHref ?? redirectLogical ?? logicalHref;
|
|
4812
|
-
const physicalEffective = basePath + effectiveLogical;
|
|
4813
5591
|
if (opts?.replace) {
|
|
4814
5592
|
window.history.replaceState({
|
|
4815
5593
|
...getHistoryStateObject(),
|
|
4816
5594
|
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey()
|
|
4817
5595
|
}, "", physicalEffective);
|
|
4818
5596
|
} else {
|
|
4819
|
-
const currentKey =
|
|
5597
|
+
const currentKey = renderedHistoryKey.current;
|
|
4820
5598
|
if (currentKey) {
|
|
4821
5599
|
saveScrollPosition(currentKey);
|
|
4822
5600
|
}
|
|
4823
5601
|
window.history.pushState({ _furinKey: generateHistoryKey() }, "", physicalEffective);
|
|
4824
5602
|
}
|
|
5603
|
+
renderedHistoryKey.current = getHistoryKey(history.state);
|
|
4825
5604
|
const effectiveUrl = new URL(physicalEffective, window.location.origin);
|
|
4826
5605
|
const logicalPath = normalizeHref(toLogical(effectiveUrl.pathname, basePath));
|
|
4827
5606
|
setCurrentHref(logicalPath + effectiveUrl.search);
|
|
4828
|
-
if (opts?.resetScroll ?? true) {
|
|
4829
|
-
pendingScrollRef.current = { href: physicalEffective, type: "reset" };
|
|
4830
|
-
}
|
|
4831
5607
|
} finally {
|
|
4832
5608
|
finishUserNavigation?.();
|
|
4833
5609
|
if (navVersion.current === myVersion) {
|
|
4834
5610
|
setIsNavigating(false);
|
|
4835
5611
|
}
|
|
4836
5612
|
}
|
|
4837
|
-
}, [
|
|
5613
|
+
}, [
|
|
5614
|
+
basePath,
|
|
5615
|
+
fetchConfirmedPageState,
|
|
5616
|
+
defaultPreloadStaleTime,
|
|
5617
|
+
prefetchCacheSize,
|
|
5618
|
+
optimisticRuntime
|
|
5619
|
+
]);
|
|
4838
5620
|
const [searchStore] = useState(() => createSearchStore({
|
|
4839
5621
|
currentHref,
|
|
5622
|
+
currentPattern: state.match?.pattern,
|
|
4840
5623
|
navigate,
|
|
4841
5624
|
search: resolvedSearch,
|
|
4842
5625
|
searchRoutes: routes
|
|
4843
5626
|
}));
|
|
4844
|
-
const searchSnapshot =
|
|
5627
|
+
const searchSnapshot = useMemo2(() => ({
|
|
4845
5628
|
currentHref,
|
|
5629
|
+
currentPattern: state.match?.pattern,
|
|
4846
5630
|
navigate,
|
|
4847
5631
|
search: resolvedSearch,
|
|
4848
5632
|
searchRoutes: routes
|
|
4849
|
-
}), [currentHref, navigate, resolvedSearch, routes]);
|
|
5633
|
+
}), [currentHref, state.match?.pattern, navigate, resolvedSearch, routes]);
|
|
4850
5634
|
useLayoutEffect(() => {
|
|
4851
5635
|
searchStore.setSnapshot(searchSnapshot);
|
|
4852
5636
|
searchStore.flush();
|
|
4853
5637
|
}, [searchStore, searchSnapshot]);
|
|
4854
|
-
const refresh =
|
|
5638
|
+
const refresh = useCallback3(async (opts) => {
|
|
4855
5639
|
const logicalPath = toLogical(window.location.pathname, basePath);
|
|
4856
5640
|
const logicalHref = logicalPath + window.location.search;
|
|
4857
5641
|
invalidatePrefetch(logicalHref, "page");
|
|
@@ -4863,13 +5647,34 @@ function RouterProvider({
|
|
|
4863
5647
|
shouldCommit: opts?.shouldCommit
|
|
4864
5648
|
});
|
|
4865
5649
|
}, [navigate, invalidatePrefetch, basePath]);
|
|
4866
|
-
const invalidationRefresh =
|
|
5650
|
+
const invalidationRefresh = useMemo2(() => createInvalidationRefresh({
|
|
4867
5651
|
onError: (error) => {
|
|
4868
5652
|
_log.warn({ action: "sync_refresh_failed", error: String(error) });
|
|
4869
5653
|
},
|
|
4870
|
-
refresh: () =>
|
|
5654
|
+
refresh: async () => {
|
|
5655
|
+
await waitForUserNavigation(pendingUserNavigation);
|
|
5656
|
+
await refresh(undefined);
|
|
5657
|
+
}
|
|
4871
5658
|
}), [refresh]);
|
|
4872
|
-
|
|
5659
|
+
useLayoutEffect(() => {
|
|
5660
|
+
syncResponse.current = (response, optimistic) => {
|
|
5661
|
+
const invalidated = [];
|
|
5662
|
+
if (response && (response.url === "" || new URL(response.url).origin === window.location.origin)) {
|
|
5663
|
+
applyRevalidateHeader(response.headers, (path, type) => {
|
|
5664
|
+
const resolvedType = type ?? "page";
|
|
5665
|
+
invalidatePrefetch(path, resolvedType);
|
|
5666
|
+
invalidated.push({ path, type: resolvedType });
|
|
5667
|
+
});
|
|
5668
|
+
}
|
|
5669
|
+
if (optimistic || autoRefresh && shouldAutoRefreshPath(optimisticSnapshot.current.href, invalidated)) {
|
|
5670
|
+
invalidationRefresh.run();
|
|
5671
|
+
}
|
|
5672
|
+
};
|
|
5673
|
+
return () => {
|
|
5674
|
+
syncResponse.current = undefined;
|
|
5675
|
+
};
|
|
5676
|
+
}, [autoRefresh, invalidatePrefetch, invalidationRefresh]);
|
|
5677
|
+
useEffect2(() => {
|
|
4873
5678
|
if (typeof window !== "undefined") {
|
|
4874
5679
|
window.__FURIN_HMR_REFRESH__ = async (beforeCommit, dataChanged) => {
|
|
4875
5680
|
hmrVersion.current += 1;
|
|
@@ -4903,8 +5708,11 @@ function RouterProvider({
|
|
|
4903
5708
|
};
|
|
4904
5709
|
}
|
|
4905
5710
|
}, [refresh]);
|
|
4906
|
-
const handlePopState =
|
|
5711
|
+
const handlePopState = useCallback3(() => {
|
|
4907
5712
|
const finishUserNavigation = beginUserNavigation(pendingUserNavigation);
|
|
5713
|
+
if (renderedHistoryKey.current) {
|
|
5714
|
+
saveScrollPosition(renderedHistoryKey.current);
|
|
5715
|
+
}
|
|
4908
5716
|
const destKey = getHistoryKey(history.state);
|
|
4909
5717
|
const logicalPath = normalizeHref(toLogical(window.location.pathname, basePath));
|
|
4910
5718
|
const logicalHref = logicalPath + window.location.search;
|
|
@@ -4919,10 +5727,13 @@ function RouterProvider({
|
|
|
4919
5727
|
try {
|
|
4920
5728
|
const cached = prefetchCache.current.get(logicalHref);
|
|
4921
5729
|
let newState;
|
|
4922
|
-
if (cached && !shouldRefetch(cached)) {
|
|
5730
|
+
if (cached && !shouldRefetch(cached) && !optimisticRuntime.has(logicalHref)) {
|
|
4923
5731
|
newState = await cached.promise;
|
|
5732
|
+
if (isRedirectState(newState) || newState && !optimisticRuntime.publishable(logicalHref, snapshotVersions.current.get(newState) ?? optimisticRuntime.revision(logicalHref))) {
|
|
5733
|
+
newState = await fetchConfirmedPageState(logicalHref, navSignal, false);
|
|
5734
|
+
}
|
|
4924
5735
|
} else {
|
|
4925
|
-
newState = await
|
|
5736
|
+
newState = await fetchConfirmedPageState(logicalHref, navSignal, false);
|
|
4926
5737
|
}
|
|
4927
5738
|
if (navVersion.current !== myVersion) {
|
|
4928
5739
|
return;
|
|
@@ -4936,19 +5747,23 @@ function RouterProvider({
|
|
|
4936
5747
|
window.location.reload();
|
|
4937
5748
|
return;
|
|
4938
5749
|
}
|
|
4939
|
-
|
|
4940
|
-
if (
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
if (navVersion.current === myVersion) {
|
|
4947
|
-
window.location.reload();
|
|
4948
|
-
}
|
|
4949
|
-
return;
|
|
5750
|
+
const resolved = await followRedirects(newState, logicalHref, myVersion, navSignal);
|
|
5751
|
+
if (navVersion.current !== myVersion) {
|
|
5752
|
+
return;
|
|
5753
|
+
}
|
|
5754
|
+
if (!resolved) {
|
|
5755
|
+
if (navVersion.current === myVersion) {
|
|
5756
|
+
window.location.reload();
|
|
4950
5757
|
}
|
|
4951
|
-
|
|
5758
|
+
return;
|
|
5759
|
+
}
|
|
5760
|
+
newState = resolved.state;
|
|
5761
|
+
const publicationHref = newState.finalHref ?? resolved.href;
|
|
5762
|
+
if (!optimisticRuntime.publishable(publicationHref, snapshotVersions.current.get(newState) ?? optimisticRuntime.revision(publicationHref))) {
|
|
5763
|
+
return;
|
|
5764
|
+
}
|
|
5765
|
+
if (!(newState.error || newState.notFound)) {
|
|
5766
|
+
optimisticRuntime.commit(publicationHref);
|
|
4952
5767
|
}
|
|
4953
5768
|
currentMatchRef.current = newState.match;
|
|
4954
5769
|
if (!newState.error) {
|
|
@@ -4958,10 +5773,11 @@ function RouterProvider({
|
|
|
4958
5773
|
if (newState.title) {
|
|
4959
5774
|
document.title = newState.title;
|
|
4960
5775
|
}
|
|
4961
|
-
const effectiveLogical = newState.finalHref ??
|
|
4962
|
-
if (
|
|
5776
|
+
const effectiveLogical = newState.finalHref ?? resolved.href;
|
|
5777
|
+
if (effectiveLogical !== logicalHref) {
|
|
4963
5778
|
window.history.replaceState(history.state, "", basePath + effectiveLogical);
|
|
4964
5779
|
}
|
|
5780
|
+
renderedHistoryKey.current = destKey;
|
|
4965
5781
|
setCurrentHref(normalizeHref(effectiveLogical));
|
|
4966
5782
|
if (destKey) {
|
|
4967
5783
|
pendingScrollRef.current = { key: destKey, type: "restore" };
|
|
@@ -4975,12 +5791,13 @@ function RouterProvider({
|
|
|
4975
5791
|
}
|
|
4976
5792
|
}
|
|
4977
5793
|
})();
|
|
4978
|
-
}, [
|
|
4979
|
-
|
|
5794
|
+
}, [fetchConfirmedPageState, basePath, optimisticRuntime]);
|
|
5795
|
+
useEffect2(() => {
|
|
4980
5796
|
history.scrollRestoration = "manual";
|
|
4981
5797
|
if (!getHistoryKey(history.state)) {
|
|
4982
5798
|
history.replaceState({ ...getHistoryStateObject(), _furinKey: generateHistoryKey() }, "");
|
|
4983
5799
|
}
|
|
5800
|
+
renderedHistoryKey.current = getHistoryKey(history.state);
|
|
4984
5801
|
}, []);
|
|
4985
5802
|
useLayoutEffect(() => {
|
|
4986
5803
|
const instruction = pendingScrollRef.current;
|
|
@@ -5009,12 +5826,12 @@ function RouterProvider({
|
|
|
5009
5826
|
} else {
|
|
5010
5827
|
window.scrollTo({ behavior: "instant", top: 0 });
|
|
5011
5828
|
}
|
|
5012
|
-
}, [currentHref]);
|
|
5013
|
-
|
|
5829
|
+
}, [currentHref, state]);
|
|
5830
|
+
useEffect2(() => {
|
|
5014
5831
|
window.addEventListener("popstate", handlePopState);
|
|
5015
5832
|
return () => window.removeEventListener("popstate", handlePopState);
|
|
5016
5833
|
}, [handlePopState]);
|
|
5017
|
-
|
|
5834
|
+
useEffect2(() => {
|
|
5018
5835
|
if (typeof window === "undefined") {
|
|
5019
5836
|
return;
|
|
5020
5837
|
}
|
|
@@ -5039,18 +5856,21 @@ function RouterProvider({
|
|
|
5039
5856
|
return;
|
|
5040
5857
|
}
|
|
5041
5858
|
e.preventDefault();
|
|
5042
|
-
navigate(logicalHref,
|
|
5859
|
+
navigate(logicalHref, undefined);
|
|
5043
5860
|
};
|
|
5044
5861
|
document.addEventListener("click", handler);
|
|
5045
5862
|
return () => document.removeEventListener("click", handler);
|
|
5046
5863
|
}, [navigate, basePath, routes]);
|
|
5047
|
-
|
|
5864
|
+
useEffect2(() => {
|
|
5048
5865
|
if (typeof window === "undefined") {
|
|
5049
5866
|
return;
|
|
5050
5867
|
}
|
|
5051
5868
|
const originalFetch = window.fetch;
|
|
5052
5869
|
const wrapped = async (...args) => {
|
|
5053
5870
|
const response = await originalFetch.apply(window, args);
|
|
5871
|
+
if (args[1] && SYNC_REQUEST in args[1]) {
|
|
5872
|
+
return response;
|
|
5873
|
+
}
|
|
5054
5874
|
if (!isSameOriginFetchResult(args[0], response.url, window.location.origin)) {
|
|
5055
5875
|
return response;
|
|
5056
5876
|
}
|
|
@@ -5074,7 +5894,7 @@ function RouterProvider({
|
|
|
5074
5894
|
window.fetch = originalFetch;
|
|
5075
5895
|
};
|
|
5076
5896
|
}, [invalidatePrefetch, invalidationRefresh, autoRefresh, basePath]);
|
|
5077
|
-
|
|
5897
|
+
useEffect2(() => {
|
|
5078
5898
|
if (!syncPath || typeof window === "undefined") {
|
|
5079
5899
|
return;
|
|
5080
5900
|
}
|
|
@@ -5110,7 +5930,25 @@ function RouterProvider({
|
|
|
5110
5930
|
}
|
|
5111
5931
|
return await response.json();
|
|
5112
5932
|
},
|
|
5113
|
-
onInvalidations: applyInvalidations
|
|
5933
|
+
onInvalidations: applyInvalidations,
|
|
5934
|
+
onReset: () => queries.invalidateAll(),
|
|
5935
|
+
onQueries: (identities) => {
|
|
5936
|
+
queries.invalidate(identities);
|
|
5937
|
+
const tags = new Set(identities.map(queryTag));
|
|
5938
|
+
const affected = (snapshot) => snapshot.querySeeds?.some((seed) => tags.has(queryTag(seed.identity)));
|
|
5939
|
+
for (const [href, entry] of prefetchCache.current) {
|
|
5940
|
+
entry.promise.then((snapshot) => {
|
|
5941
|
+
if (snapshot && affected(snapshot) && prefetchCache.current.get(href) === entry) {
|
|
5942
|
+
prefetchCache.current.delete(href);
|
|
5943
|
+
}
|
|
5944
|
+
}).catch(() => {
|
|
5945
|
+
return;
|
|
5946
|
+
});
|
|
5947
|
+
}
|
|
5948
|
+
if (autoRefresh && affected(currentState.current)) {
|
|
5949
|
+
invalidationRefresh.run();
|
|
5950
|
+
}
|
|
5951
|
+
}
|
|
5114
5952
|
});
|
|
5115
5953
|
const recover = () => {
|
|
5116
5954
|
if (disposed) {
|
|
@@ -5144,12 +5982,21 @@ function RouterProvider({
|
|
|
5144
5982
|
disposed = true;
|
|
5145
5983
|
unsubscribe?.();
|
|
5146
5984
|
};
|
|
5147
|
-
}, [syncPath, basePath, invalidatePrefetch, invalidationRefresh, autoRefresh]);
|
|
5985
|
+
}, [syncPath, basePath, invalidatePrefetch, invalidationRefresh, autoRefresh, queries]);
|
|
5986
|
+
const queryData = useMemo2(() => projectDeferredQueryData(state.data, state.querySeeds ?? [], (seed) => {
|
|
5987
|
+
if (seed.local && typeof window !== "undefined") {
|
|
5988
|
+
const original = new URL(seed.url);
|
|
5989
|
+
return queries.snapshot(new URL(original.pathname + original.search, window.location.origin).href).data;
|
|
5990
|
+
}
|
|
5991
|
+
return queries.snapshot(seed.url).data;
|
|
5992
|
+
}, resolvedQueries.current), [queries, state.data, state.querySeeds, queryRevision, deferredRevision]);
|
|
5993
|
+
const renderedData = optimisticRuntime.project(queryData, currentHref);
|
|
5148
5994
|
let pageElement;
|
|
5149
5995
|
if (state.notFound || !state.match) {
|
|
5150
|
-
|
|
5996
|
+
const notFoundElement = buildNotFoundPageElement(state.notFoundBoundaries ?? state.match?.segmentBoundaries ?? rootBoundaries, state.notFound ?? {});
|
|
5997
|
+
pageElement = root?.layout ? createElement6(root.layout, renderedData, notFoundElement) : notFoundElement;
|
|
5151
5998
|
} else {
|
|
5152
|
-
pageElement = buildPageElement(state.match, root,
|
|
5999
|
+
pageElement = buildPageElement(state.match, root, renderedData, {
|
|
5153
6000
|
onReset: () => {
|
|
5154
6001
|
refresh(undefined).catch((err) => {
|
|
5155
6002
|
_log.error({ action: "boundary_reset_failed", error: String(err) });
|
|
@@ -5163,6 +6010,7 @@ function RouterProvider({
|
|
|
5163
6010
|
children: buildRouterTree({
|
|
5164
6011
|
basePath,
|
|
5165
6012
|
currentHref,
|
|
6013
|
+
currentPattern: state.match?.pattern,
|
|
5166
6014
|
defaultPreload,
|
|
5167
6015
|
defaultPreloadDelay,
|
|
5168
6016
|
defaultPreloadStaleTime,
|
|
@@ -5185,14 +6033,20 @@ function RouterProvider({
|
|
|
5185
6033
|
})
|
|
5186
6034
|
}, undefined, false, undefined, this);
|
|
5187
6035
|
if (initialDocumentState === null) {
|
|
5188
|
-
return
|
|
6036
|
+
return /* @__PURE__ */ jsxDEV5(QueryStoreContext.Provider, {
|
|
6037
|
+
value: queries,
|
|
6038
|
+
children: routerTree
|
|
6039
|
+
}, undefined, false, undefined, this);
|
|
5189
6040
|
}
|
|
5190
6041
|
return /* @__PURE__ */ jsxDEV5(DocumentProvider, {
|
|
5191
6042
|
value: {
|
|
5192
6043
|
...initialDocumentState,
|
|
5193
6044
|
head: state.head
|
|
5194
6045
|
},
|
|
5195
|
-
children:
|
|
6046
|
+
children: /* @__PURE__ */ jsxDEV5(QueryStoreContext.Provider, {
|
|
6047
|
+
value: queries,
|
|
6048
|
+
children: routerTree
|
|
6049
|
+
}, undefined, false, undefined, this)
|
|
5196
6050
|
}, undefined, false, undefined, this);
|
|
5197
6051
|
}
|
|
5198
6052
|
// src/client/link.tsx
|
|
@@ -5244,7 +6098,7 @@ function LinkInteractive({
|
|
|
5244
6098
|
href: _href,
|
|
5245
6099
|
...anchorProps
|
|
5246
6100
|
}) {
|
|
5247
|
-
const router2 =
|
|
6101
|
+
const router2 = useRouterContext();
|
|
5248
6102
|
const anchorRef = useRef2(null);
|
|
5249
6103
|
const intentTimerRef = useRef2(null);
|
|
5250
6104
|
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ activeProps, children, hash, inactiveProps, params, search, to }, router2);
|
|
@@ -5252,15 +6106,15 @@ function LinkInteractive({
|
|
|
5252
6106
|
const effectiveDelay = preloadDelay ?? router2.defaultPreloadDelay;
|
|
5253
6107
|
const effectiveStaleTime = preloadStaleTime ?? router2.defaultPreloadStaleTime;
|
|
5254
6108
|
const { prefetch } = router2;
|
|
5255
|
-
const triggerPrefetch =
|
|
6109
|
+
const triggerPrefetch = useCallback4(() => {
|
|
5256
6110
|
prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
5257
6111
|
}, [prefetch, logicalHref, effectiveStaleTime]);
|
|
5258
|
-
|
|
6112
|
+
useEffect3(() => {
|
|
5259
6113
|
if (effectivePreload === "render") {
|
|
5260
6114
|
triggerPrefetch();
|
|
5261
6115
|
}
|
|
5262
6116
|
}, [effectivePreload, triggerPrefetch]);
|
|
5263
|
-
|
|
6117
|
+
useEffect3(() => {
|
|
5264
6118
|
if (effectivePreload !== "viewport" || !anchorRef.current) {
|
|
5265
6119
|
return;
|
|
5266
6120
|
}
|
|
@@ -5273,7 +6127,7 @@ function LinkInteractive({
|
|
|
5273
6127
|
observer.observe(anchorRef.current);
|
|
5274
6128
|
return () => observer.disconnect();
|
|
5275
6129
|
}, [effectivePreload, triggerPrefetch]);
|
|
5276
|
-
|
|
6130
|
+
useEffect3(() => () => {
|
|
5277
6131
|
if (intentTimerRef.current !== null) {
|
|
5278
6132
|
clearTimeout(intentTimerRef.current);
|
|
5279
6133
|
intentTimerRef.current = null;
|
|
@@ -5327,7 +6181,7 @@ function LinkInteractive({
|
|
|
5327
6181
|
triggerPrefetch();
|
|
5328
6182
|
}
|
|
5329
6183
|
};
|
|
5330
|
-
return
|
|
6184
|
+
return createElement7("a", {
|
|
5331
6185
|
"data-furin-link": true,
|
|
5332
6186
|
href,
|
|
5333
6187
|
onClick: handleClick,
|
|
@@ -5378,7 +6232,7 @@ function renderLinkElement(props, router2) {
|
|
|
5378
6232
|
href: _href,
|
|
5379
6233
|
...anchorProps
|
|
5380
6234
|
} = props;
|
|
5381
|
-
return
|
|
6235
|
+
return createElement7("a", {
|
|
5382
6236
|
"data-furin-link": true,
|
|
5383
6237
|
href,
|
|
5384
6238
|
...isActive ? { "data-status": "active" } : {},
|
|
@@ -5389,11 +6243,11 @@ function renderLinkElement(props, router2) {
|
|
|
5389
6243
|
}
|
|
5390
6244
|
function Link(props) {
|
|
5391
6245
|
if (typeof window === "undefined") {
|
|
5392
|
-
return
|
|
6246
|
+
return createElement7(RouterContext.Consumer, {
|
|
5393
6247
|
children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
|
|
5394
6248
|
});
|
|
5395
6249
|
}
|
|
5396
|
-
return
|
|
6250
|
+
return createElement7(LinkInteractive, props);
|
|
5397
6251
|
}
|
|
5398
6252
|
export {
|
|
5399
6253
|
CLIENT_FALLBACK_ROUTER,
|