@teyik0/furin 0.9.0-alpha.3 → 0.9.0-alpha.4
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/client/chunks/{client-d9v49jwz.js → client-p0jqzfvc.js} +65 -2
- package/dist/client/link.js +1 -1
- package/dist/client/query.d.ts +13 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +3 -1
- package/dist/furin.js +4 -14
- package/dist/server/dev/graph.d.ts +0 -1
- package/dist/server/internal.js +4 -7
- package/dist/server/router/hmr.d.ts +0 -1
- package/dist/server/router/source-version.d.ts +0 -1
- package/dist/server/static-export.js +4 -7
- package/dist/server/sync/index.js +1 -1
- package/dist/sync-client.js +1 -1
- package/package.json +1 -1
- package/src/client/query-store.ts +2 -1
- package/src/client/query.tsx +87 -0
- package/src/client.ts +1 -1
- package/src/server/dev/graph.ts +2 -7
- package/src/server/dev/runtime.ts +1 -2
- package/src/server/router/hmr.ts +1 -5
- package/src/server/router/source-version.ts +3 -6
|
@@ -391,10 +391,10 @@ class QueryStore {
|
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
entry.snapshot = { ...entry.snapshot, data };
|
|
394
|
+
this.revisionValue += 1;
|
|
394
395
|
for (const listener of entry.listeners) {
|
|
395
396
|
listener();
|
|
396
397
|
}
|
|
397
|
-
this.revisionValue += 1;
|
|
398
398
|
for (const listener of this.listeners) {
|
|
399
399
|
listener();
|
|
400
400
|
}
|
|
@@ -826,6 +826,7 @@ import {
|
|
|
826
826
|
useCallback,
|
|
827
827
|
useContext as useContext2,
|
|
828
828
|
useEffect,
|
|
829
|
+
useState,
|
|
829
830
|
useSyncExternalStore
|
|
830
831
|
} from "react";
|
|
831
832
|
var QUERY_CONTEXT = Symbol.for("furin.query.context.v1");
|
|
@@ -854,6 +855,68 @@ function useQuery2(query, options) {
|
|
|
854
855
|
isFetching: state.isFetching
|
|
855
856
|
};
|
|
856
857
|
}
|
|
858
|
+
function useInfiniteQuery2(page, options) {
|
|
859
|
+
const first = page(0)[LIVE_QUERY];
|
|
860
|
+
const context = useContext2(QueryStoreContext);
|
|
861
|
+
const store = context ?? first.reference.client;
|
|
862
|
+
const firstUrl = store.readKey(first.reference, first.options);
|
|
863
|
+
const [loaded, setLoaded] = useState({ count: 1, firstUrl });
|
|
864
|
+
if (loaded.firstUrl !== firstUrl) {
|
|
865
|
+
setLoaded({ count: 1, firstUrl });
|
|
866
|
+
}
|
|
867
|
+
const count = loaded.firstUrl === firstUrl ? loaded.count : 1;
|
|
868
|
+
const urls = Array.from({ length: count }, (_, index) => {
|
|
869
|
+
const { options: readOptions, reference } = page(index)[LIVE_QUERY];
|
|
870
|
+
const url = store.readKey(reference, readOptions);
|
|
871
|
+
store.bind(url, () => reference.load(readOptions), reference.client);
|
|
872
|
+
return url;
|
|
873
|
+
});
|
|
874
|
+
const key = urls.join(`
|
|
875
|
+
`);
|
|
876
|
+
const subscribe = useCallback((listener) => {
|
|
877
|
+
const unsubscribes = key.split(`
|
|
878
|
+
`).map((url) => store.subscribe(url, listener));
|
|
879
|
+
return () => {
|
|
880
|
+
for (const unsubscribe of unsubscribes) {
|
|
881
|
+
unsubscribe();
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
}, [store, key]);
|
|
885
|
+
useSyncExternalStore(subscribe, store.revision, store.revision);
|
|
886
|
+
useEffect(() => {
|
|
887
|
+
for (const url of key.split(`
|
|
888
|
+
`)) {
|
|
889
|
+
store.fetch(url);
|
|
890
|
+
}
|
|
891
|
+
}, [store, key]);
|
|
892
|
+
const snapshots = urls.map((url) => store.snapshot(url));
|
|
893
|
+
const pages = [];
|
|
894
|
+
for (const entry of snapshots) {
|
|
895
|
+
if (entry.data === undefined) {
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
pages.push(entry.data);
|
|
899
|
+
}
|
|
900
|
+
const last = pages.at(-1);
|
|
901
|
+
const hasNext = pages.length === count && last !== undefined && options.next(last);
|
|
902
|
+
const fetchNext = () => {
|
|
903
|
+
const failed = urls.filter((_, index) => snapshots[index]?.error !== null);
|
|
904
|
+
if (failed.length > 0) {
|
|
905
|
+
for (const url of failed) {
|
|
906
|
+
store.fetch(url);
|
|
907
|
+
}
|
|
908
|
+
} else if (hasNext) {
|
|
909
|
+
setLoaded((previous) => previous.firstUrl === firstUrl && previous.count === count ? { count: count + 1, firstUrl } : previous);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
return {
|
|
913
|
+
error: snapshots.find((entry) => entry.error !== null)?.error ?? null,
|
|
914
|
+
fetchNext,
|
|
915
|
+
hasNext,
|
|
916
|
+
isFetching: snapshots.some((entry) => entry.isFetching),
|
|
917
|
+
pages
|
|
918
|
+
};
|
|
919
|
+
}
|
|
857
920
|
|
|
858
921
|
// src/client/route-api.tsx
|
|
859
922
|
import { createContext as createContext3, createElement as createElement2, useContext as useContext3 } from "react";
|
|
@@ -1032,4 +1095,4 @@ function createSyncCatchUp(options) {
|
|
|
1032
1095
|
};
|
|
1033
1096
|
}
|
|
1034
1097
|
|
|
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 };
|
|
1098
|
+
export { DocumentProvider2, useDocumentState, HeadContent2, Scripts2, FurinDocumentFallback, createRequestId, mergeQuerySeeds, queryTag, queryTags, LIVE_QUERY, currentQueryEnvironment, QueryStore, SYNC_REQUEST, registerOptimisticRuntime, findOptimisticRuntime, createOptimisticRuntime, QueryStoreContext, useQuery2, useInfiniteQuery2, withRouteSnapshot, getRouteApi2, isAbortError, createInvalidationRefresh, createSyncCatchUp };
|
package/dist/client/link.js
CHANGED
package/dist/client/query.d.ts
CHANGED
|
@@ -9,4 +9,17 @@ export declare function useQuery<Result extends ReadResult, Selected = LiveData<
|
|
|
9
9
|
error: Result["error"] | null;
|
|
10
10
|
isFetching: boolean;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Pages are ordinary store entries keyed by their URL: invalidation refetches every loaded page.
|
|
14
|
+
* The hook owns only how many pages are shown; a new first page (changed filters) restarts at one.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useInfiniteQuery<Result extends ReadResult>(page: (index: number) => LiveQuery<Result>, options: {
|
|
17
|
+
next: (last: LiveData<Result>) => boolean;
|
|
18
|
+
}): {
|
|
19
|
+
error: Result["error"] | null;
|
|
20
|
+
fetchNext: () => void;
|
|
21
|
+
hasNext: boolean;
|
|
22
|
+
isFetching: boolean;
|
|
23
|
+
pages: LiveData<Result>[];
|
|
24
|
+
};
|
|
12
25
|
export {};
|
package/dist/client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { defineRootRoute, defineRoute } from "./client/define-route.ts";
|
|
|
3
3
|
export { type DocumentAssets, DocumentProvider, type DocumentState, HeadContent, Scripts, } from "./client/document.tsx";
|
|
4
4
|
export { type HotComponentRegistry, reconcileHotComponentRegistry, updateHotComponent, } from "./client/hmr.ts";
|
|
5
5
|
export { useMutation } from "./client/mutation.ts";
|
|
6
|
-
export { useQuery } from "./client/query.tsx";
|
|
6
|
+
export { useInfiniteQuery, useQuery } from "./client/query.tsx";
|
|
7
7
|
export type { LiveQuery } from "./client/query-store.ts";
|
|
8
8
|
export { getRouteApi } from "./client/route-api.tsx";
|
|
9
9
|
export { furinSync, type OptimisticCache, type SyncCallOptions } from "./client/sync.ts";
|
package/dist/client.js
CHANGED
|
@@ -9,9 +9,10 @@ import {
|
|
|
9
9
|
SYNC_REQUEST,
|
|
10
10
|
findOptimisticRuntime,
|
|
11
11
|
useQuery2,
|
|
12
|
+
useInfiniteQuery2,
|
|
12
13
|
getRouteApi2,
|
|
13
14
|
createSyncCatchUp
|
|
14
|
-
} from "./client/chunks/client-
|
|
15
|
+
} from "./client/chunks/client-p0jqzfvc.js";
|
|
15
16
|
|
|
16
17
|
// src/client/client-module.ts
|
|
17
18
|
import { preloadModule } from "react-dom";
|
|
@@ -1340,6 +1341,7 @@ export {
|
|
|
1340
1341
|
updateHotComponent,
|
|
1341
1342
|
useAsyncError,
|
|
1342
1343
|
useAsyncValue,
|
|
1344
|
+
useInfiniteQuery2 as useInfiniteQuery,
|
|
1343
1345
|
useMutation,
|
|
1344
1346
|
useQuery2 as useQuery
|
|
1345
1347
|
};
|
package/dist/furin.js
CHANGED
|
@@ -1318,7 +1318,6 @@ class DevGraph {
|
|
|
1318
1318
|
#eventSequence = 0;
|
|
1319
1319
|
#revision = 0;
|
|
1320
1320
|
#snapshot;
|
|
1321
|
-
#sourceGeneration = 0;
|
|
1322
1321
|
constructor(initialSnapshot) {
|
|
1323
1322
|
this.#snapshot = initialSnapshot;
|
|
1324
1323
|
}
|
|
@@ -1521,9 +1520,6 @@ class DevGraph {
|
|
|
1521
1520
|
}
|
|
1522
1521
|
}
|
|
1523
1522
|
}
|
|
1524
|
-
invalidateModules() {
|
|
1525
|
-
this.#sourceGeneration += 1;
|
|
1526
|
-
}
|
|
1527
1523
|
sourceVersion(path) {
|
|
1528
1524
|
const modulePath = normalizeModulePath(path);
|
|
1529
1525
|
const fingerprint = this.#sourceFingerprint(modulePath, new Set);
|
|
@@ -1543,9 +1539,9 @@ class DevGraph {
|
|
|
1543
1539
|
let ownFingerprint;
|
|
1544
1540
|
try {
|
|
1545
1541
|
const stats = statSync(path, { bigint: true });
|
|
1546
|
-
ownFingerprint = `${stats.mtimeNs}:${stats.size}
|
|
1542
|
+
ownFingerprint = `${stats.mtimeNs}:${stats.size}`;
|
|
1547
1543
|
} catch {
|
|
1548
|
-
ownFingerprint =
|
|
1544
|
+
ownFingerprint = "missing";
|
|
1549
1545
|
}
|
|
1550
1546
|
const dependencies = [...this.#dependencies.get(path) ?? []].toSorted((left, right) => left.localeCompare(right)).map((dependency) => this.#sourceFingerprint(dependency, visited));
|
|
1551
1547
|
return `${path}:${ownFingerprint}:${dependencies.join(",")}`;
|
|
@@ -4579,10 +4575,10 @@ class QueryStore {
|
|
|
4579
4575
|
}
|
|
4580
4576
|
}
|
|
4581
4577
|
entry.snapshot = { ...entry.snapshot, data };
|
|
4578
|
+
this.revisionValue += 1;
|
|
4582
4579
|
for (const listener of entry.listeners) {
|
|
4583
4580
|
listener();
|
|
4584
4581
|
}
|
|
4585
|
-
this.revisionValue += 1;
|
|
4586
4582
|
for (const listener of this.listeners) {
|
|
4587
4583
|
listener();
|
|
4588
4584
|
}
|
|
@@ -7951,9 +7947,6 @@ function routeModuleSourceVersion(path) {
|
|
|
7951
7947
|
});
|
|
7952
7948
|
return String(Math.max(...(relevant.length > 0 ? relevant : [current]).map((graph) => Number(graph.sourceVersion(path)))));
|
|
7953
7949
|
}
|
|
7954
|
-
function invalidateRouteModuleSourceVersions() {
|
|
7955
|
-
devGraph(undefined).invalidateModules();
|
|
7956
|
-
}
|
|
7957
7950
|
var init_source_version = __esm(() => {
|
|
7958
7951
|
init_graph();
|
|
7959
7952
|
init_instance();
|
|
@@ -10074,6 +10067,7 @@ import {
|
|
|
10074
10067
|
useCallback,
|
|
10075
10068
|
useContext as useContext2,
|
|
10076
10069
|
useEffect,
|
|
10070
|
+
useState,
|
|
10077
10071
|
useSyncExternalStore
|
|
10078
10072
|
} from "react";
|
|
10079
10073
|
var QUERY_CONTEXT2, contextGlobal2, QueryStoreContext;
|
|
@@ -16962,9 +16956,6 @@ function importStampedRouteModule(path, resolveImport) {
|
|
|
16962
16956
|
const stamp = routeModuleSourceVersion(path);
|
|
16963
16957
|
return devGraph(undefined).importModule(path, stamp, resolveImport);
|
|
16964
16958
|
}
|
|
16965
|
-
function invalidateStampedRouteModules() {
|
|
16966
|
-
invalidateRouteModuleSourceVersions();
|
|
16967
|
-
}
|
|
16968
16959
|
function isResolvedRouteModuleCandidate(layoutPath, imported, ctx) {
|
|
16969
16960
|
if (existsSync6(layoutPath) || ctx?.modules[layoutPath]) {
|
|
16970
16961
|
return true;
|
|
@@ -23629,7 +23620,6 @@ async function createDevRuntime(instance, resolvedPagesDir, style, options) {
|
|
|
23629
23620
|
reportRouteConfig();
|
|
23630
23621
|
const hmrEntry = (await import(join9(furinDir, "index.html"))).default;
|
|
23631
23622
|
const refreshDevelopmentRoutes = (changedSources) => withInstance(instance, async () => {
|
|
23632
|
-
invalidateStampedRouteModules();
|
|
23633
23623
|
try {
|
|
23634
23624
|
const previousSnapshot = currentSnapshot();
|
|
23635
23625
|
const repaired = repairedDevelopmentRoutes(previousSnapshot, changedSources, graph);
|
|
@@ -74,7 +74,6 @@ export declare class DevGraph<Snapshot> {
|
|
|
74
74
|
recordImports(importer: string, imports: string[]): void;
|
|
75
75
|
recordSourceError(message: string, position: DevSourcePosition): void;
|
|
76
76
|
sourceError(message: string, entryPath: string): DevSourcePosition | undefined;
|
|
77
|
-
invalidateModules(): void;
|
|
78
77
|
sourceVersion(path: string): string;
|
|
79
78
|
state<Value>(key: symbol, initialize: () => Value): Value;
|
|
80
79
|
subscribe(after: number, serverId: string | undefined, listener: (event: DevGraphEvent) => void): {
|
package/dist/server/internal.js
CHANGED
|
@@ -3363,7 +3363,6 @@ class DevGraph {
|
|
|
3363
3363
|
#eventSequence = 0;
|
|
3364
3364
|
#revision = 0;
|
|
3365
3365
|
#snapshot;
|
|
3366
|
-
#sourceGeneration = 0;
|
|
3367
3366
|
constructor(initialSnapshot) {
|
|
3368
3367
|
this.#snapshot = initialSnapshot;
|
|
3369
3368
|
}
|
|
@@ -3566,9 +3565,6 @@ class DevGraph {
|
|
|
3566
3565
|
}
|
|
3567
3566
|
}
|
|
3568
3567
|
}
|
|
3569
|
-
invalidateModules() {
|
|
3570
|
-
this.#sourceGeneration += 1;
|
|
3571
|
-
}
|
|
3572
3568
|
sourceVersion(path) {
|
|
3573
3569
|
const modulePath = normalizeModulePath(path);
|
|
3574
3570
|
const fingerprint = this.#sourceFingerprint(modulePath, new Set);
|
|
@@ -3588,9 +3584,9 @@ class DevGraph {
|
|
|
3588
3584
|
let ownFingerprint;
|
|
3589
3585
|
try {
|
|
3590
3586
|
const stats = statSync(path, { bigint: true });
|
|
3591
|
-
ownFingerprint = `${stats.mtimeNs}:${stats.size}
|
|
3587
|
+
ownFingerprint = `${stats.mtimeNs}:${stats.size}`;
|
|
3592
3588
|
} catch {
|
|
3593
|
-
ownFingerprint =
|
|
3589
|
+
ownFingerprint = "missing";
|
|
3594
3590
|
}
|
|
3595
3591
|
const dependencies = [...this.#dependencies.get(path) ?? []].toSorted((left, right) => left.localeCompare(right)).map((dependency) => this.#sourceFingerprint(dependency, visited));
|
|
3596
3592
|
return `${path}:${ownFingerprint}:${dependencies.join(",")}`;
|
|
@@ -4787,10 +4783,10 @@ class QueryStore {
|
|
|
4787
4783
|
}
|
|
4788
4784
|
}
|
|
4789
4785
|
entry.snapshot = { ...entry.snapshot, data };
|
|
4786
|
+
this.revisionValue += 1;
|
|
4790
4787
|
for (const listener of entry.listeners) {
|
|
4791
4788
|
listener();
|
|
4792
4789
|
}
|
|
4793
|
-
this.revisionValue += 1;
|
|
4794
4790
|
for (const listener of this.listeners) {
|
|
4795
4791
|
listener();
|
|
4796
4792
|
}
|
|
@@ -6142,6 +6138,7 @@ import {
|
|
|
6142
6138
|
useCallback,
|
|
6143
6139
|
useContext as useContext2,
|
|
6144
6140
|
useEffect,
|
|
6141
|
+
useState,
|
|
6145
6142
|
useSyncExternalStore
|
|
6146
6143
|
} from "react";
|
|
6147
6144
|
var QUERY_CONTEXT2 = Symbol.for("furin.query.context.v1");
|
|
@@ -11,7 +11,6 @@ type RouteModuleImport = (specifier: string) => Promise<CompiledModule>;
|
|
|
11
11
|
* requests for the same edited version.
|
|
12
12
|
*/
|
|
13
13
|
export declare function importStampedRouteModule(path: string, resolveImport: RouteModuleImport): Promise<CompiledModule>;
|
|
14
|
-
export declare function invalidateStampedRouteModules(): void;
|
|
15
14
|
/**
|
|
16
15
|
* Re-imports the page's layouts (`layoutPaths`, shallow → deep, as the route
|
|
17
16
|
* manifest lists them) with a versioned module identity, then patches the
|
|
@@ -3355,7 +3355,6 @@ class DevGraph {
|
|
|
3355
3355
|
#eventSequence = 0;
|
|
3356
3356
|
#revision = 0;
|
|
3357
3357
|
#snapshot;
|
|
3358
|
-
#sourceGeneration = 0;
|
|
3359
3358
|
constructor(initialSnapshot) {
|
|
3360
3359
|
this.#snapshot = initialSnapshot;
|
|
3361
3360
|
}
|
|
@@ -3558,9 +3557,6 @@ class DevGraph {
|
|
|
3558
3557
|
}
|
|
3559
3558
|
}
|
|
3560
3559
|
}
|
|
3561
|
-
invalidateModules() {
|
|
3562
|
-
this.#sourceGeneration += 1;
|
|
3563
|
-
}
|
|
3564
3560
|
sourceVersion(path) {
|
|
3565
3561
|
const modulePath = normalizeModulePath(path);
|
|
3566
3562
|
const fingerprint = this.#sourceFingerprint(modulePath, new Set);
|
|
@@ -3580,9 +3576,9 @@ class DevGraph {
|
|
|
3580
3576
|
let ownFingerprint;
|
|
3581
3577
|
try {
|
|
3582
3578
|
const stats = statSync(path, { bigint: true });
|
|
3583
|
-
ownFingerprint = `${stats.mtimeNs}:${stats.size}
|
|
3579
|
+
ownFingerprint = `${stats.mtimeNs}:${stats.size}`;
|
|
3584
3580
|
} catch {
|
|
3585
|
-
ownFingerprint =
|
|
3581
|
+
ownFingerprint = "missing";
|
|
3586
3582
|
}
|
|
3587
3583
|
const dependencies = [...this.#dependencies.get(path) ?? []].toSorted((left, right) => left.localeCompare(right)).map((dependency) => this.#sourceFingerprint(dependency, visited));
|
|
3588
3584
|
return `${path}:${ownFingerprint}:${dependencies.join(",")}`;
|
|
@@ -4617,10 +4613,10 @@ class QueryStore {
|
|
|
4617
4613
|
}
|
|
4618
4614
|
}
|
|
4619
4615
|
entry.snapshot = { ...entry.snapshot, data };
|
|
4616
|
+
this.revisionValue += 1;
|
|
4620
4617
|
for (const listener of entry.listeners) {
|
|
4621
4618
|
listener();
|
|
4622
4619
|
}
|
|
4623
|
-
this.revisionValue += 1;
|
|
4624
4620
|
for (const listener of this.listeners) {
|
|
4625
4621
|
listener();
|
|
4626
4622
|
}
|
|
@@ -5948,6 +5944,7 @@ import {
|
|
|
5948
5944
|
useCallback,
|
|
5949
5945
|
useContext as useContext2,
|
|
5950
5946
|
useEffect,
|
|
5947
|
+
useState,
|
|
5951
5948
|
useSyncExternalStore
|
|
5952
5949
|
} from "react";
|
|
5953
5950
|
var QUERY_CONTEXT2 = Symbol.for("furin.query.context.v1");
|
|
@@ -3777,10 +3777,10 @@ class QueryStore {
|
|
|
3777
3777
|
}
|
|
3778
3778
|
}
|
|
3779
3779
|
entry.snapshot = { ...entry.snapshot, data };
|
|
3780
|
+
this.revisionValue += 1;
|
|
3780
3781
|
for (const listener of entry.listeners) {
|
|
3781
3782
|
listener();
|
|
3782
3783
|
}
|
|
3783
|
-
this.revisionValue += 1;
|
|
3784
3784
|
for (const listener of this.listeners) {
|
|
3785
3785
|
listener();
|
|
3786
3786
|
}
|
package/dist/sync-client.js
CHANGED
|
@@ -602,10 +602,10 @@ class QueryStore {
|
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
entry.snapshot = { ...entry.snapshot, data };
|
|
605
|
+
this.revisionValue += 1;
|
|
605
606
|
for (const listener of entry.listeners) {
|
|
606
607
|
listener();
|
|
607
608
|
}
|
|
608
|
-
this.revisionValue += 1;
|
|
609
609
|
for (const listener of this.listeners) {
|
|
610
610
|
listener();
|
|
611
611
|
}
|
package/package.json
CHANGED
|
@@ -243,10 +243,11 @@ export class QueryStore {
|
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
entry.snapshot = { ...entry.snapshot, data };
|
|
246
|
+
// Before any listener: a listener reading `revision()` must see this publish.
|
|
247
|
+
this.revisionValue += 1;
|
|
246
248
|
for (const listener of entry.listeners) {
|
|
247
249
|
listener();
|
|
248
250
|
}
|
|
249
|
-
this.revisionValue += 1;
|
|
250
251
|
for (const listener of this.listeners) {
|
|
251
252
|
listener();
|
|
252
253
|
}
|
package/src/client/query.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
useCallback,
|
|
5
5
|
useContext,
|
|
6
6
|
useEffect,
|
|
7
|
+
useState,
|
|
7
8
|
useSyncExternalStore,
|
|
8
9
|
} from "react";
|
|
9
10
|
import { LIVE_QUERY, type LiveQuery, type QueryStore, type ReadResult } from "./query-store.ts";
|
|
@@ -48,3 +49,89 @@ export function useQuery<Result extends ReadResult, Selected = LiveData<Result>>
|
|
|
48
49
|
isFetching: state.isFetching,
|
|
49
50
|
};
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Pages are ordinary store entries keyed by their URL: invalidation refetches every loaded page.
|
|
55
|
+
* The hook owns only how many pages are shown; a new first page (changed filters) restarts at one.
|
|
56
|
+
*/
|
|
57
|
+
export function useInfiniteQuery<Result extends ReadResult>(
|
|
58
|
+
page: (index: number) => LiveQuery<Result>,
|
|
59
|
+
options: { next: (last: LiveData<Result>) => boolean }
|
|
60
|
+
): {
|
|
61
|
+
error: Result["error"] | null;
|
|
62
|
+
fetchNext: () => void;
|
|
63
|
+
hasNext: boolean;
|
|
64
|
+
isFetching: boolean;
|
|
65
|
+
pages: LiveData<Result>[];
|
|
66
|
+
} {
|
|
67
|
+
const first = page(0)[LIVE_QUERY];
|
|
68
|
+
const context = useContext(QueryStoreContext);
|
|
69
|
+
const store = context ?? first.reference.client;
|
|
70
|
+
const firstUrl = store.readKey(first.reference, first.options);
|
|
71
|
+
const [loaded, setLoaded] = useState({ count: 1, firstUrl });
|
|
72
|
+
if (loaded.firstUrl !== firstUrl) {
|
|
73
|
+
setLoaded({ count: 1, firstUrl });
|
|
74
|
+
}
|
|
75
|
+
const count = loaded.firstUrl === firstUrl ? loaded.count : 1;
|
|
76
|
+
const urls = Array.from({ length: count }, (_, index) => {
|
|
77
|
+
const { options: readOptions, reference } = page(index)[LIVE_QUERY];
|
|
78
|
+
const url = store.readKey(reference, readOptions);
|
|
79
|
+
store.bind(url, () => reference.load(readOptions), reference.client);
|
|
80
|
+
return url;
|
|
81
|
+
});
|
|
82
|
+
// Encoded URLs never contain a newline: one stable string stands for the page list.
|
|
83
|
+
const key = urls.join("\n");
|
|
84
|
+
const subscribe = useCallback(
|
|
85
|
+
(listener: () => void) => {
|
|
86
|
+
const unsubscribes = key.split("\n").map((url) => store.subscribe(url, listener));
|
|
87
|
+
return () => {
|
|
88
|
+
for (const unsubscribe of unsubscribes) {
|
|
89
|
+
unsubscribe();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
[store, key]
|
|
94
|
+
);
|
|
95
|
+
// The store revision changes on every publish, so it versions all pages at once.
|
|
96
|
+
useSyncExternalStore(subscribe, store.revision, store.revision);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
for (const url of key.split("\n")) {
|
|
99
|
+
store.fetch(url);
|
|
100
|
+
}
|
|
101
|
+
}, [store, key]);
|
|
102
|
+
const snapshots = urls.map((url) => store.snapshot(url));
|
|
103
|
+
const pages: LiveData<Result>[] = [];
|
|
104
|
+
for (const entry of snapshots) {
|
|
105
|
+
if (entry.data === undefined) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
pages.push(entry.data as LiveData<Result>);
|
|
109
|
+
}
|
|
110
|
+
const last = pages.at(-1);
|
|
111
|
+
const hasNext = pages.length === count && last !== undefined && options.next(last);
|
|
112
|
+
const fetchNext = () => {
|
|
113
|
+
// A failed page stays stale in the store: retry it rather than skipping past it.
|
|
114
|
+
const failed = urls.filter((_, index) => snapshots[index]?.error !== null);
|
|
115
|
+
if (failed.length > 0) {
|
|
116
|
+
for (const url of failed) {
|
|
117
|
+
store.fetch(url);
|
|
118
|
+
}
|
|
119
|
+
} else if (hasNext) {
|
|
120
|
+
// Calls in the same render see the same `count`: only the first one adds a page.
|
|
121
|
+
setLoaded((previous) =>
|
|
122
|
+
previous.firstUrl === firstUrl && previous.count === count
|
|
123
|
+
? { count: count + 1, firstUrl }
|
|
124
|
+
: previous
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
error: (snapshots.find((entry) => entry.error !== null)?.error ?? null) as
|
|
130
|
+
| Result["error"]
|
|
131
|
+
| null,
|
|
132
|
+
fetchNext,
|
|
133
|
+
hasNext,
|
|
134
|
+
isFetching: snapshots.some((entry) => entry.isFetching),
|
|
135
|
+
pages,
|
|
136
|
+
};
|
|
137
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -22,7 +22,7 @@ export {
|
|
|
22
22
|
updateHotComponent,
|
|
23
23
|
} from "./client/hmr.ts";
|
|
24
24
|
export { useMutation } from "./client/mutation.ts";
|
|
25
|
-
export { useQuery } from "./client/query.tsx";
|
|
25
|
+
export { useInfiniteQuery, useQuery } from "./client/query.tsx";
|
|
26
26
|
export type { LiveQuery } from "./client/query-store.ts";
|
|
27
27
|
export { getRouteApi } from "./client/route-api.tsx";
|
|
28
28
|
export { furinSync, type OptimisticCache, type SyncCallOptions } from "./client/sync.ts";
|
package/src/server/dev/graph.ts
CHANGED
|
@@ -139,7 +139,6 @@ export class DevGraph<Snapshot> {
|
|
|
139
139
|
#eventSequence = 0;
|
|
140
140
|
#revision = 0;
|
|
141
141
|
#snapshot: Snapshot;
|
|
142
|
-
#sourceGeneration = 0;
|
|
143
142
|
|
|
144
143
|
constructor(initialSnapshot: Snapshot) {
|
|
145
144
|
this.#snapshot = initialSnapshot;
|
|
@@ -373,10 +372,6 @@ export class DevGraph<Snapshot> {
|
|
|
373
372
|
}
|
|
374
373
|
}
|
|
375
374
|
|
|
376
|
-
invalidateModules(): void {
|
|
377
|
-
this.#sourceGeneration += 1;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
375
|
sourceVersion(path: string): string {
|
|
381
376
|
const modulePath = normalizeModulePath(path);
|
|
382
377
|
const fingerprint = this.#sourceFingerprint(modulePath, new Set());
|
|
@@ -397,9 +392,9 @@ export class DevGraph<Snapshot> {
|
|
|
397
392
|
let ownFingerprint: string;
|
|
398
393
|
try {
|
|
399
394
|
const stats = statSync(path, { bigint: true });
|
|
400
|
-
ownFingerprint = `${stats.mtimeNs}:${stats.size}
|
|
395
|
+
ownFingerprint = `${stats.mtimeNs}:${stats.size}`;
|
|
401
396
|
} catch {
|
|
402
|
-
ownFingerprint =
|
|
397
|
+
ownFingerprint = "missing";
|
|
403
398
|
}
|
|
404
399
|
const dependencies = [...(this.#dependencies.get(path) ?? [])]
|
|
405
400
|
.toSorted((left, right) => left.localeCompare(right))
|
|
@@ -9,7 +9,7 @@ import { createInstrumentationPlugin } from "../devtools/instrumentation.ts";
|
|
|
9
9
|
import { type FurinInstance, withInstance } from "../instance.ts";
|
|
10
10
|
import type { ModeOptions, ModeRuntime } from "../mode.ts";
|
|
11
11
|
import { bindRuntimeRoutes, createRouteRenderer } from "../router/dispatch.ts";
|
|
12
|
-
import { developmentPagePorts
|
|
12
|
+
import { developmentPagePorts } from "../router/hmr.ts";
|
|
13
13
|
import { buildRouteMatcher } from "../router/patterns.ts";
|
|
14
14
|
import { createSearchRouteMetadata } from "../router/schemas.ts";
|
|
15
15
|
import type { ResolvedRoute, RootLayout } from "../router/types.ts";
|
|
@@ -269,7 +269,6 @@ export async function createDevRuntime(
|
|
|
269
269
|
const hmrEntry = (await import(join(furinDir, "index.html"))).default;
|
|
270
270
|
const refreshDevelopmentRoutes = (changedSources: readonly string[]): Promise<void> =>
|
|
271
271
|
withInstance(instance, async () => {
|
|
272
|
-
invalidateStampedRouteModules();
|
|
273
272
|
try {
|
|
274
273
|
const previousSnapshot = currentSnapshot();
|
|
275
274
|
const repaired = repairedDevelopmentRoutes(previousSnapshot, changedSources, graph);
|
package/src/server/router/hmr.ts
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
import type { CurrentRoute, PagePorts } from "./dispatch.ts";
|
|
39
39
|
import { resolveMode, resolveRouteRevalidate } from "./patterns.ts";
|
|
40
40
|
import { createRouteDataErrorResponse, isPprRoute } from "./plugin.ts";
|
|
41
|
-
import {
|
|
41
|
+
import { routeModuleSourceVersion } from "./source-version.ts";
|
|
42
42
|
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
43
43
|
|
|
44
44
|
type RouteModuleImport = (specifier: string) => Promise<CompiledModule>;
|
|
@@ -152,10 +152,6 @@ export function importStampedRouteModule(
|
|
|
152
152
|
return devGraph(undefined).importModule(path, stamp, resolveImport);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
export function invalidateStampedRouteModules(): void {
|
|
156
|
-
invalidateRouteModuleSourceVersions();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
155
|
function isResolvedRouteModuleCandidate(
|
|
160
156
|
layoutPath: string,
|
|
161
157
|
imported: CompiledModule,
|
|
@@ -3,8 +3,9 @@ import { defaultInstanceBucket, scopedInstance } from "../instance.ts";
|
|
|
3
3
|
|
|
4
4
|
export function routeModuleSourceVersion(path: string): string {
|
|
5
5
|
// Bun's runtime plugin loads modules outside any runtime scope. Use the
|
|
6
|
-
// graphs whose routes depend on this source (or that have no snapshot yet)
|
|
7
|
-
//
|
|
6
|
+
// graphs whose routes depend on this source (or that have no snapshot yet).
|
|
7
|
+
// A version only advances when the source or a recorded dependency changes,
|
|
8
|
+
// so an unchanged module keeps one ESM identity for every importer.
|
|
8
9
|
const current = devGraph(scopedInstance() ?? defaultInstanceBucket());
|
|
9
10
|
const relevant = developmentGraphs().filter((graph) => {
|
|
10
11
|
const { snapshot } = graph;
|
|
@@ -22,7 +23,3 @@ export function routeModuleSourceVersion(path: string): string {
|
|
|
22
23
|
)
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
export function invalidateRouteModuleSourceVersions(): void {
|
|
27
|
-
devGraph(undefined).invalidateModules();
|
|
28
|
-
}
|