@teyik0/furin 0.2.0-alpha.1 → 0.2.0-alpha.2
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/package.json +8 -3
- package/src/adapter/static.ts +23 -6
- package/src/build/client.ts +5 -2
- package/src/build/hydrate.ts +7 -1
- package/src/build/route-types.ts +37 -7
- package/src/build/shared.ts +1 -0
- package/src/build/ssg-cache.ts +3 -2
- package/src/client/link.tsx +13 -4
- package/src/client/router/context.ts +2 -0
- package/src/client/router/index.ts +9 -0
- package/src/client/router/link-utils.ts +5 -8
- package/src/client/router/navigation.ts +61 -0
- package/src/client/router/provider.tsx +59 -23
- package/src/client/router/search/index.ts +99 -0
- package/src/client/router/search-store.ts +86 -0
- package/src/client/router/types.ts +12 -4
- package/src/furin.ts +11 -4
- package/src/server/render/isr.ts +29 -7
- package/src/server/render/not-found.ts +2 -0
- package/src/server/render/ssg.ts +15 -4
- package/src/server/render/ssr.ts +47 -9
- package/src/server/router/hmr.ts +14 -10
- package/src/server/router/index.ts +1 -2
- package/src/server/router/patterns.ts +5 -0
- package/src/server/router/plugin.ts +28 -45
- package/src/server/router/schemas.ts +172 -57
- package/src/shared/search-params.ts +182 -0
- package/dist/adapter/bun.d.ts +0 -3
- package/dist/adapter/static.d.ts +0 -3
- package/dist/build/client.d.ts +0 -25
- package/dist/build/compile-entry.d.ts +0 -9
- package/dist/build/compile-entry.ts +0 -109
- package/dist/build/entry-template.d.ts +0 -38
- package/dist/build/entry-template.ts +0 -156
- package/dist/build/hydrate.d.ts +0 -24
- package/dist/build/index.d.ts +0 -8
- package/dist/build/index.js +0 -7069
- package/dist/build/route-types.d.ts +0 -21
- package/dist/build/scan-server.d.ts +0 -8
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -36
- package/dist/build/shared.d.ts +0 -11
- package/dist/build/ssg-cache.d.ts +0 -4
- package/dist/build/types.d.ts +0 -80
- package/dist/cli/config.d.ts +0 -9
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -7082
- package/dist/client/boundaries.d.ts +0 -117
- package/dist/client/default-screens.d.ts +0 -17
- package/dist/client/link.d.ts +0 -22
- package/dist/client/link.js +0 -3450
- package/dist/client/router/boundary-tree.d.ts +0 -26
- package/dist/client/router/context.d.ts +0 -8
- package/dist/client/router/history.d.ts +0 -9
- package/dist/client/router/index.d.ts +0 -7
- package/dist/client/router/link-utils.d.ts +0 -51
- package/dist/client/router/provider.d.ts +0 -4
- package/dist/client/router/spa-response.d.ts +0 -58
- package/dist/client/router/types.d.ts +0 -279
- package/dist/client/server-error.d.ts +0 -12
- package/dist/client.d.ts +0 -242
- package/dist/client.js +0 -96
- package/dist/config.d.ts +0 -57
- package/dist/config.js +0 -29
- package/dist/env.d.ts +0 -50
- package/dist/furin.d.ts +0 -69
- package/dist/furin.js +0 -7373
- package/dist/plugin/index.d.ts +0 -20
- package/dist/plugin/index.js +0 -1500
- package/dist/plugin/transform-client.d.ts +0 -10
- package/dist/server/auto-invalidate/index.d.ts +0 -4
- package/dist/server/auto-invalidate/plugin.d.ts +0 -38
- package/dist/server/auto-invalidate/registry.d.ts +0 -9
- package/dist/server/auto-invalidate/runtime.d.ts +0 -9
- package/dist/server/auto-invalidate/types.d.ts +0 -12
- package/dist/server/cache/dev-loader.d.ts +0 -28
- package/dist/server/cache/index.d.ts +0 -10
- package/dist/server/cache/invalidation.d.ts +0 -12
- package/dist/server/cache/isr-ssg.d.ts +0 -26
- package/dist/server/cache/isr.d.ts +0 -6
- package/dist/server/cache/registry.d.ts +0 -5
- package/dist/server/cache/route-cache.d.ts +0 -26
- package/dist/server/cache/ssg.d.ts +0 -5
- package/dist/server/context-logger.d.ts +0 -28
- package/dist/server/dev-inspector.d.ts +0 -89
- package/dist/server/dev-page-plugin.d.ts +0 -109
- package/dist/server/internal.d.ts +0 -35
- package/dist/server/internal.js +0 -17
- package/dist/server/lang-detect.d.ts +0 -5
- package/dist/server/render/assemble.d.ts +0 -47
- package/dist/server/render/element.d.ts +0 -24
- package/dist/server/render/index.d.ts +0 -7
- package/dist/server/render/index.ts +0 -22
- package/dist/server/render/isr.d.ts +0 -3
- package/dist/server/render/loaders.d.ts +0 -64
- package/dist/server/render/not-found.d.ts +0 -6
- package/dist/server/render/shell.d.ts +0 -39
- package/dist/server/render/shell.ts +0 -202
- package/dist/server/render/ssg.d.ts +0 -8
- package/dist/server/render/ssr.d.ts +0 -107
- package/dist/server/render/template.d.ts +0 -6
- package/dist/server/router/discovery.d.ts +0 -16
- package/dist/server/router/hmr.d.ts +0 -64
- package/dist/server/router/index.d.ts +0 -6
- package/dist/server/router/index.js +0 -28
- package/dist/server/router/index.ts +0 -29
- package/dist/server/router/patterns.d.ts +0 -40
- package/dist/server/router/plugin.d.ts +0 -20
- package/dist/server/router/schemas.d.ts +0 -51
- package/dist/server/router/types.d.ts +0 -60
- package/dist/server/runtime-env.d.ts +0 -3
- package/dist/server/runtime-env.js +0 -10
- package/dist/shared/await.d.ts +0 -67
- package/dist/shared/deferred-ndjson.d.ts +0 -32
- package/dist/shared/digest.d.ts +0 -16
- package/dist/shared/error.d.ts +0 -37
- package/dist/shared/not-found.d.ts +0 -19
- package/dist/shared/utils/ast-walk.d.ts +0 -18
- package/dist/shared/utils/index.d.ts +0 -13
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { RouteManifest as LinkRouteManifest, RouteSearch, RouteTo } from "@teyik0/furin/link";
|
|
2
|
+
import { useCallback, useContext, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import {
|
|
4
|
+
findSearchDefaultsForRouteTarget,
|
|
5
|
+
type SearchParamsInput,
|
|
6
|
+
} from "../../../shared/search-params.ts";
|
|
7
|
+
import { buildHref } from "../link-utils.ts";
|
|
8
|
+
import { FALLBACK_SEARCH_STORE, SearchStoreContext } from "../search-store.ts";
|
|
9
|
+
|
|
10
|
+
export interface RouteManifest extends LinkRouteManifest {}
|
|
11
|
+
|
|
12
|
+
export type SearchRouteTo = keyof LinkRouteManifest extends never
|
|
13
|
+
? RouteTo
|
|
14
|
+
: (string & {}) | keyof LinkRouteManifest;
|
|
15
|
+
|
|
16
|
+
type SearchRouteSearch<To extends SearchRouteTo> = keyof LinkRouteManifest extends never
|
|
17
|
+
? RouteSearch<To & RouteTo>
|
|
18
|
+
: To extends keyof LinkRouteManifest
|
|
19
|
+
? LinkRouteManifest[To] extends { search?: infer S }
|
|
20
|
+
? S
|
|
21
|
+
: undefined
|
|
22
|
+
: undefined;
|
|
23
|
+
|
|
24
|
+
export type EmptyRouteSearch = Record<PropertyKey, never>;
|
|
25
|
+
|
|
26
|
+
export type ResolvedRouteSearch<To extends SearchRouteTo> =
|
|
27
|
+
SearchRouteSearch<To> extends never | undefined
|
|
28
|
+
? EmptyRouteSearch
|
|
29
|
+
: NonNullable<SearchRouteSearch<To>>;
|
|
30
|
+
|
|
31
|
+
export type SetSearchInput<To extends SearchRouteTo> =
|
|
32
|
+
| Partial<ResolvedRouteSearch<To>>
|
|
33
|
+
| ((prev: ResolvedRouteSearch<To>) => Partial<ResolvedRouteSearch<To>>);
|
|
34
|
+
|
|
35
|
+
export interface SetSearchOptions {
|
|
36
|
+
replace?: boolean;
|
|
37
|
+
resetScroll?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type SetSearch<To extends SearchRouteTo> = (
|
|
41
|
+
next: SetSearchInput<To>,
|
|
42
|
+
opts?: SetSearchOptions
|
|
43
|
+
) => Promise<void>;
|
|
44
|
+
|
|
45
|
+
function pathnameFromLogicalHref(logicalHref: string): string {
|
|
46
|
+
return new URL(logicalHref, "http://furin.local").pathname;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function useSearchSelection<To extends SearchRouteTo, TSelected>(
|
|
50
|
+
selector: (search: ResolvedRouteSearch<To>) => TSelected
|
|
51
|
+
): TSelected {
|
|
52
|
+
const store = useContext(SearchStoreContext) ?? FALLBACK_SEARCH_STORE;
|
|
53
|
+
const selectorRef = useRef(selector);
|
|
54
|
+
selectorRef.current = selector;
|
|
55
|
+
|
|
56
|
+
const getSnapshot = useCallback(
|
|
57
|
+
() => selectorRef.current(store.getSnapshot().search as ResolvedRouteSearch<To>),
|
|
58
|
+
[store]
|
|
59
|
+
);
|
|
60
|
+
const getServerSnapshot = useCallback(
|
|
61
|
+
() => selectorRef.current(store.getServerSnapshot().search as ResolvedRouteSearch<To>),
|
|
62
|
+
[store]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return useSyncExternalStore(store.subscribe, getSnapshot, getServerSnapshot);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function useSearch<To extends SearchRouteTo>(
|
|
69
|
+
_from: To
|
|
70
|
+
): [ResolvedRouteSearch<To>, SetSearch<To>];
|
|
71
|
+
export function useSearch<To extends SearchRouteTo, TSelected>(
|
|
72
|
+
_from: To,
|
|
73
|
+
selector: (search: ResolvedRouteSearch<To>) => TSelected
|
|
74
|
+
): [TSelected, SetSearch<To>];
|
|
75
|
+
export function useSearch<To extends SearchRouteTo, TSelected>(
|
|
76
|
+
_from: To,
|
|
77
|
+
selector?: (search: ResolvedRouteSearch<To>) => TSelected
|
|
78
|
+
): [ResolvedRouteSearch<To> | TSelected, SetSearch<To>] {
|
|
79
|
+
const store = useContext(SearchStoreContext) ?? FALLBACK_SEARCH_STORE;
|
|
80
|
+
const selected = useSearchSelection<To, ResolvedRouteSearch<To> | TSelected>((search) =>
|
|
81
|
+
selector ? selector(search) : search
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const setSearch = useCallback<SetSearch<To>>(
|
|
85
|
+
(next, opts) => {
|
|
86
|
+
const snapshot = store.getSnapshot();
|
|
87
|
+
const search = snapshot.search as ResolvedRouteSearch<To>;
|
|
88
|
+
const patch = typeof next === "function" ? next(search) : next;
|
|
89
|
+
const merged = { ...search, ...patch } as SearchParamsInput;
|
|
90
|
+
const pathname = pathnameFromLogicalHref(snapshot.currentHref);
|
|
91
|
+
const searchDefaults = findSearchDefaultsForRouteTarget(pathname, snapshot.searchRoutes);
|
|
92
|
+
const href = buildHref(pathname, merged, undefined, searchDefaults);
|
|
93
|
+
return snapshot.navigate(href, opts);
|
|
94
|
+
},
|
|
95
|
+
[store]
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return [selected, setSearch];
|
|
99
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
3
|
+
import type { RouterContextValue } from "./types.ts";
|
|
4
|
+
|
|
5
|
+
export interface SearchStoreSnapshot {
|
|
6
|
+
currentHref: string;
|
|
7
|
+
navigate: RouterContextValue["navigate"];
|
|
8
|
+
search: SearchParamsInput;
|
|
9
|
+
searchRoutes: SearchRouteMetadata[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type SearchStoreListener = () => void;
|
|
13
|
+
|
|
14
|
+
export interface SearchStore {
|
|
15
|
+
flush: () => void;
|
|
16
|
+
getServerSnapshot: () => SearchStoreSnapshot;
|
|
17
|
+
getSnapshot: () => SearchStoreSnapshot;
|
|
18
|
+
setSnapshot: (next: SearchStoreSnapshot) => void;
|
|
19
|
+
subscribe: (listener: SearchStoreListener) => () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function searchSnapshotChanged(a: SearchStoreSnapshot, b: SearchStoreSnapshot): boolean {
|
|
23
|
+
return (
|
|
24
|
+
a.currentHref !== b.currentHref ||
|
|
25
|
+
a.navigate !== b.navigate ||
|
|
26
|
+
a.search !== b.search ||
|
|
27
|
+
a.searchRoutes !== b.searchRoutes
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createSearchStore(initialSnapshot: SearchStoreSnapshot): SearchStore {
|
|
32
|
+
let snapshot = initialSnapshot;
|
|
33
|
+
let version = 0;
|
|
34
|
+
let flushedVersion = 0;
|
|
35
|
+
const listeners = new Set<SearchStoreListener>();
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
flush: () => {
|
|
39
|
+
if (flushedVersion === version) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
flushedVersion = version;
|
|
43
|
+
for (const listener of [...listeners]) {
|
|
44
|
+
listener();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
getServerSnapshot: () => snapshot,
|
|
48
|
+
getSnapshot: () => snapshot,
|
|
49
|
+
setSnapshot: (next) => {
|
|
50
|
+
if (!searchSnapshotChanged(snapshot, next)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
snapshot = next;
|
|
54
|
+
version++;
|
|
55
|
+
},
|
|
56
|
+
subscribe: (listener) => {
|
|
57
|
+
listeners.add(listener);
|
|
58
|
+
return () => {
|
|
59
|
+
listeners.delete(listener);
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function searchSnapshotFromRouterContext(context: RouterContextValue): SearchStoreSnapshot {
|
|
66
|
+
return {
|
|
67
|
+
currentHref: context.currentHref,
|
|
68
|
+
navigate: context.navigate,
|
|
69
|
+
search: context.search,
|
|
70
|
+
searchRoutes: context.searchRoutes,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const FALLBACK_SEARCH_STORE = createSearchStore({
|
|
75
|
+
currentHref: "/",
|
|
76
|
+
navigate: (href, _opts) => {
|
|
77
|
+
if (typeof window !== "undefined") {
|
|
78
|
+
window.location.href = href;
|
|
79
|
+
}
|
|
80
|
+
return Promise.resolve();
|
|
81
|
+
},
|
|
82
|
+
search: {},
|
|
83
|
+
searchRoutes: [],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const SearchStoreContext = createContext<SearchStore | null>(null);
|
|
@@ -2,6 +2,7 @@ import type React from "react";
|
|
|
2
2
|
import type { RuntimeRoute } from "../../client.ts";
|
|
3
3
|
import type { ErrorComponent } from "../../shared/error.ts";
|
|
4
4
|
import type { NotFoundComponent } from "../../shared/not-found.ts";
|
|
5
|
+
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Augment this interface via declaration merging in furin-env.d.ts
|
|
@@ -35,11 +36,13 @@ export type RouteTo = keyof RouteManifest extends never
|
|
|
35
36
|
* Falls back to a permissive record when RouteManifest is not augmented.
|
|
36
37
|
*/
|
|
37
38
|
export type RouteSearch<To extends RouteTo> = keyof RouteManifest extends never
|
|
38
|
-
?
|
|
39
|
+
? SearchParamsInput
|
|
39
40
|
: To extends keyof RouteManifest
|
|
40
|
-
? RouteManifest[To] extends {
|
|
41
|
-
?
|
|
42
|
-
:
|
|
41
|
+
? RouteManifest[To] extends { searchInput?: infer I }
|
|
42
|
+
? I
|
|
43
|
+
: RouteManifest[To] extends { search?: infer S }
|
|
44
|
+
? S
|
|
45
|
+
: undefined
|
|
43
46
|
: undefined;
|
|
44
47
|
|
|
45
48
|
export type PreloadStrategy = false | "intent" | "viewport" | "render";
|
|
@@ -115,6 +118,10 @@ export interface RouterContextValue {
|
|
|
115
118
|
* Prefer this over `navigate(window.location.pathname)` after a mutation.
|
|
116
119
|
*/
|
|
117
120
|
refresh: (opts?: { resetScroll?: boolean }) => Promise<void>;
|
|
121
|
+
/** Current server-resolved query params for the rendered route. */
|
|
122
|
+
search: SearchParamsInput;
|
|
123
|
+
/** Route-level search defaults used to build clean hrefs without default params. */
|
|
124
|
+
searchRoutes: SearchRouteMetadata[];
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
/**
|
|
@@ -137,6 +144,7 @@ export interface ClientRoute {
|
|
|
137
144
|
pageRoute?: RuntimeRoute;
|
|
138
145
|
pattern: string;
|
|
139
146
|
regex: RegExp;
|
|
147
|
+
searchDefaults?: SearchParamsInput;
|
|
140
148
|
/**
|
|
141
149
|
* Per-segment boundary chain, ordered shallow→deep. Each `depth` maps 1:1
|
|
142
150
|
* to the route-chain index used on the server side, so `buildPageElement`
|
package/src/furin.ts
CHANGED
|
@@ -19,7 +19,12 @@ import {
|
|
|
19
19
|
setProductionTemplateContent,
|
|
20
20
|
setProductionTemplatePath,
|
|
21
21
|
} from "./server/render/template.ts";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
createDataEndpoint,
|
|
24
|
+
createRoutePlugin,
|
|
25
|
+
createSearchRouteMetadata,
|
|
26
|
+
loadProdRoutes,
|
|
27
|
+
} from "./server/router/index.ts";
|
|
23
28
|
import { IS_DEV } from "./server/runtime-env.ts";
|
|
24
29
|
|
|
25
30
|
// biome-ignore lint/suspicious/noEmptyInterface: intentionally augmentable via furin-env.d.ts
|
|
@@ -272,6 +277,7 @@ export async function furin({
|
|
|
272
277
|
|
|
273
278
|
const { scanPages } = await import("./server/router/index.ts");
|
|
274
279
|
const { root, routes } = await scanPages(resolvedPagesDir);
|
|
280
|
+
const searchRoutes = createSearchRouteMetadata(routes);
|
|
275
281
|
|
|
276
282
|
const { writeDevFiles } = await import("./build/hydrate.ts");
|
|
277
283
|
writeDevFiles(
|
|
@@ -317,7 +323,7 @@ export async function furin({
|
|
|
317
323
|
.use(createDataEndpoint(routes))
|
|
318
324
|
.use((app) => {
|
|
319
325
|
for (const route of routes) {
|
|
320
|
-
app.use(createRoutePlugin(route, root));
|
|
326
|
+
app.use(createRoutePlugin(route, root, undefined, searchRoutes));
|
|
321
327
|
}
|
|
322
328
|
return app;
|
|
323
329
|
});
|
|
@@ -329,6 +335,7 @@ export async function furin({
|
|
|
329
335
|
throw new Error("[furin] No pre-built assets found. Run `bunx furin build` first.");
|
|
330
336
|
}
|
|
331
337
|
const { root, routes } = loadProdRoutes(ctx);
|
|
338
|
+
const searchRoutes = createSearchRouteMetadata(routes);
|
|
332
339
|
const prodBuildId = ctx.buildId ?? "";
|
|
333
340
|
setBuildId(prodBuildId);
|
|
334
341
|
hydrateSSGCacheFromCompileContext(ctx);
|
|
@@ -366,7 +373,7 @@ export async function furin({
|
|
|
366
373
|
return;
|
|
367
374
|
}
|
|
368
375
|
const origin = server?.url?.origin ?? "http://localhost:3000";
|
|
369
|
-
await warmSSGCache(routes, root, origin);
|
|
376
|
+
await warmSSGCache(routes, root, origin, searchRoutes);
|
|
370
377
|
})
|
|
371
378
|
.use(
|
|
372
379
|
await (async () => {
|
|
@@ -408,7 +415,7 @@ export async function furin({
|
|
|
408
415
|
.use(createDataEndpoint(routes))
|
|
409
416
|
.use((app) => {
|
|
410
417
|
for (const route of routes) {
|
|
411
|
-
app.use(createRoutePlugin(route, root, prodBuildId));
|
|
418
|
+
app.use(createRoutePlugin(route, root, prodBuildId, searchRoutes));
|
|
412
419
|
}
|
|
413
420
|
return app;
|
|
414
421
|
});
|
package/src/server/render/isr.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from "elysia";
|
|
2
2
|
import { renderToReadableStream } from "react-dom/server";
|
|
3
3
|
import { isNotFoundError } from "../../shared/not-found.ts";
|
|
4
|
+
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
4
5
|
import { autoInvalidateRegistry } from "../auto-invalidate/registry.ts";
|
|
5
6
|
import { deleteISRCache, getISRCache, setISRCache } from "../cache/isr.ts";
|
|
6
7
|
import type { ISRCacheEntry } from "../cache/isr-ssg.ts";
|
|
@@ -42,12 +43,13 @@ function serveISRCacheHit(
|
|
|
42
43
|
cacheKey: string,
|
|
43
44
|
revalidate: number,
|
|
44
45
|
root: RootLayout,
|
|
45
|
-
buildId: string | undefined
|
|
46
|
+
buildId: string | undefined,
|
|
47
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
46
48
|
): string | undefined {
|
|
47
49
|
const isFresh = Date.now() - cached.generatedAt < revalidate * 1000;
|
|
48
50
|
|
|
49
51
|
if (!isFresh) {
|
|
50
|
-
revalidateInBackground(route, params, cacheKey, revalidate, root, ctx);
|
|
52
|
+
revalidateInBackground(route, params, cacheKey, revalidate, root, ctx, searchRoutes);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
const etag = isrEtag(buildId, cached.generatedAt);
|
|
@@ -154,7 +156,8 @@ export async function handleISR(
|
|
|
154
156
|
route: ResolvedRoute,
|
|
155
157
|
ctx: Context,
|
|
156
158
|
root: RootLayout,
|
|
157
|
-
buildId: string | undefined
|
|
159
|
+
buildId: string | undefined,
|
|
160
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
158
161
|
) {
|
|
159
162
|
const revalidate = route.page._route.revalidate ?? 60;
|
|
160
163
|
const params = ctx.params ?? {};
|
|
@@ -162,11 +165,21 @@ export async function handleISR(
|
|
|
162
165
|
|
|
163
166
|
const cached = getISRCache(cacheKey);
|
|
164
167
|
if (cached) {
|
|
165
|
-
return serveISRCacheHit(
|
|
168
|
+
return serveISRCacheHit(
|
|
169
|
+
cached,
|
|
170
|
+
ctx,
|
|
171
|
+
route,
|
|
172
|
+
params,
|
|
173
|
+
cacheKey,
|
|
174
|
+
revalidate,
|
|
175
|
+
root,
|
|
176
|
+
buildId,
|
|
177
|
+
searchRoutes
|
|
178
|
+
);
|
|
166
179
|
}
|
|
167
180
|
|
|
168
181
|
const renderStart = Date.now();
|
|
169
|
-
const prepared = await prepareRender(route, ctx, root, undefined, false, undefined);
|
|
182
|
+
const prepared = await prepareRender(route, ctx, root, undefined, false, undefined, searchRoutes);
|
|
170
183
|
|
|
171
184
|
if (prepared instanceof Response) {
|
|
172
185
|
return prepared;
|
|
@@ -219,7 +232,8 @@ function revalidateInBackground(
|
|
|
219
232
|
cacheKey: string,
|
|
220
233
|
revalidate: number,
|
|
221
234
|
root: RootLayout,
|
|
222
|
-
originalCtx: LoaderContext
|
|
235
|
+
originalCtx: LoaderContext,
|
|
236
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
223
237
|
) {
|
|
224
238
|
if (pendingRevalidations.has(cacheKey)) {
|
|
225
239
|
const logger = createLogger({});
|
|
@@ -236,7 +250,15 @@ function revalidateInBackground(
|
|
|
236
250
|
}
|
|
237
251
|
pendingRevalidations.add(cacheKey);
|
|
238
252
|
|
|
239
|
-
renderForPath(
|
|
253
|
+
renderForPath(
|
|
254
|
+
route,
|
|
255
|
+
params,
|
|
256
|
+
root,
|
|
257
|
+
new URL(originalCtx.request.url).origin,
|
|
258
|
+
"isr",
|
|
259
|
+
undefined,
|
|
260
|
+
searchRoutes
|
|
261
|
+
)
|
|
240
262
|
.then((result) => {
|
|
241
263
|
if (result instanceof Response) {
|
|
242
264
|
return;
|
|
@@ -43,6 +43,8 @@ export async function renderRootNotFound(
|
|
|
43
43
|
const notFoundContext: RouterContextValue = {
|
|
44
44
|
basePath: "",
|
|
45
45
|
currentHref: request ? normalizeHref(new URL(request.url).pathname) : "/",
|
|
46
|
+
search: {},
|
|
47
|
+
searchRoutes: [],
|
|
46
48
|
navigate: (_href, _opts) => Promise.resolve(),
|
|
47
49
|
prefetch: (_href, _opts) => {
|
|
48
50
|
/* noop */
|
package/src/server/render/ssg.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
1
2
|
import { mapWithConcurrency } from "../../shared/utils/index.ts";
|
|
2
3
|
import type { SsgCacheEntry } from "../cache/isr-ssg.ts";
|
|
3
4
|
import { getSSGCache, setSSGCache } from "../cache/ssg.ts";
|
|
@@ -11,7 +12,8 @@ export async function prerenderSSG(
|
|
|
11
12
|
params: Record<string, string>,
|
|
12
13
|
root: RootLayout,
|
|
13
14
|
origin: string,
|
|
14
|
-
basePath
|
|
15
|
+
basePath?: string,
|
|
16
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
15
17
|
): Promise<SsgCacheEntry | Response> {
|
|
16
18
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
17
19
|
|
|
@@ -25,7 +27,15 @@ export async function prerenderSSG(
|
|
|
25
27
|
return taggedEntry;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const renderResult = await renderForPath(
|
|
30
|
+
const renderResult = await renderForPath(
|
|
31
|
+
route,
|
|
32
|
+
params,
|
|
33
|
+
root,
|
|
34
|
+
origin,
|
|
35
|
+
"ssg",
|
|
36
|
+
basePath,
|
|
37
|
+
searchRoutes
|
|
38
|
+
);
|
|
29
39
|
if (renderResult instanceof Response) {
|
|
30
40
|
return renderResult;
|
|
31
41
|
}
|
|
@@ -65,7 +75,8 @@ const SSG_WARM_CONCURRENCY = 4;
|
|
|
65
75
|
export async function warmSSGCache(
|
|
66
76
|
routes: ResolvedRoute[],
|
|
67
77
|
root: RootLayout,
|
|
68
|
-
origin: string
|
|
78
|
+
origin: string,
|
|
79
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
69
80
|
): Promise<void> {
|
|
70
81
|
const targets = routes.filter((r) => r.mode === "ssg" && r.page.staticParams);
|
|
71
82
|
const warmupLogger = createLogger({});
|
|
@@ -115,7 +126,7 @@ export async function warmSSGCache(
|
|
|
115
126
|
for (const params of paramSets) {
|
|
116
127
|
tasks.push(async () => {
|
|
117
128
|
try {
|
|
118
|
-
await prerenderSSG(route, params, root, origin, undefined);
|
|
129
|
+
await prerenderSSG(route, params, root, origin, undefined, searchRoutes);
|
|
119
130
|
} catch (err) {
|
|
120
131
|
logSsgError({ render: "ssg", action: "prerender_failed", route: route.pattern }, err);
|
|
121
132
|
}
|
package/src/server/render/ssr.ts
CHANGED
|
@@ -8,8 +8,14 @@ import {
|
|
|
8
8
|
normalizeHref,
|
|
9
9
|
RouterContext,
|
|
10
10
|
type RouterContextValue,
|
|
11
|
+
SearchStoreContext,
|
|
11
12
|
} from "../../client/router/index.ts";
|
|
13
|
+
import {
|
|
14
|
+
createSearchStore,
|
|
15
|
+
searchSnapshotFromRouterContext,
|
|
16
|
+
} from "../../client/router/search-store.ts";
|
|
12
17
|
import { computeErrorDigest } from "../../shared/digest.ts";
|
|
18
|
+
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
13
19
|
import { runInSyntheticRenderScope, useLogger } from "../context-logger.ts";
|
|
14
20
|
// FurinNotFoundError is used indirectly via buildNotFoundElement in element.tsx
|
|
15
21
|
import type { ResolvedRoute, RootLayout } from "../router/index.ts";
|
|
@@ -87,7 +93,11 @@ export function withSSRRouterContext(
|
|
|
87
93
|
element: ReactNode,
|
|
88
94
|
contextValue: RouterContextValue
|
|
89
95
|
): ReactNode {
|
|
90
|
-
return createElement(
|
|
96
|
+
return createElement(
|
|
97
|
+
SearchStoreContext.Provider,
|
|
98
|
+
{ value: createSearchStore(searchSnapshotFromRouterContext(contextValue)) },
|
|
99
|
+
createElement(RouterContext.Provider, { value: contextValue }, element)
|
|
100
|
+
);
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
interface ShellFallbackResult {
|
|
@@ -158,6 +168,12 @@ export function assertDeferredModeAllowed(
|
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
170
|
|
|
171
|
+
function currentHrefFromContext(ctx: Context): string {
|
|
172
|
+
const pathUrl = new URL(ctx.path, "http://furin.local");
|
|
173
|
+
const requestUrl = new URL(ctx.request.url);
|
|
174
|
+
return normalizeHref(pathUrl.pathname) + (pathUrl.search || requestUrl.search);
|
|
175
|
+
}
|
|
176
|
+
|
|
161
177
|
/**
|
|
162
178
|
* Builds the success-path element and head injection. `head()` is user code
|
|
163
179
|
* that runs synchronously, outside the render pipeline's shell-error handling,
|
|
@@ -206,7 +222,8 @@ export async function prepareRender(
|
|
|
206
222
|
root: RootLayout,
|
|
207
223
|
basePath: string | undefined,
|
|
208
224
|
throwOnFailure: boolean,
|
|
209
|
-
precomputedLoaderResult: LoaderResult | undefined
|
|
225
|
+
precomputedLoaderResult: LoaderResult | undefined,
|
|
226
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
210
227
|
): Promise<PreparedRender | Response> {
|
|
211
228
|
const loaderStart = Date.now();
|
|
212
229
|
const loaderResult = precomputedLoaderResult ?? (await runLoaders(route, ctx));
|
|
@@ -273,7 +290,9 @@ export async function prepareRender(
|
|
|
273
290
|
|
|
274
291
|
const ssrContext: RouterContextValue = {
|
|
275
292
|
basePath: basePath ?? "",
|
|
276
|
-
currentHref:
|
|
293
|
+
currentHref: currentHrefFromContext(ctx),
|
|
294
|
+
search: (ctx.query as SearchParamsInput | undefined) ?? {},
|
|
295
|
+
searchRoutes: searchRoutes ?? [],
|
|
277
296
|
navigate: (_href, _opts) => Promise.resolve(),
|
|
278
297
|
prefetch: (_href, _opts) => {
|
|
279
298
|
/* noop */
|
|
@@ -313,7 +332,8 @@ export function renderForPath(
|
|
|
313
332
|
root: RootLayout,
|
|
314
333
|
origin: string,
|
|
315
334
|
mode: "ssg" | "isr",
|
|
316
|
-
basePath
|
|
335
|
+
basePath?: string,
|
|
336
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
317
337
|
): Promise<RenderResult | Response> {
|
|
318
338
|
return runInSyntheticRenderScope(
|
|
319
339
|
async () => {
|
|
@@ -330,7 +350,15 @@ export function renderForPath(
|
|
|
330
350
|
path: resolvedPath,
|
|
331
351
|
} as Context;
|
|
332
352
|
|
|
333
|
-
const prepared = await prepareRender(
|
|
353
|
+
const prepared = await prepareRender(
|
|
354
|
+
route,
|
|
355
|
+
ctx,
|
|
356
|
+
root,
|
|
357
|
+
basePath,
|
|
358
|
+
true,
|
|
359
|
+
undefined,
|
|
360
|
+
searchRoutes
|
|
361
|
+
);
|
|
334
362
|
if (prepared instanceof Response) {
|
|
335
363
|
return prepared;
|
|
336
364
|
}
|
|
@@ -381,9 +409,10 @@ export async function serializeLoaderDataNdjson(
|
|
|
381
409
|
export async function renderToHTML(
|
|
382
410
|
route: ResolvedRoute,
|
|
383
411
|
ctx: Context,
|
|
384
|
-
root: RootLayout
|
|
412
|
+
root: RootLayout,
|
|
413
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
385
414
|
): Promise<RenderResult> {
|
|
386
|
-
const prepared = await prepareRender(route, ctx, root, undefined, false, undefined);
|
|
415
|
+
const prepared = await prepareRender(route, ctx, root, undefined, false, undefined, searchRoutes);
|
|
387
416
|
|
|
388
417
|
if (prepared instanceof Response) {
|
|
389
418
|
throw prepared;
|
|
@@ -419,9 +448,18 @@ export async function renderSSR(
|
|
|
419
448
|
route: ResolvedRoute,
|
|
420
449
|
ctx: Context,
|
|
421
450
|
root: RootLayout,
|
|
422
|
-
precomputedLoaderResult: LoaderResult | undefined
|
|
451
|
+
precomputedLoaderResult: LoaderResult | undefined,
|
|
452
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
423
453
|
): Promise<Response> {
|
|
424
|
-
const prepared = await prepareRender(
|
|
454
|
+
const prepared = await prepareRender(
|
|
455
|
+
route,
|
|
456
|
+
ctx,
|
|
457
|
+
root,
|
|
458
|
+
undefined,
|
|
459
|
+
false,
|
|
460
|
+
precomputedLoaderResult,
|
|
461
|
+
searchRoutes
|
|
462
|
+
);
|
|
425
463
|
|
|
426
464
|
if (prepared instanceof Response) {
|
|
427
465
|
return prepared;
|
package/src/server/router/hmr.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import type { Context } from "elysia";
|
|
3
3
|
import type { RuntimePage, RuntimeRoute } from "../../client.ts";
|
|
4
|
+
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
4
5
|
import { collectRouteChainFromRoute, isFurinPage, isFurinRoute } from "../../shared/utils/index.ts";
|
|
5
6
|
import { autoInvalidateRegistry } from "../auto-invalidate/registry.ts";
|
|
6
7
|
import {
|
|
@@ -183,7 +184,8 @@ export function rebuildDevRoute(
|
|
|
183
184
|
export async function handleDevRequest(
|
|
184
185
|
route: ResolvedRoute,
|
|
185
186
|
ctx: Context,
|
|
186
|
-
root: RootLayout
|
|
187
|
+
root: RootLayout,
|
|
188
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
187
189
|
): Promise<unknown> {
|
|
188
190
|
// Load the page via ?furin-server virtual namespace so it stays out of
|
|
189
191
|
// --hot's file watcher, then hand off to renderSSR which runs loaders,
|
|
@@ -231,7 +233,7 @@ export async function handleDevRequest(
|
|
|
231
233
|
// a fresh entry exists. HTML re-assembles every time so the dev shell
|
|
232
234
|
// chunk URL is always current.
|
|
233
235
|
if (refreshedRoute.mode === "isr") {
|
|
234
|
-
return renderDevISRWithLoaderCache(refreshedRoute, ctx, currentRoot);
|
|
236
|
+
return renderDevISRWithLoaderCache(refreshedRoute, ctx, currentRoot, searchRoutes);
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
// Live SSG — same trick as Live ISR, but the cache entry is forever-fresh
|
|
@@ -241,10 +243,10 @@ export async function handleDevRequest(
|
|
|
241
243
|
// loader on every refresh — which would make expensive loaders (DB
|
|
242
244
|
// queries, MDX parsing, sitemap reads) painful in dev.
|
|
243
245
|
if (refreshedRoute.mode === "ssg") {
|
|
244
|
-
return renderDevSSGWithLoaderCache(refreshedRoute, ctx, currentRoot);
|
|
246
|
+
return renderDevSSGWithLoaderCache(refreshedRoute, ctx, currentRoot, searchRoutes);
|
|
245
247
|
}
|
|
246
248
|
|
|
247
|
-
return renderSSR(refreshedRoute, ctx, currentRoot, undefined);
|
|
249
|
+
return renderSSR(refreshedRoute, ctx, currentRoot, undefined, searchRoutes);
|
|
248
250
|
}
|
|
249
251
|
} catch (err) {
|
|
250
252
|
console.error(`[furin] Dev page load error for ${route.path}:`, err);
|
|
@@ -266,7 +268,8 @@ export async function handleDevRequest(
|
|
|
266
268
|
export async function renderDevISRWithLoaderCache(
|
|
267
269
|
route: ResolvedRoute,
|
|
268
270
|
ctx: Context,
|
|
269
|
-
root: RootLayout
|
|
271
|
+
root: RootLayout,
|
|
272
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
270
273
|
): Promise<Response> {
|
|
271
274
|
const cacheKey = `${root.path}:${resolvePath(route.pattern, ctx.params ?? {})}`;
|
|
272
275
|
const cached = getDevISRLoaderCache(cacheKey);
|
|
@@ -278,7 +281,7 @@ export async function renderDevISRWithLoaderCache(
|
|
|
278
281
|
deferredPromises: undefined,
|
|
279
282
|
headers: cached.headers,
|
|
280
283
|
};
|
|
281
|
-
return renderSSR(route, ctx, root, precomputed);
|
|
284
|
+
return renderSSR(route, ctx, root, precomputed, searchRoutes);
|
|
282
285
|
}
|
|
283
286
|
|
|
284
287
|
const result = await runLoaders(route, ctx);
|
|
@@ -298,7 +301,7 @@ export async function renderDevISRWithLoaderCache(
|
|
|
298
301
|
route.tags
|
|
299
302
|
);
|
|
300
303
|
}
|
|
301
|
-
return renderSSR(route, ctx, root, result);
|
|
304
|
+
return renderSSR(route, ctx, root, result, searchRoutes);
|
|
302
305
|
}
|
|
303
306
|
|
|
304
307
|
/**
|
|
@@ -311,7 +314,8 @@ export async function renderDevISRWithLoaderCache(
|
|
|
311
314
|
export async function renderDevSSGWithLoaderCache(
|
|
312
315
|
route: ResolvedRoute,
|
|
313
316
|
ctx: Context,
|
|
314
|
-
root: RootLayout
|
|
317
|
+
root: RootLayout,
|
|
318
|
+
searchRoutes?: SearchRouteMetadata[]
|
|
315
319
|
): Promise<Response> {
|
|
316
320
|
const cacheKey = `${root.path}:${resolvePath(route.pattern, ctx.params ?? {})}`;
|
|
317
321
|
const cached = getDevSSGLoaderCache(cacheKey);
|
|
@@ -323,7 +327,7 @@ export async function renderDevSSGWithLoaderCache(
|
|
|
323
327
|
deferredPromises: undefined,
|
|
324
328
|
headers: cached.headers,
|
|
325
329
|
};
|
|
326
|
-
return renderSSR(route, ctx, root, precomputed);
|
|
330
|
+
return renderSSR(route, ctx, root, precomputed, searchRoutes);
|
|
327
331
|
}
|
|
328
332
|
|
|
329
333
|
const result = await runLoaders(route, ctx);
|
|
@@ -343,7 +347,7 @@ export async function renderDevSSGWithLoaderCache(
|
|
|
343
347
|
route.tags
|
|
344
348
|
);
|
|
345
349
|
}
|
|
346
|
-
return renderSSR(route, ctx, root, result);
|
|
350
|
+
return renderSSR(route, ctx, root, result, searchRoutes);
|
|
347
351
|
}
|
|
348
352
|
|
|
349
353
|
/**
|
|
@@ -21,9 +21,8 @@ export {
|
|
|
21
21
|
export { createDataEndpoint, createRoutePlugin } from "./plugin.ts";
|
|
22
22
|
export {
|
|
23
23
|
applySchemaDefaults,
|
|
24
|
-
|
|
24
|
+
createSearchRouteMetadata,
|
|
25
25
|
mergeRouteSchemas,
|
|
26
26
|
parseDataEndpointPath,
|
|
27
|
-
queryDefaultRedirectHook,
|
|
28
27
|
} from "./schemas.ts";
|
|
29
28
|
export type { ResolvedRoute, RootLayout, SegmentBoundary } from "./types.ts";
|
|
@@ -25,6 +25,11 @@ export function resolveMode(page: RuntimePage, routeChain: RuntimeRoute[]): "ssr
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const hasLoader = routeChain.some((r) => r.loader) || !!page.loader;
|
|
28
|
+
const hasQuery = routeChain.some((r) => r.query);
|
|
29
|
+
|
|
30
|
+
if (hasQuery) {
|
|
31
|
+
return "ssr";
|
|
32
|
+
}
|
|
28
33
|
|
|
29
34
|
if (!hasLoader) {
|
|
30
35
|
return "ssg";
|