@teyik0/furin 0.8.0-alpha.0 → 0.9.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/adapter/bun/app.d.ts +1 -0
- package/dist/adapter/bun.d.ts +3 -1
- package/dist/adapter/runtime-build.d.ts +8 -5
- package/dist/adapter/vercel.js +8 -8
- package/dist/build/client.d.ts +2 -2
- package/dist/build/discover-mounts-process.d.ts +1 -1
- package/dist/build/discover-pages-process.d.ts +1 -0
- package/dist/build/discover-pages.d.ts +11 -0
- package/dist/build/discovery-module.d.ts +3 -0
- package/dist/build/discovery-plugins.d.ts +34 -0
- package/dist/build/elysia-aot.d.ts +1 -1
- package/dist/build/entry-template.ts +6 -1
- package/dist/build/hydrate.d.ts +3 -2
- package/dist/build/index.js +7688 -8458
- package/dist/build/preload-manifest.d.ts +2 -2
- package/dist/build/route-metadata.d.ts +31 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/shared.d.ts +2 -2
- package/dist/build/types.d.ts +11 -0
- package/dist/cli/dev-worker.d.ts +1 -0
- package/dist/cli/dev-worker.ts +123 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/index.js +7811 -8477
- package/dist/client/browser-events-runtime.d.ts +2 -2
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/chunks/{client-brdfd773.js → client-rjhxgt64.js} +187 -4
- package/dist/client/dev-error-overlay.ts +18 -1
- package/dist/client/link.js +110 -156
- package/dist/client/query-store.d.ts +5 -0
- package/dist/client/router/navigation-controller.d.ts +2 -0
- package/dist/client/router/use-fetch-interception.d.ts +1 -1
- package/dist/client/router/use-sync-stream.d.ts +1 -1
- package/dist/client/{router/sync-catch-up.d.ts → sync-catch-up.d.ts} +5 -3
- package/dist/client/sync-client.d.ts +74 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +533 -145
- package/dist/config.d.ts +6 -1
- package/dist/config.js +3 -1
- package/dist/define-route.d.ts +3 -3
- package/dist/furin.d.ts +2 -1
- package/dist/furin.js +1119 -346
- package/dist/plugin/index.js +5 -5
- package/dist/plugin/route-registry.d.ts +22 -2
- package/dist/rsc/build/index.d.ts +4 -3
- package/dist/server/dev/server-only-module.d.ts +5 -0
- package/dist/server/internal.js +201 -91
- package/dist/server/logging/ingest-plugin.d.ts +1 -2
- package/dist/server/production-server.js +36 -33
- package/dist/server/server-entry.d.ts +5 -0
- package/dist/server/server-entry.js +36 -0
- package/dist/server/static-export.js +201 -91
- package/dist/server/sync/adapter.d.ts +4 -3
- package/dist/server/sync/config.d.ts +7 -0
- package/dist/server/sync/connection.d.ts +13 -0
- package/dist/server/sync/drizzle/index.js +5 -4
- package/dist/server/sync/index.d.ts +3 -0
- package/dist/server/sync/index.js +1361 -243
- package/dist/server/sync/invalidate-sync.d.ts +6 -2
- package/dist/server/sync/local-client.d.ts +9 -0
- package/dist/server/sync/postgres/index.d.ts +1 -1
- package/dist/server/sync/postgres/index.js +2 -2
- package/dist/server/sync/prisma/index.js +2 -2
- package/dist/server/sync/redis/index.d.ts +1 -1
- package/dist/server/sync/redis/index.js +4 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/runtime.d.ts +3 -0
- package/dist/server/sync/sqlite/index.d.ts +1 -1
- package/dist/server/sync/sqlite/index.js +3 -2
- package/dist/shared/browser-events.d.ts +4 -0
- package/dist/sync-client.d.ts +3 -0
- package/dist/sync-client.js +1600 -0
- package/package.json +12 -7
- package/src/adapter/README.md +7 -0
- package/src/adapter/build.ts +34 -33
- package/src/adapter/bun/app.ts +5 -0
- package/src/adapter/bun/server.ts +2 -2
- package/src/adapter/bun.ts +18 -2
- package/src/adapter/furin-app.d.ts +1 -0
- package/src/adapter/package.ts +1 -0
- package/src/adapter/runtime-build.ts +18 -12
- package/src/adapter/static.ts +17 -13
- package/src/build/client.ts +7 -5
- package/src/build/discover-mounts-process.ts +5 -1
- package/src/build/discover-pages-process.ts +151 -0
- package/src/build/discover-pages.ts +69 -0
- package/src/build/discovery-module.ts +70 -0
- package/src/build/discovery-plugins.ts +101 -0
- package/src/build/elysia-aot-worker.ts +9 -8
- package/src/build/elysia-aot.ts +110 -75
- package/src/build/entry-template.ts +6 -1
- package/src/build/hydrate.ts +11 -8
- package/src/build/index.ts +6 -50
- package/src/build/preload-manifest.ts +3 -3
- package/src/build/route-metadata.ts +90 -0
- package/src/build/route-types.ts +1 -1
- package/src/build/shared.ts +6 -8
- package/src/build/types.ts +9 -0
- package/src/cli/config.ts +4 -0
- package/src/cli/dev-worker.ts +123 -0
- package/src/cli/dev.ts +91 -0
- package/src/cli/index.ts +24 -1
- package/src/client/browser-events-runtime.ts +97 -23
- package/src/client/browser-events.ts +8 -0
- package/src/client/dev-error-overlay.ts +18 -1
- package/src/client/query-store.ts +54 -3
- package/src/client/router/navigation-controller.ts +45 -12
- package/src/client/router/provider.tsx +6 -2
- package/src/client/router/use-fetch-interception.ts +1 -1
- package/src/client/router/use-sync-stream.ts +96 -44
- package/src/client/{router/sync-catch-up.ts → sync-catch-up.ts} +28 -12
- package/src/client/sync-client.ts +528 -0
- package/src/client/sync.ts +11 -4
- package/src/client.ts +10 -0
- package/src/config.ts +17 -10
- package/src/furin.ts +5 -0
- package/src/plugin/route-registry.ts +53 -7
- package/src/rsc/build/index.ts +6 -3
- package/src/server/browser-events/plugin.ts +79 -25
- package/src/server/dev/rewrite-module-specifiers.ts +2 -1
- package/src/server/dev/server-only-module.ts +23 -0
- package/src/server/dev/symbolicate.ts +4 -3
- package/src/server/dev-page-imports.ts +3 -1
- package/src/server/dev-page-plugin.ts +18 -1
- package/src/server/logging/ingest-plugin.ts +3 -9
- package/src/server/server-entry.ts +39 -0
- package/src/server/sync/adapter.ts +7 -3
- package/src/server/sync/config.ts +12 -6
- package/src/server/sync/connection.ts +71 -0
- package/src/server/sync/index.ts +3 -0
- package/src/server/sync/invalidate-sync.ts +30 -5
- package/src/server/sync/local-client.ts +84 -0
- package/src/server/sync/plugin.ts +27 -20
- package/src/server/sync/postgres/index.ts +9 -2
- package/src/server/sync/redis/index.ts +5 -1
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/runtime.ts +56 -18
- package/src/server/sync/sqlite/index.ts +6 -2
- package/src/server/sync/stream.ts +17 -5
- package/src/shared/browser-events.ts +1 -1
- package/src/sync-client.ts +14 -0
- package/dist/server/logger.d.ts +0 -10
- package/src/server/logger.ts +0 -34
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function installBrowserEventsRuntime(browser: Window, moduleUrlValue: string, transport?: "sse"): void;
|
|
2
|
-
export declare function browserEventsClientSource(): string;
|
|
1
|
+
export declare function installBrowserEventsRuntime(browser: Window, moduleUrlValue: string, transport?: "sse", sync?: boolean): void;
|
|
2
|
+
export declare function browserEventsClientSource(sync?: boolean): string;
|
|
3
3
|
export declare function browserEventsSseClientSource(): string;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import type { BrowserEventChannel, BrowserEventFor } from "../shared/browser-events.ts";
|
|
2
|
+
/** @internal Router refresh is the existing explicit resume action for cookie authentication. */
|
|
3
|
+
export declare function setBrowserSyncAuthentication(authorized: boolean): void;
|
|
2
4
|
export declare function subscribeBrowserEvent<TChannel extends BrowserEventChannel>(channel: TChannel, listener: (event: BrowserEventFor<TChannel>) => void): (() => void) | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isWithinPrefix,
|
|
3
|
+
encodeInvalidationEntry,
|
|
3
4
|
buildHref2
|
|
4
5
|
} from "./client-xy6g38kx.js";
|
|
5
6
|
|
|
@@ -474,6 +475,45 @@ class QueryStore {
|
|
|
474
475
|
generation() {
|
|
475
476
|
return this.epoch;
|
|
476
477
|
}
|
|
478
|
+
clear(preserveData) {
|
|
479
|
+
this.epoch += 1;
|
|
480
|
+
if (!preserveData) {
|
|
481
|
+
this.session = undefined;
|
|
482
|
+
}
|
|
483
|
+
this.projections.clear();
|
|
484
|
+
for (const entry of this.entries.values()) {
|
|
485
|
+
if (!preserveData) {
|
|
486
|
+
entry.base = undefined;
|
|
487
|
+
entry.identity = undefined;
|
|
488
|
+
}
|
|
489
|
+
entry.promise = undefined;
|
|
490
|
+
entry.stale = true;
|
|
491
|
+
entry.version += 1;
|
|
492
|
+
entry.snapshot = { data: entry.base, error: null, isFetching: false };
|
|
493
|
+
this.publish(entry);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
dispose() {
|
|
497
|
+
this.epoch += 1;
|
|
498
|
+
for (const entry of this.entries.values()) {
|
|
499
|
+
entry.listeners.clear();
|
|
500
|
+
}
|
|
501
|
+
this.entries.clear();
|
|
502
|
+
this.requests = [];
|
|
503
|
+
this.projections.clear();
|
|
504
|
+
this.listeners.clear();
|
|
505
|
+
}
|
|
506
|
+
setError(url, error) {
|
|
507
|
+
const entry = this.entry(url);
|
|
508
|
+
entry.base = undefined;
|
|
509
|
+
entry.stale = false;
|
|
510
|
+
entry.version += 1;
|
|
511
|
+
entry.snapshot = { data: undefined, error, isFetching: false };
|
|
512
|
+
for (const projection of this.projections) {
|
|
513
|
+
projection.transforms.delete(entry);
|
|
514
|
+
}
|
|
515
|
+
this.publish(entry);
|
|
516
|
+
}
|
|
477
517
|
version(url) {
|
|
478
518
|
return this.entry(url).version;
|
|
479
519
|
}
|
|
@@ -515,7 +555,7 @@ class QueryStore {
|
|
|
515
555
|
const { epoch } = this;
|
|
516
556
|
entry.snapshot = { ...entry.snapshot, isFetching: true };
|
|
517
557
|
this.publish(entry);
|
|
518
|
-
|
|
558
|
+
const promise = Promise.resolve().then(() => entry.load?.()).then((result) => {
|
|
519
559
|
if (!result || epoch !== this.epoch || version !== entry.version || this.pending(entry)) {
|
|
520
560
|
return;
|
|
521
561
|
}
|
|
@@ -529,6 +569,9 @@ class QueryStore {
|
|
|
529
569
|
entry.snapshot = { ...entry.snapshot, error };
|
|
530
570
|
}
|
|
531
571
|
}).finally(() => {
|
|
572
|
+
if (entry.promise !== promise) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
532
575
|
entry.promise = undefined;
|
|
533
576
|
entry.snapshot = { ...entry.snapshot, isFetching: false };
|
|
534
577
|
this.publish(entry);
|
|
@@ -536,13 +579,14 @@ class QueryStore {
|
|
|
536
579
|
this.fetch(url);
|
|
537
580
|
}
|
|
538
581
|
});
|
|
539
|
-
|
|
582
|
+
entry.promise = promise;
|
|
583
|
+
return promise;
|
|
540
584
|
}
|
|
541
585
|
invalidate(identities) {
|
|
542
586
|
const tags = new Set(identities.map(queryTag));
|
|
543
587
|
let affected = false;
|
|
544
588
|
for (const [url, entry] of this.entries) {
|
|
545
|
-
if (entry.identity && queryTags(entry.identity).some((tag) => tags.has(tag))) {
|
|
589
|
+
if (entry.identity && queryTags(entry.identity).some((tag) => tags.has(tag)) || !entry.identity && entry.load && identities.length > 0) {
|
|
546
590
|
affected = true;
|
|
547
591
|
this.invalidateEntry(url, entry);
|
|
548
592
|
}
|
|
@@ -849,4 +893,143 @@ function getRouteApi2(pattern) {
|
|
|
849
893
|
};
|
|
850
894
|
}
|
|
851
895
|
|
|
852
|
-
|
|
896
|
+
// src/client/router/abort.ts
|
|
897
|
+
function isAbortError(error) {
|
|
898
|
+
return error !== null && typeof error === "object" && "name" in error && error.name === "AbortError";
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// src/client/sync-catch-up.ts
|
|
902
|
+
var LAYOUT_SUFFIX_RE = /:layout$/;
|
|
903
|
+
var RESET_REFRESH_INTERVAL_MS = 1000;
|
|
904
|
+
function changeInvalidations(change) {
|
|
905
|
+
const paths = [];
|
|
906
|
+
const queries = [...change.queries ?? []];
|
|
907
|
+
for (const entry of change.invalidations) {
|
|
908
|
+
if (typeof entry === "string") {
|
|
909
|
+
const trimmed = entry.trim();
|
|
910
|
+
const type = trimmed.endsWith(":layout") ? "layout" : "page";
|
|
911
|
+
const path = trimmed.replace(LAYOUT_SUFFIX_RE, "");
|
|
912
|
+
paths.push(encodeInvalidationEntry(path, type));
|
|
913
|
+
} else if (entry.kind === "path") {
|
|
914
|
+
paths.push(encodeInvalidationEntry(entry.path, entry.type));
|
|
915
|
+
} else {
|
|
916
|
+
for (const tag of entry.tags) {
|
|
917
|
+
const identity = queryFromTag(tag);
|
|
918
|
+
if (identity) {
|
|
919
|
+
queries.push(identity);
|
|
920
|
+
} else {
|
|
921
|
+
paths.push("/:layout");
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return { paths, queries };
|
|
927
|
+
}
|
|
928
|
+
function createInvalidationRefresh(options) {
|
|
929
|
+
let running;
|
|
930
|
+
let requested = false;
|
|
931
|
+
const refreshUntilCurrent = async () => {
|
|
932
|
+
do {
|
|
933
|
+
requested = false;
|
|
934
|
+
try {
|
|
935
|
+
await options.refresh();
|
|
936
|
+
} catch (error) {
|
|
937
|
+
if (!isAbortError(error)) {
|
|
938
|
+
throw error;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
} while (requested);
|
|
942
|
+
};
|
|
943
|
+
return {
|
|
944
|
+
run() {
|
|
945
|
+
requested = true;
|
|
946
|
+
if (!running) {
|
|
947
|
+
running = refreshUntilCurrent().catch((error) => {
|
|
948
|
+
if (!isAbortError(error)) {
|
|
949
|
+
options.onError(error);
|
|
950
|
+
}
|
|
951
|
+
}).finally(() => {
|
|
952
|
+
running = undefined;
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
return running;
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
function createSyncCatchUp(options) {
|
|
960
|
+
let currentCursor;
|
|
961
|
+
let running;
|
|
962
|
+
let requested = false;
|
|
963
|
+
let lastReset = Number.NEGATIVE_INFINITY;
|
|
964
|
+
let pendingReset;
|
|
965
|
+
let closed = false;
|
|
966
|
+
const refreshAfterReset = () => {
|
|
967
|
+
pendingReset = undefined;
|
|
968
|
+
lastReset = Date.now();
|
|
969
|
+
options.onReset?.();
|
|
970
|
+
options.onInvalidations(["/:layout"]);
|
|
971
|
+
};
|
|
972
|
+
const scheduleResetRefresh = () => {
|
|
973
|
+
if (pendingReset) {
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
const wait = lastReset + RESET_REFRESH_INTERVAL_MS - Date.now();
|
|
977
|
+
if (wait <= 0) {
|
|
978
|
+
refreshAfterReset();
|
|
979
|
+
} else {
|
|
980
|
+
pendingReset = setTimeout(refreshAfterReset, wait);
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
const readUntilCurrent = async () => {
|
|
984
|
+
do {
|
|
985
|
+
requested = false;
|
|
986
|
+
let page;
|
|
987
|
+
do {
|
|
988
|
+
page = await options.fetchPage(currentCursor ?? "0");
|
|
989
|
+
if (closed) {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (page.reset) {
|
|
993
|
+
currentCursor = page.cursor;
|
|
994
|
+
scheduleResetRefresh();
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
for (const change of page.changes) {
|
|
998
|
+
applyChange(change);
|
|
999
|
+
}
|
|
1000
|
+
currentCursor = page.cursor;
|
|
1001
|
+
} while (page.hasMore);
|
|
1002
|
+
} while (requested && !closed);
|
|
1003
|
+
};
|
|
1004
|
+
const applyChange = (change) => {
|
|
1005
|
+
const { paths, queries } = changeInvalidations(change);
|
|
1006
|
+
options.onInvalidations(paths);
|
|
1007
|
+
if (queries.length > 0) {
|
|
1008
|
+
options.onQueries?.(queries);
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
return {
|
|
1012
|
+
catchUp() {
|
|
1013
|
+
if (closed) {
|
|
1014
|
+
return Promise.resolve();
|
|
1015
|
+
}
|
|
1016
|
+
requested = true;
|
|
1017
|
+
if (!running) {
|
|
1018
|
+
running = readUntilCurrent().finally(() => {
|
|
1019
|
+
running = undefined;
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
return running;
|
|
1023
|
+
},
|
|
1024
|
+
cursor: () => currentCursor,
|
|
1025
|
+
close() {
|
|
1026
|
+
closed = true;
|
|
1027
|
+
clearTimeout(pendingReset);
|
|
1028
|
+
},
|
|
1029
|
+
seed(cursor) {
|
|
1030
|
+
currentCursor ??= cursor;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
export { DocumentProvider2, useDocumentState, HeadContent2, Scripts2, FurinDocumentFallback, createRequestId, mergeQuerySeeds, queryTag, queryTags, LIVE_QUERY, currentQueryEnvironment, QueryStore, SYNC_REQUEST, registerOptimisticRuntime, findOptimisticRuntime, createOptimisticRuntime, QueryStoreContext, useQuery2, withRouteSnapshot, getRouteApi2, isAbortError, createInvalidationRefresh, createSyncCatchUp };
|
|
@@ -52,13 +52,15 @@ const initialState = stateElement
|
|
|
52
52
|
: undefined;
|
|
53
53
|
const endpointSuffix = "/_furin/dev/overlay.js";
|
|
54
54
|
const blobFramePattern = /blob:https?:\/\/[^\s)]+?(?=:\d+:\d+\)?(?:\n|$))/g;
|
|
55
|
-
const sourceMapPattern =
|
|
55
|
+
const sourceMapPattern = /^\s*\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/m;
|
|
56
56
|
const clientUrl = new URL(import.meta.url);
|
|
57
57
|
const inferredBasePath = clientUrl.pathname.endsWith(endpointSuffix)
|
|
58
58
|
? clientUrl.pathname.slice(0, -endpointSuffix.length)
|
|
59
59
|
: "";
|
|
60
60
|
const basePath = initialState?.basePath ?? inferredBasePath;
|
|
61
61
|
let currentEvent = initialState?.event;
|
|
62
|
+
let clientRenderFailed = false;
|
|
63
|
+
let recoverAfterUpdate = false;
|
|
62
64
|
let coldFailure = initialState !== undefined;
|
|
63
65
|
let host: HTMLDivElement | undefined;
|
|
64
66
|
|
|
@@ -178,9 +180,24 @@ async function reportClientError(detail: ClientErrorDetail): Promise<void> {
|
|
|
178
180
|
|
|
179
181
|
window.addEventListener("furin:client-error", (event) => {
|
|
180
182
|
const { detail } = event as CustomEvent<ClientErrorDetail>;
|
|
183
|
+
if (detail.phase === "client-render") {
|
|
184
|
+
clientRenderFailed = true;
|
|
185
|
+
}
|
|
181
186
|
reportClientError(detail).catch(() => undefined);
|
|
182
187
|
});
|
|
183
188
|
|
|
189
|
+
// Retry only failures from before this update, including when reporting is still
|
|
190
|
+
// in flight or server readiness has already dismissed the overlay.
|
|
191
|
+
window.addEventListener("furin:hmr-before-update", () => {
|
|
192
|
+
recoverAfterUpdate = clientRenderFailed;
|
|
193
|
+
});
|
|
194
|
+
window.addEventListener("furin:hmr-after-update", () => {
|
|
195
|
+
if (recoverAfterUpdate) {
|
|
196
|
+
recoverAfterUpdate = false;
|
|
197
|
+
window.location.reload();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
184
201
|
if (currentEvent) {
|
|
185
202
|
render(currentEvent);
|
|
186
203
|
}
|
package/dist/client/link.js
CHANGED
|
@@ -5,14 +5,16 @@ import {
|
|
|
5
5
|
mergeQuerySeeds,
|
|
6
6
|
queryTag,
|
|
7
7
|
queryTags,
|
|
8
|
-
queryFromTag,
|
|
9
8
|
QueryStore,
|
|
10
9
|
SYNC_REQUEST,
|
|
11
10
|
registerOptimisticRuntime,
|
|
12
11
|
createOptimisticRuntime,
|
|
13
12
|
QueryStoreContext,
|
|
14
|
-
withRouteSnapshot
|
|
15
|
-
|
|
13
|
+
withRouteSnapshot,
|
|
14
|
+
isAbortError,
|
|
15
|
+
createInvalidationRefresh,
|
|
16
|
+
createSyncCatchUp
|
|
17
|
+
} from "./chunks/client-rjhxgt64.js";
|
|
16
18
|
import {
|
|
17
19
|
restoreRscSource2
|
|
18
20
|
} from "./chunks/client-k88668k7.js";
|
|
@@ -23,7 +25,6 @@ import {
|
|
|
23
25
|
import {
|
|
24
26
|
physicalPath,
|
|
25
27
|
isWithinPrefix,
|
|
26
|
-
encodeInvalidationEntry,
|
|
27
28
|
findSearchDefaultsForRouteTarget,
|
|
28
29
|
TRAILING_SLASHES_RE,
|
|
29
30
|
navigationHrefPolicy,
|
|
@@ -715,6 +716,16 @@ function collectRouteChainFromRoute(route) {
|
|
|
715
716
|
return chain;
|
|
716
717
|
}
|
|
717
718
|
|
|
719
|
+
// src/client/browser-events.ts
|
|
720
|
+
var BROWSER_EVENT_RUNTIME_KEY = Symbol.for("furin.browser-events.runtime");
|
|
721
|
+
function setBrowserSyncAuthentication(authorized) {
|
|
722
|
+
globalThis[BROWSER_EVENT_RUNTIME_KEY]?.setSyncAuthentication?.(authorized);
|
|
723
|
+
}
|
|
724
|
+
function subscribeBrowserEvent(channel, listener) {
|
|
725
|
+
const runtime = globalThis[BROWSER_EVENT_RUNTIME_KEY];
|
|
726
|
+
return runtime?.subscribe(channel, listener);
|
|
727
|
+
}
|
|
728
|
+
|
|
718
729
|
// src/client/route-element.tsx
|
|
719
730
|
import { createElement } from "react";
|
|
720
731
|
|
|
@@ -894,6 +905,7 @@ class NavigationController {
|
|
|
894
905
|
#version = 0;
|
|
895
906
|
#pendingAbort = null;
|
|
896
907
|
#committedAbort = null;
|
|
908
|
+
#contextAbort = new AbortController;
|
|
897
909
|
#pendingUserNavigation = null;
|
|
898
910
|
#renderedHistoryKey;
|
|
899
911
|
#pendingScroll = null;
|
|
@@ -942,7 +954,12 @@ class NavigationController {
|
|
|
942
954
|
const generation = this.#generation.current;
|
|
943
955
|
const entry = {
|
|
944
956
|
createdAt: Date.now(),
|
|
945
|
-
promise: this.#config.fetchPage({
|
|
957
|
+
promise: this.#config.fetchPage({
|
|
958
|
+
currentMatch: this.#currentMatch,
|
|
959
|
+
hmrRefresh: false,
|
|
960
|
+
href,
|
|
961
|
+
signal: this.#contextAbort.signal
|
|
962
|
+
}).then((result) => ({ generation, result, revision: undefined })),
|
|
946
963
|
staleTime: staleTime ?? this.#config.defaultStaleTime
|
|
947
964
|
};
|
|
948
965
|
this.#store(href, entry);
|
|
@@ -964,6 +981,23 @@ class NavigationController {
|
|
|
964
981
|
}
|
|
965
982
|
}
|
|
966
983
|
};
|
|
984
|
+
invalidateContext() {
|
|
985
|
+
this.#version += 1;
|
|
986
|
+
const pendingAbort = this.#pendingAbort;
|
|
987
|
+
const committedAbort = this.#committedAbort;
|
|
988
|
+
const contextAbort = this.#contextAbort;
|
|
989
|
+
const pendingNavigation = this.#pendingUserNavigation;
|
|
990
|
+
this.#pendingAbort = null;
|
|
991
|
+
this.#committedAbort = null;
|
|
992
|
+
this.#contextAbort = new AbortController;
|
|
993
|
+
this.#pendingUserNavigation = null;
|
|
994
|
+
this.invalidatePath("/", "layout");
|
|
995
|
+
this.#setNavigating(false);
|
|
996
|
+
pendingAbort?.abort();
|
|
997
|
+
committedAbort?.abort();
|
|
998
|
+
contextAbort.abort();
|
|
999
|
+
pendingNavigation?.resolve();
|
|
1000
|
+
}
|
|
967
1001
|
invalidateQueries(affected) {
|
|
968
1002
|
this.#generation.bump((_href, state) => affected(state));
|
|
969
1003
|
for (const [href, entry] of this.#cache) {
|
|
@@ -981,7 +1015,7 @@ class NavigationController {
|
|
|
981
1015
|
}
|
|
982
1016
|
async waitForUserNavigation() {
|
|
983
1017
|
while (this.#pendingUserNavigation) {
|
|
984
|
-
await this.#pendingUserNavigation;
|
|
1018
|
+
await this.#pendingUserNavigation.promise;
|
|
985
1019
|
}
|
|
986
1020
|
}
|
|
987
1021
|
adoptHistoryEntry() {
|
|
@@ -1019,18 +1053,14 @@ class NavigationController {
|
|
|
1019
1053
|
}
|
|
1020
1054
|
}
|
|
1021
1055
|
#beginUserNavigation() {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
const promise = new Promise((settle) => {
|
|
1026
|
-
resolve = settle;
|
|
1027
|
-
});
|
|
1028
|
-
this.#pendingUserNavigation = promise;
|
|
1056
|
+
this.#pendingUserNavigation?.resolve();
|
|
1057
|
+
const navigation = Promise.withResolvers();
|
|
1058
|
+
this.#pendingUserNavigation = navigation;
|
|
1029
1059
|
return () => {
|
|
1030
|
-
if (this.#pendingUserNavigation ===
|
|
1060
|
+
if (this.#pendingUserNavigation === navigation) {
|
|
1031
1061
|
this.#pendingUserNavigation = null;
|
|
1032
1062
|
}
|
|
1033
|
-
resolve();
|
|
1063
|
+
navigation.resolve();
|
|
1034
1064
|
};
|
|
1035
1065
|
}
|
|
1036
1066
|
#startAbort() {
|
|
@@ -1056,11 +1086,21 @@ class NavigationController {
|
|
|
1056
1086
|
this.#version += 1;
|
|
1057
1087
|
const version = this.#version;
|
|
1058
1088
|
const abort = this.#startAbort();
|
|
1089
|
+
const cancelled = Promise.withResolvers();
|
|
1090
|
+
const onAbort = () => cancelled.resolve(false);
|
|
1091
|
+
abort.signal.addEventListener("abort", onAbort, { once: true });
|
|
1059
1092
|
let committed = false;
|
|
1060
1093
|
this.#setNavigating(true);
|
|
1061
1094
|
try {
|
|
1062
|
-
|
|
1095
|
+
if (abort.signal.aborted) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
committed = await Promise.race([
|
|
1099
|
+
this.#load(href, kind, version, abort.signal),
|
|
1100
|
+
cancelled.promise
|
|
1101
|
+
]);
|
|
1063
1102
|
} finally {
|
|
1103
|
+
abort.signal.removeEventListener("abort", onAbort);
|
|
1064
1104
|
this.#settleAbort(abort, committed);
|
|
1065
1105
|
finishUserNavigation?.();
|
|
1066
1106
|
if (this.#version === version) {
|
|
@@ -2734,11 +2774,6 @@ async function readDeferredLines(readLine, resolvers) {
|
|
|
2734
2774
|
}
|
|
2735
2775
|
}
|
|
2736
2776
|
|
|
2737
|
-
// src/client/router/abort.ts
|
|
2738
|
-
function isAbortError(error) {
|
|
2739
|
-
return error !== null && typeof error === "object" && "name" in error && error.name === "AbortError";
|
|
2740
|
-
}
|
|
2741
|
-
|
|
2742
2777
|
// src/shared/navigation-data.ts
|
|
2743
2778
|
var NAVIGATION_DATA_TOKEN = "_furin=data";
|
|
2744
2779
|
function navigationDataHref(href) {
|
|
@@ -2949,126 +2984,6 @@ async function fetchPageState(context, rawLogicalHref, signal, hmrRefresh) {
|
|
|
2949
2984
|
}
|
|
2950
2985
|
}
|
|
2951
2986
|
|
|
2952
|
-
// src/client/router/sync-catch-up.ts
|
|
2953
|
-
var LAYOUT_SUFFIX_RE = /:layout$/;
|
|
2954
|
-
var RESET_REFRESH_INTERVAL_MS = 1000;
|
|
2955
|
-
function changeInvalidations(change) {
|
|
2956
|
-
const paths = [];
|
|
2957
|
-
const queries = [...change.queries ?? []];
|
|
2958
|
-
for (const entry of change.invalidations) {
|
|
2959
|
-
if (typeof entry === "string") {
|
|
2960
|
-
const trimmed = entry.trim();
|
|
2961
|
-
const type = trimmed.endsWith(":layout") ? "layout" : "page";
|
|
2962
|
-
const path = trimmed.replace(LAYOUT_SUFFIX_RE, "");
|
|
2963
|
-
paths.push(encodeInvalidationEntry(path, type));
|
|
2964
|
-
} else if (entry.kind === "path") {
|
|
2965
|
-
paths.push(encodeInvalidationEntry(entry.path, entry.type));
|
|
2966
|
-
} else {
|
|
2967
|
-
for (const tag of entry.tags) {
|
|
2968
|
-
const identity = queryFromTag(tag);
|
|
2969
|
-
if (identity) {
|
|
2970
|
-
queries.push(identity);
|
|
2971
|
-
} else {
|
|
2972
|
-
paths.push("/:layout");
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
return { paths, queries };
|
|
2978
|
-
}
|
|
2979
|
-
function createInvalidationRefresh(options) {
|
|
2980
|
-
let running;
|
|
2981
|
-
let requested = false;
|
|
2982
|
-
const refreshUntilCurrent = async () => {
|
|
2983
|
-
do {
|
|
2984
|
-
requested = false;
|
|
2985
|
-
try {
|
|
2986
|
-
await options.refresh();
|
|
2987
|
-
} catch (error) {
|
|
2988
|
-
if (!isAbortError(error)) {
|
|
2989
|
-
throw error;
|
|
2990
|
-
}
|
|
2991
|
-
}
|
|
2992
|
-
} while (requested);
|
|
2993
|
-
};
|
|
2994
|
-
return {
|
|
2995
|
-
run() {
|
|
2996
|
-
requested = true;
|
|
2997
|
-
if (!running) {
|
|
2998
|
-
running = refreshUntilCurrent().catch((error) => {
|
|
2999
|
-
if (!isAbortError(error)) {
|
|
3000
|
-
options.onError(error);
|
|
3001
|
-
}
|
|
3002
|
-
}).finally(() => {
|
|
3003
|
-
running = undefined;
|
|
3004
|
-
});
|
|
3005
|
-
}
|
|
3006
|
-
return running;
|
|
3007
|
-
}
|
|
3008
|
-
};
|
|
3009
|
-
}
|
|
3010
|
-
function createSyncCatchUp(options) {
|
|
3011
|
-
let currentCursor;
|
|
3012
|
-
let running;
|
|
3013
|
-
let requested = false;
|
|
3014
|
-
let lastReset = Number.NEGATIVE_INFINITY;
|
|
3015
|
-
let pendingReset;
|
|
3016
|
-
const refreshAfterReset = () => {
|
|
3017
|
-
pendingReset = undefined;
|
|
3018
|
-
lastReset = Date.now();
|
|
3019
|
-
options.onReset?.();
|
|
3020
|
-
options.onInvalidations(["/:layout"]);
|
|
3021
|
-
};
|
|
3022
|
-
const scheduleResetRefresh = () => {
|
|
3023
|
-
if (pendingReset) {
|
|
3024
|
-
return;
|
|
3025
|
-
}
|
|
3026
|
-
const wait = lastReset + RESET_REFRESH_INTERVAL_MS - Date.now();
|
|
3027
|
-
if (wait <= 0) {
|
|
3028
|
-
refreshAfterReset();
|
|
3029
|
-
} else {
|
|
3030
|
-
pendingReset = setTimeout(refreshAfterReset, wait);
|
|
3031
|
-
}
|
|
3032
|
-
};
|
|
3033
|
-
const readUntilCurrent = async () => {
|
|
3034
|
-
do {
|
|
3035
|
-
requested = false;
|
|
3036
|
-
let page;
|
|
3037
|
-
do {
|
|
3038
|
-
page = await options.fetchPage(currentCursor ?? "0");
|
|
3039
|
-
if (page.reset) {
|
|
3040
|
-
currentCursor = page.cursor;
|
|
3041
|
-
scheduleResetRefresh();
|
|
3042
|
-
break;
|
|
3043
|
-
}
|
|
3044
|
-
for (const change of page.changes) {
|
|
3045
|
-
const { paths, queries } = changeInvalidations(change);
|
|
3046
|
-
options.onInvalidations(paths);
|
|
3047
|
-
if (queries.length > 0) {
|
|
3048
|
-
options.onQueries?.(queries);
|
|
3049
|
-
}
|
|
3050
|
-
}
|
|
3051
|
-
currentCursor = page.cursor;
|
|
3052
|
-
} while (page.hasMore);
|
|
3053
|
-
} while (requested);
|
|
3054
|
-
};
|
|
3055
|
-
return {
|
|
3056
|
-
catchUp() {
|
|
3057
|
-
requested = true;
|
|
3058
|
-
if (!running) {
|
|
3059
|
-
running = readUntilCurrent().finally(() => {
|
|
3060
|
-
running = undefined;
|
|
3061
|
-
});
|
|
3062
|
-
}
|
|
3063
|
-
return running;
|
|
3064
|
-
},
|
|
3065
|
-
cursor: () => currentCursor,
|
|
3066
|
-
seed(cursor) {
|
|
3067
|
-
currentCursor ??= cursor;
|
|
3068
|
-
}
|
|
3069
|
-
};
|
|
3070
|
-
}
|
|
3071
|
-
|
|
3072
2987
|
// src/client/router/use-fetch-interception.ts
|
|
3073
2988
|
import { useEffect } from "react";
|
|
3074
2989
|
|
|
@@ -3248,15 +3163,6 @@ function useHmrRefresh(controller) {
|
|
|
3248
3163
|
// src/client/router/use-sync-stream.ts
|
|
3249
3164
|
import { log as log3 } from "evlog";
|
|
3250
3165
|
import { useEffect as useEffect4 } from "react";
|
|
3251
|
-
|
|
3252
|
-
// src/client/browser-events.ts
|
|
3253
|
-
var BROWSER_EVENT_RUNTIME_KEY = Symbol.for("furin.browser-events.runtime");
|
|
3254
|
-
function subscribeBrowserEvent(channel, listener) {
|
|
3255
|
-
const runtime = globalThis[BROWSER_EVENT_RUNTIME_KEY];
|
|
3256
|
-
return runtime?.subscribe(channel, listener);
|
|
3257
|
-
}
|
|
3258
|
-
|
|
3259
|
-
// src/client/router/use-sync-stream.ts
|
|
3260
3166
|
function useSyncStream(options) {
|
|
3261
3167
|
const { autoRefresh, basePath, controller, invalidationRefresh, queries, syncPath } = options;
|
|
3262
3168
|
useEffect4(() => {
|
|
@@ -3266,6 +3172,24 @@ function useSyncStream(options) {
|
|
|
3266
3172
|
const changesUrl = syncPath.startsWith("/") ? `${basePath}${syncPath}` : `${basePath}/${syncPath}`;
|
|
3267
3173
|
let unsubscribe;
|
|
3268
3174
|
let disposed = false;
|
|
3175
|
+
let requestController = new AbortController;
|
|
3176
|
+
let contextChanged = false;
|
|
3177
|
+
let session;
|
|
3178
|
+
const clearContext = () => {
|
|
3179
|
+
contextChanged = true;
|
|
3180
|
+
queries.clear();
|
|
3181
|
+
controller.invalidateContext();
|
|
3182
|
+
};
|
|
3183
|
+
const observeSession = (response) => {
|
|
3184
|
+
const identity = response.headers.get("x-furin-sync-session");
|
|
3185
|
+
if (identity === null) {
|
|
3186
|
+
return;
|
|
3187
|
+
}
|
|
3188
|
+
if (session !== undefined && identity !== session) {
|
|
3189
|
+
clearContext();
|
|
3190
|
+
}
|
|
3191
|
+
session = identity;
|
|
3192
|
+
};
|
|
3269
3193
|
const applyInvalidations = (entries) => {
|
|
3270
3194
|
if (disposed) {
|
|
3271
3195
|
return;
|
|
@@ -3283,17 +3207,26 @@ function useSyncStream(options) {
|
|
|
3283
3207
|
}
|
|
3284
3208
|
}
|
|
3285
3209
|
};
|
|
3286
|
-
const
|
|
3210
|
+
const createRecovery = () => createSyncCatchUp({
|
|
3287
3211
|
fetchPage: async (after) => {
|
|
3288
3212
|
const url = new URL(`${changesUrl}/changes`, window.location.origin);
|
|
3289
3213
|
if (after !== undefined) {
|
|
3290
3214
|
url.searchParams.set("after", after);
|
|
3291
3215
|
}
|
|
3292
|
-
const
|
|
3216
|
+
const { signal } = requestController;
|
|
3217
|
+
const response = await window.fetch(url, { signal });
|
|
3218
|
+
signal.throwIfAborted();
|
|
3219
|
+
if (response.status === 401 || response.status === 403) {
|
|
3220
|
+
clearContext();
|
|
3221
|
+
setBrowserSyncAuthentication(false);
|
|
3222
|
+
}
|
|
3293
3223
|
if (!response.ok) {
|
|
3294
3224
|
throw new Error(`Sync catch-up failed with status ${response.status}`);
|
|
3295
3225
|
}
|
|
3296
|
-
|
|
3226
|
+
const page = await response.json();
|
|
3227
|
+
signal.throwIfAborted();
|
|
3228
|
+
observeSession(response);
|
|
3229
|
+
return page;
|
|
3297
3230
|
},
|
|
3298
3231
|
onInvalidations: applyInvalidations,
|
|
3299
3232
|
onReset: () => {
|
|
@@ -3311,22 +3244,38 @@ function useSyncStream(options) {
|
|
|
3311
3244
|
}
|
|
3312
3245
|
}
|
|
3313
3246
|
});
|
|
3247
|
+
let catchUp = createRecovery();
|
|
3314
3248
|
const recover = () => {
|
|
3315
3249
|
if (disposed) {
|
|
3316
3250
|
return;
|
|
3317
3251
|
}
|
|
3318
|
-
|
|
3252
|
+
const current = catchUp;
|
|
3253
|
+
current.catchUp().then(() => {
|
|
3254
|
+
if (!disposed && catchUp === current && contextChanged) {
|
|
3255
|
+
contextChanged = false;
|
|
3256
|
+
queries.invalidateAll();
|
|
3257
|
+
applyInvalidations(["/:layout"]);
|
|
3258
|
+
}
|
|
3259
|
+
}).catch((error) => {
|
|
3319
3260
|
if (!disposed) {
|
|
3320
3261
|
log3.warn({ action: "sync_catch_up_failed", error: String(error) });
|
|
3321
3262
|
}
|
|
3322
3263
|
});
|
|
3323
3264
|
};
|
|
3324
3265
|
const onSync = (event) => {
|
|
3266
|
+
if (event.data.context === "changed") {
|
|
3267
|
+
requestController.abort();
|
|
3268
|
+
requestController = new AbortController;
|
|
3269
|
+
catchUp.close();
|
|
3270
|
+
catchUp = createRecovery();
|
|
3271
|
+
clearContext();
|
|
3272
|
+
recover();
|
|
3273
|
+
return;
|
|
3274
|
+
}
|
|
3325
3275
|
if (typeof event.data.cursor !== "string") {
|
|
3326
3276
|
log3.warn({ action: "sync_invalid_event", event: "browser-events.sync" });
|
|
3327
3277
|
return;
|
|
3328
3278
|
}
|
|
3329
|
-
catchUp.seed(event.data.cursor);
|
|
3330
3279
|
recover();
|
|
3331
3280
|
};
|
|
3332
3281
|
const connect = () => {
|
|
@@ -3341,6 +3290,8 @@ function useSyncStream(options) {
|
|
|
3341
3290
|
connect();
|
|
3342
3291
|
return () => {
|
|
3343
3292
|
disposed = true;
|
|
3293
|
+
requestController.abort();
|
|
3294
|
+
catchUp.close();
|
|
3344
3295
|
unsubscribe?.();
|
|
3345
3296
|
};
|
|
3346
3297
|
}, [syncPath, basePath, invalidationRefresh, autoRefresh, queries, controller]);
|
|
@@ -3606,7 +3557,10 @@ function RouterProvider({
|
|
|
3606
3557
|
invalidatePrefetch,
|
|
3607
3558
|
navigate,
|
|
3608
3559
|
prefetch,
|
|
3609
|
-
refresh
|
|
3560
|
+
refresh: (options) => {
|
|
3561
|
+
setBrowserSyncAuthentication(true);
|
|
3562
|
+
return refresh(options);
|
|
3563
|
+
},
|
|
3610
3564
|
searchRoutes: routes
|
|
3611
3565
|
}), [
|
|
3612
3566
|
basePath,
|