@teyik0/furin 0.3.0-alpha.1 → 0.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun.d.ts +1 -1
- package/dist/build/client.d.ts +2 -2
- package/dist/build/entry-template.d.ts +4 -0
- package/dist/build/entry-template.ts +17 -3
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +8288 -6629
- package/dist/build/route-types.d.ts +2 -22
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +1 -1
- package/dist/cli/index.js +7862 -6168
- package/dist/client/boundaries.d.ts +2 -0
- package/dist/client/define-route.d.ts +35 -0
- package/dist/client/document.d.ts +26 -0
- package/dist/client/hmr.d.ts +10 -0
- package/dist/client/internal/runtime-types.d.ts +3 -1
- package/dist/client/link.js +1177 -894
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +9 -0
- package/dist/client/router/search/index.d.ts +3 -7
- package/dist/client/router/types.d.ts +32 -24
- package/dist/client.d.ts +4 -159
- package/dist/client.js +183 -21
- package/dist/config.d.ts +8 -8
- package/dist/config.js +8 -8
- package/dist/define-route.d.ts +1355 -0
- package/dist/furin.d.ts +17 -33
- package/dist/furin.js +13444 -10301
- package/dist/plugin/index.js +953 -244
- package/dist/plugin/route-config-autofix.d.ts +31 -0
- package/dist/plugin/routes.d.ts +27 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +1 -0
- package/dist/rsc/build/index.d.ts +1 -1
- package/dist/rsc.js +3 -3
- package/dist/server/dev-page-plugin.d.ts +7 -5
- package/dist/server/devtools/instrumentation.d.ts +2 -2
- package/dist/server/devtools/instrumentation.production.d.ts +2 -2
- package/dist/server/devtools/plugin.d.ts +2 -2
- package/dist/server/internal.d.ts +3 -0
- package/dist/server/logger.d.ts +4 -0
- package/dist/server/render/assemble.d.ts +0 -9
- package/dist/server/render/document.d.ts +4 -0
- package/dist/server/render/element.d.ts +2 -1
- package/dist/server/render/index.d.ts +1 -1
- package/dist/server/render/index.ts +0 -1
- package/dist/server/render/isr.d.ts +1 -1
- package/dist/server/render/loaders.d.ts +1 -1
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-route.d.ts +1 -1
- package/dist/server/render/ssg.d.ts +1 -1
- package/dist/server/render/ssr.d.ts +7 -6
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +24 -0
- package/dist/server/router/hmr.d.ts +16 -8
- package/dist/server/router/patterns.d.ts +6 -0
- package/dist/server/router/plugin.d.ts +4 -3
- package/dist/server/router/schema-merge.d.ts +2 -2
- package/dist/server/router/schemas.d.ts +5 -5
- package/dist/server/router/source-version.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -0
- package/dist/server/sync/index.js +961 -806
- package/dist/server/sync/postgres/migrate.js +3 -2
- package/dist/shared/await.d.ts +6 -7
- package/dist/shared/elysia-contract.d.ts +41 -0
- package/dist/shared/route-map.d.ts +5 -0
- package/dist/shared/utils/index.d.ts +1 -3
- package/package.json +44 -41
- package/src/adapter/bun.ts +42 -22
- package/src/adapter/package.ts +20 -14
- package/src/adapter/static.ts +4 -3
- package/src/build/client.ts +20 -3
- package/src/build/entry-template.ts +17 -3
- package/src/build/hydrate.ts +98 -28
- package/src/build/index.ts +2 -2
- package/src/build/route-types.ts +19 -114
- package/src/build/shared.ts +1 -1
- package/src/build/ssg-cache.ts +2 -5
- package/src/build/types.ts +1 -1
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +7 -7
- package/src/client/boundaries.tsx +9 -1
- package/src/client/define-route.ts +48 -0
- package/src/client/document.tsx +165 -0
- package/src/client/hmr.ts +40 -0
- package/src/client/internal/runtime-types.ts +3 -1
- package/src/client/link.tsx +21 -6
- package/src/client/router/index.ts +1 -0
- package/src/client/router/link-utils.ts +26 -0
- package/src/client/router/provider.tsx +25 -2
- package/src/client/router/search/index.ts +4 -12
- package/src/client/router/types.ts +50 -24
- package/src/client.ts +14 -316
- package/src/config.ts +10 -10
- package/src/define-route.ts +959 -0
- package/src/devtools/devtools-element.js +11 -10
- package/src/furin.ts +303 -53
- package/src/plugin/route-config-autofix.ts +1140 -0
- package/src/plugin/routes.ts +891 -0
- package/src/plugin/transform-client.ts +132 -266
- package/src/plugin/transform-isomorphic.ts +1 -1
- package/src/routes.ts +6 -0
- package/src/rsc/build/index.ts +1 -1
- package/src/server/auto-invalidate/registry.ts +2 -2
- package/src/server/dev-page-plugin.ts +31 -12
- package/src/server/devtools/instrumentation.production.ts +2 -2
- package/src/server/devtools/instrumentation.ts +2 -2
- package/src/server/devtools/plugin.ts +5 -3
- package/src/server/instance.ts +3 -3
- package/src/server/internal.ts +3 -0
- package/src/server/logger.ts +21 -0
- package/src/server/render/assemble.ts +0 -41
- package/src/server/render/document.tsx +25 -0
- package/src/server/render/element.tsx +13 -1
- package/src/server/render/index.ts +0 -1
- package/src/server/render/isr.ts +31 -10
- package/src/server/render/loaders.ts +31 -6
- package/src/server/render/not-found.ts +51 -27
- package/src/server/render/ppr-route.ts +1 -1
- package/src/server/render/ssg.ts +1 -1
- package/src/server/render/ssr.ts +271 -113
- package/src/server/render/template.ts +91 -1
- package/src/server/router/defined-route.ts +110 -0
- package/src/server/router/discovery.ts +129 -29
- package/src/server/router/hmr.ts +111 -40
- package/src/server/router/patterns.ts +40 -12
- package/src/server/router/plugin.ts +63 -46
- package/src/server/router/schema-merge.ts +4 -14
- package/src/server/router/schemas.ts +11 -8
- package/src/server/router/source-version.ts +16 -0
- package/src/server/router/types.ts +2 -0
- package/src/server/sync/postgres/migrate.ts +3 -2
- package/src/server/sync/response.ts +14 -10
- package/src/shared/await.tsx +6 -7
- package/src/shared/elysia-contract.ts +63 -0
- package/src/shared/route-map.ts +37 -0
- package/src/shared/utils/index.ts +2 -20
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -30
- package/dist/server/router/index.d.ts +0 -7
- package/dist/server/router/index.js +0 -27
- package/dist/server/router/index.ts +0 -28
- package/src/build/server-routes-entry.ts +0 -30
- package/src/server/router/index.ts +0 -28
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { createContext, createElement, type ReactNode, useContext } from "react";
|
|
2
|
+
import type { HeadOptions, MetaDescriptor } from "../client.ts";
|
|
3
|
+
|
|
4
|
+
export interface DocumentAssets {
|
|
5
|
+
buildId: string | undefined;
|
|
6
|
+
entryModule: string | undefined;
|
|
7
|
+
faviconHref: string | undefined;
|
|
8
|
+
staticMode: boolean;
|
|
9
|
+
stylesheets: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DocumentState {
|
|
13
|
+
assets: DocumentAssets;
|
|
14
|
+
dataJson: string | undefined;
|
|
15
|
+
head: HeadOptions | undefined;
|
|
16
|
+
syncJson: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const DocumentContext = createContext<DocumentState | null>(null);
|
|
20
|
+
|
|
21
|
+
function serializeJson(value: unknown): string {
|
|
22
|
+
return JSON.stringify(value)
|
|
23
|
+
.replaceAll("<", "\\u003c")
|
|
24
|
+
.replaceAll(">", "\\u003e")
|
|
25
|
+
.replaceAll("\u2028", "\\u2028")
|
|
26
|
+
.replaceAll("\u2029", "\\u2029");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function DocumentProvider({
|
|
30
|
+
children,
|
|
31
|
+
value,
|
|
32
|
+
}: {
|
|
33
|
+
children?: ReactNode;
|
|
34
|
+
value: DocumentState;
|
|
35
|
+
}): ReactNode {
|
|
36
|
+
return <DocumentContext.Provider value={value}>{children}</DocumentContext.Provider>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useDocumentState(): DocumentState | null {
|
|
40
|
+
return useContext(DocumentContext);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function renderMeta(meta: MetaDescriptor, index: number): ReactNode {
|
|
44
|
+
if ("title" in meta) {
|
|
45
|
+
return <title key={`title:${index}`}>{meta.title}</title>;
|
|
46
|
+
}
|
|
47
|
+
if ("script:ld+json" in meta) {
|
|
48
|
+
return (
|
|
49
|
+
<script
|
|
50
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: JSON-LD is an explicit raw-head API and is escaped by the route author contract.
|
|
51
|
+
dangerouslySetInnerHTML={{ __html: serializeJson(meta["script:ld+json"]) }}
|
|
52
|
+
key={`json-ld:${index}`}
|
|
53
|
+
type="application/ld+json"
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if ("tagName" in meta) {
|
|
58
|
+
const { tagName, ...attributes } = meta;
|
|
59
|
+
return createElement(tagName, { ...attributes, key: `${tagName}:${index}` });
|
|
60
|
+
}
|
|
61
|
+
return createElement("meta", { ...meta, key: `meta:${index}` });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function HeadContent(): ReactNode {
|
|
65
|
+
const state = useContext(DocumentContext);
|
|
66
|
+
if (state === null) {
|
|
67
|
+
throw new Error("[furin] <HeadContent /> must be rendered inside the root layout.");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
<meta charSet="utf-8" data-furin-head="" />
|
|
73
|
+
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
|
74
|
+
<script
|
|
75
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: static framework bootstrap with no user-controlled input.
|
|
76
|
+
dangerouslySetInnerHTML={{
|
|
77
|
+
__html:
|
|
78
|
+
'try{var __t=localStorage.getItem("furin-theme");document.documentElement.classList.add(__t==="light"?"light":"dark")}catch(e){document.documentElement.classList.add("dark")}',
|
|
79
|
+
}}
|
|
80
|
+
/>
|
|
81
|
+
{state.assets.buildId ? <meta content={state.assets.buildId} name="furin-build-id" /> : null}
|
|
82
|
+
{state.assets.staticMode ? <meta content="static" name="furin-mode" /> : null}
|
|
83
|
+
{state.assets.faviconHref ? <link href={state.assets.faviconHref} rel="icon" /> : null}
|
|
84
|
+
{state.assets.stylesheets.map((href) => (
|
|
85
|
+
<link crossOrigin="" href={href} key={href} rel="stylesheet" />
|
|
86
|
+
))}
|
|
87
|
+
{state.head?.meta?.map(renderMeta)}
|
|
88
|
+
{state.head?.links?.map((link, index) => (
|
|
89
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: duplicate link descriptors are valid and their declared order is significant.
|
|
90
|
+
<link key={`${link.rel}:${link.href}:${index}`} {...link} />
|
|
91
|
+
))}
|
|
92
|
+
{state.head?.scripts?.map(({ children, ...attributes }, index) => (
|
|
93
|
+
<script
|
|
94
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: duplicate inline scripts are valid and their declared order is significant.
|
|
95
|
+
key={`script:${index}`}
|
|
96
|
+
{...attributes}
|
|
97
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: HeadOptions scripts are an explicit raw HTML API.
|
|
98
|
+
dangerouslySetInnerHTML={children === undefined ? undefined : { __html: children }}
|
|
99
|
+
/>
|
|
100
|
+
))}
|
|
101
|
+
{state.head?.styles?.map(({ children, type }, index) => (
|
|
102
|
+
<style
|
|
103
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: HeadOptions styles are an explicit raw HTML API.
|
|
104
|
+
dangerouslySetInnerHTML={{ __html: children }}
|
|
105
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: duplicate inline styles are valid and their declared order is significant.
|
|
106
|
+
key={`style:${index}`}
|
|
107
|
+
type={type}
|
|
108
|
+
/>
|
|
109
|
+
))}
|
|
110
|
+
</>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function Scripts(): ReactNode {
|
|
115
|
+
const state = useContext(DocumentContext);
|
|
116
|
+
if (state === null) {
|
|
117
|
+
throw new Error("[furin] <Scripts /> must be rendered inside the root layout.");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
{state.syncJson === undefined ? null : (
|
|
123
|
+
<script
|
|
124
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: value is escaped framework JSON.
|
|
125
|
+
dangerouslySetInnerHTML={{ __html: state.syncJson }}
|
|
126
|
+
id="__FURIN_SYNC__"
|
|
127
|
+
type="application/json"
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
{state.dataJson === undefined ? null : (
|
|
131
|
+
<script
|
|
132
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: value is escaped framework JSON.
|
|
133
|
+
dangerouslySetInnerHTML={{ __html: state.dataJson }}
|
|
134
|
+
id="__FURIN_DATA__"
|
|
135
|
+
type="application/json"
|
|
136
|
+
/>
|
|
137
|
+
)}
|
|
138
|
+
<script
|
|
139
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: value is escaped framework JSON.
|
|
140
|
+
dangerouslySetInnerHTML={{ __html: serializeJson(state.head ?? {}) }}
|
|
141
|
+
data-furin-scripts=""
|
|
142
|
+
id="__FURIN_HEAD__"
|
|
143
|
+
type="application/json"
|
|
144
|
+
/>
|
|
145
|
+
{state.assets.entryModule === undefined ? null : (
|
|
146
|
+
<script crossOrigin="" data-furin-entry="" src={state.assets.entryModule} type="module" />
|
|
147
|
+
)}
|
|
148
|
+
</>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** @internal Framework-owned last resort when the user root document throws. */
|
|
153
|
+
export function FurinDocumentFallback({ children }: { children: ReactNode }): ReactNode {
|
|
154
|
+
return (
|
|
155
|
+
<html lang="en">
|
|
156
|
+
<head>
|
|
157
|
+
<HeadContent />
|
|
158
|
+
</head>
|
|
159
|
+
<body>
|
|
160
|
+
{children}
|
|
161
|
+
<Scripts />
|
|
162
|
+
</body>
|
|
163
|
+
</html>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
|
|
3
|
+
type ClientComponent<Props> = (props: Props) => React.ReactNode;
|
|
4
|
+
|
|
5
|
+
export interface HotComponentSlot {
|
|
6
|
+
current: ClientComponent<never>;
|
|
7
|
+
stable: ClientComponent<never>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type HotComponentRegistry = Map<string, HotComponentSlot>;
|
|
11
|
+
|
|
12
|
+
export function reconcileHotComponentRegistry(
|
|
13
|
+
registry: HotComponentRegistry,
|
|
14
|
+
activeKeys: ReadonlySet<string>
|
|
15
|
+
): void {
|
|
16
|
+
for (const key of registry.keys()) {
|
|
17
|
+
if (!activeKeys.has(key)) {
|
|
18
|
+
registry.delete(key);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function updateHotComponent<Props>(
|
|
24
|
+
registry: HotComponentRegistry,
|
|
25
|
+
key: string,
|
|
26
|
+
component: ClientComponent<Props>
|
|
27
|
+
): ClientComponent<Props> {
|
|
28
|
+
const existing = registry.get(key);
|
|
29
|
+
if (existing) {
|
|
30
|
+
existing.current = component as ClientComponent<never>;
|
|
31
|
+
return existing.stable as ClientComponent<Props>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const slot: HotComponentSlot = {
|
|
35
|
+
current: component as ClientComponent<never>,
|
|
36
|
+
stable: (props) => slot.current(props),
|
|
37
|
+
};
|
|
38
|
+
registry.set(key, slot);
|
|
39
|
+
return slot.stable as ClientComponent<Props>;
|
|
40
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
-
import type { HeadOptions, RenderingMode
|
|
2
|
+
import type { HeadOptions, RenderingMode } from "../../client.ts";
|
|
3
|
+
import type { RequestLoaderContext } from "../../define-route.ts";
|
|
3
4
|
|
|
4
5
|
export type RuntimeData = Record<string, unknown>;
|
|
5
6
|
|
|
@@ -15,6 +16,7 @@ export interface RuntimeRoute {
|
|
|
15
16
|
query?: unknown;
|
|
16
17
|
requestLoader?: (ctx: RequestLoaderContext) => Awaitable<object>;
|
|
17
18
|
revalidate?: number;
|
|
19
|
+
sourcePath?: string;
|
|
18
20
|
tags?: string[];
|
|
19
21
|
}
|
|
20
22
|
|
package/src/client/link.tsx
CHANGED
|
@@ -5,7 +5,12 @@ import {
|
|
|
5
5
|
type SearchParamsInput,
|
|
6
6
|
} from "../shared/search-params.ts";
|
|
7
7
|
import { CLIENT_FALLBACK_ROUTER, RouterContext, useRouter } from "./router/context.ts";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
applyLinkParams,
|
|
10
|
+
buildHref,
|
|
11
|
+
navigationHrefPolicy,
|
|
12
|
+
normalizeHref,
|
|
13
|
+
} from "./router/link-utils.ts";
|
|
9
14
|
import type { LinkProps, RouterContextValue, RouteTo } from "./router/types.ts";
|
|
10
15
|
|
|
11
16
|
// biome-ignore lint/performance/noBarrelFile: re-exporting router symbols preserves backward compatibility for @teyik0/furin/link consumers
|
|
@@ -28,23 +33,31 @@ interface LinkView {
|
|
|
28
33
|
function computeLinkView<To extends RouteTo>(
|
|
29
34
|
{
|
|
30
35
|
to,
|
|
36
|
+
params,
|
|
31
37
|
search,
|
|
32
38
|
hash,
|
|
33
39
|
children,
|
|
34
40
|
activeProps,
|
|
35
41
|
inactiveProps,
|
|
36
|
-
}: Pick<
|
|
42
|
+
}: Pick<
|
|
43
|
+
LinkProps<To>,
|
|
44
|
+
"to" | "params" | "search" | "hash" | "children" | "activeProps" | "inactiveProps"
|
|
45
|
+
>,
|
|
37
46
|
router: RouterContextValue
|
|
38
47
|
): LinkView {
|
|
39
|
-
const
|
|
40
|
-
const logicalHref = buildHref(
|
|
48
|
+
const resolvedTo = applyLinkParams(
|
|
41
49
|
to as string,
|
|
50
|
+
params as Record<string, string | number> | null | undefined
|
|
51
|
+
);
|
|
52
|
+
const searchDefaults = findSearchDefaultsForRouteTarget(resolvedTo, router.searchRoutes);
|
|
53
|
+
const logicalHref = buildHref(
|
|
54
|
+
resolvedTo,
|
|
42
55
|
search as SearchParamsInput | null | undefined,
|
|
43
56
|
hash,
|
|
44
57
|
searchDefaults
|
|
45
58
|
);
|
|
46
59
|
const logicalHrefWithoutHash = buildHref(
|
|
47
|
-
|
|
60
|
+
resolvedTo,
|
|
48
61
|
search as SearchParamsInput | null | undefined,
|
|
49
62
|
undefined,
|
|
50
63
|
searchDefaults
|
|
@@ -76,6 +89,7 @@ function isSameOriginUrl(url: string): boolean {
|
|
|
76
89
|
*/
|
|
77
90
|
function LinkInteractive<To extends RouteTo>({
|
|
78
91
|
to,
|
|
92
|
+
params,
|
|
79
93
|
search,
|
|
80
94
|
hash,
|
|
81
95
|
preload,
|
|
@@ -102,7 +116,7 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
102
116
|
// logicalHref: route-relative path (no basePath), used for navigation + active state.
|
|
103
117
|
// physicalHref (href): what the browser sees — basePath + logicalHref.
|
|
104
118
|
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView(
|
|
105
|
-
{ activeProps, children, hash, inactiveProps, search, to },
|
|
119
|
+
{ activeProps, children, hash, inactiveProps, params, search, to },
|
|
106
120
|
router
|
|
107
121
|
);
|
|
108
122
|
const effectivePreload = preload ?? router.defaultPreload;
|
|
@@ -272,6 +286,7 @@ function renderLinkElement<To extends RouteTo>(
|
|
|
272
286
|
// Destructure to strip Link-specific and client-only props before spreading onto <a>.
|
|
273
287
|
const {
|
|
274
288
|
to: _to,
|
|
289
|
+
params: _params,
|
|
275
290
|
search: _search,
|
|
276
291
|
hash: _hash,
|
|
277
292
|
children: _children,
|
|
@@ -68,6 +68,32 @@ export function isSameOriginFetchResult(
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Substitutes typed path params into a route pattern: `/board/:boardId` with
|
|
73
|
+
* `{ boardId: 42 }` → `/board/42`. The `*` wildcard segment (catch-all) is
|
|
74
|
+
* replaced from `params["*"]`. Unknown segments are left untouched so
|
|
75
|
+
* partially-applied patterns stay visible.
|
|
76
|
+
*
|
|
77
|
+
* @internal Exported for unit testing only.
|
|
78
|
+
*/
|
|
79
|
+
export function applyLinkParams(
|
|
80
|
+
to: string,
|
|
81
|
+
params: Record<string, string | number> | null | undefined
|
|
82
|
+
): string {
|
|
83
|
+
if (!params) {
|
|
84
|
+
return to;
|
|
85
|
+
}
|
|
86
|
+
let url = to.replaceAll(/:([a-zA-Z0-9_]+)/g, (match: string, name: string) =>
|
|
87
|
+
name in params ? encodeURIComponent(String(params[name])) : match
|
|
88
|
+
);
|
|
89
|
+
const wildcard: string | number | undefined = params["*"];
|
|
90
|
+
if (wildcard !== undefined && url.includes("/*")) {
|
|
91
|
+
const encodedWildcard = String(wildcard).split("/").map(encodeURIComponent).join("/");
|
|
92
|
+
url = url.replace("/*", () => `/${encodedWildcard}`);
|
|
93
|
+
}
|
|
94
|
+
return url;
|
|
95
|
+
}
|
|
96
|
+
|
|
71
97
|
/**
|
|
72
98
|
* Builds a full href string from a pathname, optional search params, and optional hash.
|
|
73
99
|
* Null/undefined search values are omitted.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { log } from "evlog";
|
|
2
2
|
import type React from "react";
|
|
3
3
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import type { HeadOptions } from "../../client.ts";
|
|
4
5
|
import { parseDeferredNdjson } from "../../shared/deferred-ndjson.ts";
|
|
5
6
|
import type { SearchParamsInput } from "../../shared/search-params.ts";
|
|
7
|
+
import { DocumentProvider, useDocumentState } from "../document.tsx";
|
|
6
8
|
import { isAbortError } from "./abort.ts";
|
|
7
9
|
import { buildPageElement, buildRouterTree } from "./boundary-tree.tsx";
|
|
8
10
|
import {
|
|
@@ -85,10 +87,12 @@ export function RouterProvider({
|
|
|
85
87
|
prefetchCacheSize,
|
|
86
88
|
syncStream,
|
|
87
89
|
}: RouterProviderProps): React.ReactElement {
|
|
90
|
+
const initialDocumentState = useDocumentState();
|
|
88
91
|
// Initial state. When `initialMatch` is `null`, `initialNotFound` MUST be set —
|
|
89
92
|
// the provider boots into the inline not-found UI.
|
|
90
93
|
const [state, setState] = useState<RouterState>(() => ({
|
|
91
94
|
data: initialData,
|
|
95
|
+
head: initialDocumentState?.head,
|
|
92
96
|
match: initialMatch,
|
|
93
97
|
notFound: initialNotFound,
|
|
94
98
|
}));
|
|
@@ -237,6 +241,7 @@ export function RouterProvider({
|
|
|
237
241
|
// __furinError — error sentinel (digest, message, status)
|
|
238
242
|
// __furinTitle — document title resolved server-side from head()
|
|
239
243
|
const {
|
|
244
|
+
__furinHead,
|
|
240
245
|
__furinStatus,
|
|
241
246
|
__furinNotFound,
|
|
242
247
|
__furinRedirect,
|
|
@@ -248,6 +253,7 @@ export function RouterProvider({
|
|
|
248
253
|
__furinNotFound?: { data?: unknown; message?: string };
|
|
249
254
|
__furinRedirect?: string;
|
|
250
255
|
__furinError?: { digest: string; message: string; status: number };
|
|
256
|
+
__furinHead?: HeadOptions;
|
|
251
257
|
__furinTitle?: string;
|
|
252
258
|
[key: string]: unknown;
|
|
253
259
|
};
|
|
@@ -273,6 +279,7 @@ export function RouterProvider({
|
|
|
273
279
|
data: {},
|
|
274
280
|
error: __furinError,
|
|
275
281
|
finalHref,
|
|
282
|
+
head: __furinHead,
|
|
276
283
|
match: loadedMatch,
|
|
277
284
|
title,
|
|
278
285
|
};
|
|
@@ -292,6 +299,7 @@ export function RouterProvider({
|
|
|
292
299
|
return {
|
|
293
300
|
data,
|
|
294
301
|
finalHref,
|
|
302
|
+
head: __furinHead,
|
|
295
303
|
match: loadedMatch,
|
|
296
304
|
notFound,
|
|
297
305
|
title,
|
|
@@ -303,7 +311,7 @@ export function RouterProvider({
|
|
|
303
311
|
return { data, finalHref, match: null, title };
|
|
304
312
|
}
|
|
305
313
|
|
|
306
|
-
return { data, finalHref, match: loadedMatch, title };
|
|
314
|
+
return { data, finalHref, head: __furinHead, match: loadedMatch, title };
|
|
307
315
|
} catch (err: unknown) {
|
|
308
316
|
if (!isAbortError(err)) {
|
|
309
317
|
log.error({
|
|
@@ -630,6 +638,7 @@ export function RouterProvider({
|
|
|
630
638
|
// Render-synchronous scroll restoration.
|
|
631
639
|
useLayoutEffect(() => {
|
|
632
640
|
const instruction = pendingScrollRef.current;
|
|
641
|
+
// biome-ignore lint/suspicious/noUnnecessaryConditions: the ref is null until navigation schedules scrolling
|
|
633
642
|
if (!instruction) {
|
|
634
643
|
return;
|
|
635
644
|
}
|
|
@@ -872,7 +881,7 @@ export function RouterProvider({
|
|
|
872
881
|
);
|
|
873
882
|
}
|
|
874
883
|
|
|
875
|
-
|
|
884
|
+
const routerTree = (
|
|
876
885
|
<SearchStoreContext.Provider value={searchStore}>
|
|
877
886
|
{buildRouterTree(
|
|
878
887
|
{
|
|
@@ -892,6 +901,7 @@ export function RouterProvider({
|
|
|
892
901
|
pageElement,
|
|
893
902
|
{
|
|
894
903
|
digest: initialDigest,
|
|
904
|
+
document: initialDocumentState !== null,
|
|
895
905
|
onReset: () => {
|
|
896
906
|
refresh(undefined).catch((err: unknown) => {
|
|
897
907
|
log.error({ action: "boundary_reset_failed", error: String(err) });
|
|
@@ -902,4 +912,17 @@ export function RouterProvider({
|
|
|
902
912
|
)}
|
|
903
913
|
</SearchStoreContext.Provider>
|
|
904
914
|
);
|
|
915
|
+
if (initialDocumentState === null) {
|
|
916
|
+
return routerTree;
|
|
917
|
+
}
|
|
918
|
+
return (
|
|
919
|
+
<DocumentProvider
|
|
920
|
+
value={{
|
|
921
|
+
...initialDocumentState,
|
|
922
|
+
head: state.head,
|
|
923
|
+
}}
|
|
924
|
+
>
|
|
925
|
+
{routerTree}
|
|
926
|
+
</DocumentProvider>
|
|
927
|
+
);
|
|
905
928
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RouteManifest
|
|
1
|
+
import type { RouteManifest, RouteSearch, RouteTo } from "@teyik0/furin/link";
|
|
2
2
|
import { useCallback, useContext, useSyncExternalStore } from "react";
|
|
3
3
|
import {
|
|
4
4
|
findSearchDefaultsForRouteTarget,
|
|
@@ -7,19 +7,11 @@ import {
|
|
|
7
7
|
import { buildHref } from "../link-utils.ts";
|
|
8
8
|
import { FALLBACK_SEARCH_STORE, SearchStoreContext } from "../search-store.ts";
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
export type SearchRouteTo = keyof LinkRouteManifest extends never
|
|
10
|
+
export type SearchRouteTo = keyof RouteManifest extends never
|
|
13
11
|
? RouteTo
|
|
14
|
-
: (string & {}) | keyof
|
|
12
|
+
: (string & {}) | keyof RouteManifest;
|
|
15
13
|
|
|
16
|
-
type SearchRouteSearch<To extends SearchRouteTo> =
|
|
17
|
-
? RouteSearch<To & RouteTo>
|
|
18
|
-
: To extends keyof LinkRouteManifest
|
|
19
|
-
? LinkRouteManifest[To] extends { search?: infer S }
|
|
20
|
-
? S
|
|
21
|
-
: undefined
|
|
22
|
-
: undefined;
|
|
14
|
+
type SearchRouteSearch<To extends SearchRouteTo> = RouteSearch<To & RouteTo>;
|
|
23
15
|
|
|
24
16
|
export type EmptyRouteSearch = Record<PropertyKey, never>;
|
|
25
17
|
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
+
import type { RouteMap } from "@teyik0/furin/routes";
|
|
1
2
|
import type React from "react";
|
|
3
|
+
import type { HeadOptions } from "../../client.ts";
|
|
4
|
+
import type {
|
|
5
|
+
ElysiaRouteLeaf,
|
|
6
|
+
ElysiaRouteParams,
|
|
7
|
+
ElysiaRouteQuery,
|
|
8
|
+
} from "../../shared/elysia-contract.ts";
|
|
2
9
|
import type { ErrorComponent } from "../../shared/error.ts";
|
|
3
10
|
import type { NotFoundComponent } from "../../shared/not-found.ts";
|
|
4
11
|
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
5
12
|
import type { RuntimeRoute } from "../internal/runtime-types.ts";
|
|
6
13
|
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* "/": { search?: never };
|
|
18
|
-
* [key: `/blog/${string}`]: { search?: never };
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
*/
|
|
22
|
-
// biome-ignore lint/suspicious/noEmptyInterface: intentionally augmentable via furin-env.d.ts
|
|
23
|
-
export interface RouteManifest {}
|
|
14
|
+
/** Exact public projection of the generated Elysia route map. */
|
|
15
|
+
export type RouteManifest = RouteMap;
|
|
16
|
+
|
|
17
|
+
type RouteSearchInput<Route> = Route extends { elysia: infer App }
|
|
18
|
+
? unknown extends ElysiaRouteQuery<ElysiaRouteLeaf<App>>
|
|
19
|
+
? undefined
|
|
20
|
+
: ElysiaRouteQuery<ElysiaRouteLeaf<App>>
|
|
21
|
+
: undefined;
|
|
22
|
+
|
|
23
|
+
type RouteParamInput<Value> = Value extends number ? string | number : Value;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* The valid `to` pathname union derived from the
|
|
26
|
+
* The valid `to` pathname union derived from the generated RouteMap.
|
|
27
27
|
* Falls back to `string` when furin-env.d.ts has not been generated yet.
|
|
28
28
|
* When augmented, also includes `https://` and `http://` for external links.
|
|
29
29
|
*/
|
|
@@ -33,16 +33,33 @@ export type RouteTo = keyof RouteManifest extends never
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* The typed search params for a given `to` pathname.
|
|
36
|
-
* Falls back to a permissive record
|
|
36
|
+
* Falls back to a permissive record before RouteMap generation.
|
|
37
37
|
*/
|
|
38
38
|
export type RouteSearch<To extends RouteTo> = keyof RouteManifest extends never
|
|
39
39
|
? SearchParamsInput
|
|
40
40
|
: To extends keyof RouteManifest
|
|
41
|
-
? RouteManifest[To]
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
? RouteSearchInput<RouteManifest[To]>
|
|
42
|
+
: undefined;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* URL values for a route's path params: schema numbers accept both `42` and
|
|
46
|
+
* `"42"` (the URL always carries strings), everything else stays as declared.
|
|
47
|
+
* Falls back to a permissive record before RouteMap generation.
|
|
48
|
+
*/
|
|
49
|
+
export type RouteParamsOf<To extends RouteTo> = keyof RouteManifest extends never
|
|
50
|
+
? Record<string, string | number>
|
|
51
|
+
: To extends keyof RouteManifest
|
|
52
|
+
? RouteManifest[To] extends { elysia: infer App }
|
|
53
|
+
? unknown extends ElysiaRouteParams<ElysiaRouteLeaf<App>>
|
|
54
|
+
? undefined
|
|
55
|
+
: keyof ElysiaRouteParams<ElysiaRouteLeaf<App>> extends never
|
|
56
|
+
? undefined
|
|
57
|
+
: {
|
|
58
|
+
[Key in keyof ElysiaRouteParams<ElysiaRouteLeaf<App>>]: RouteParamInput<
|
|
59
|
+
ElysiaRouteParams<ElysiaRouteLeaf<App>>[Key]
|
|
60
|
+
>;
|
|
61
|
+
}
|
|
62
|
+
: undefined
|
|
46
63
|
: undefined;
|
|
47
64
|
|
|
48
65
|
export type PreloadStrategy = false | "intent" | "viewport" | "render";
|
|
@@ -66,6 +83,12 @@ export interface LinkProps<To extends RouteTo = RouteTo>
|
|
|
66
83
|
* Styles and classNames from `inactiveProps` win over the static props.
|
|
67
84
|
*/
|
|
68
85
|
inactiveProps?: () => React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
86
|
+
/**
|
|
87
|
+
* Typed path params for this route pattern: `/board/:boardId` with
|
|
88
|
+
* `{ boardId: 42 }` renders `/board/42`. Auto-completed from the route's
|
|
89
|
+
* params schema; schema numbers accept both `42` and `"42"`.
|
|
90
|
+
*/
|
|
91
|
+
params?: RouteParamsOf<To>;
|
|
69
92
|
/** Preload strategy. Default: "intent" (preload on hover/focus). */
|
|
70
93
|
preload?: PreloadStrategy;
|
|
71
94
|
/** Delay in ms before intent preload triggers. Default: 50. */
|
|
@@ -221,6 +244,7 @@ export interface RouterState {
|
|
|
221
244
|
error?: { digest: string; message: string; status: number };
|
|
222
245
|
/** The canonical href after server-side redirects (e.g. query-default redirect). */
|
|
223
246
|
finalHref?: string;
|
|
247
|
+
head?: HeadOptions;
|
|
224
248
|
/**
|
|
225
249
|
* The currently rendered route.
|
|
226
250
|
*
|
|
@@ -271,6 +295,8 @@ export interface RootBoundaryOptions {
|
|
|
271
295
|
* Server-logged error id propagated from `__FURIN_DATA__.__furinError.digest`.
|
|
272
296
|
*/
|
|
273
297
|
digest?: string;
|
|
298
|
+
/** @internal Render the root fallback as a complete document. */
|
|
299
|
+
document?: boolean;
|
|
274
300
|
onReset?: () => void;
|
|
275
301
|
resetKey?: string | number;
|
|
276
302
|
}
|