@teyik0/furin 0.1.0-alpha.11 → 0.1.0-alpha.13
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/LICENSE +21 -0
- package/README.md +251 -0
- package/dist/build/compile-entry.ts +129 -0
- package/dist/build/entry-template.ts +133 -0
- package/dist/build/index.js +453 -282
- package/dist/build/server-routes-entry.ts +55 -0
- package/dist/cli/index.js +457 -286
- package/dist/env.d.ts +50 -0
- package/dist/furin.js +402 -263
- package/dist/internal.js +17 -0
- package/dist/link.d.ts +5 -438
- package/dist/link.js +228 -137
- package/dist/plugin/index.js +9 -7
- package/dist/render/cache.d.ts +18 -5
- package/dist/render/dev-cache.d.ts +29 -0
- package/dist/render/index.ts +870 -0
- package/dist/render/route-cache.d.ts +26 -0
- package/dist/render/shell.ts +187 -0
- package/dist/router-provider.d.ts +467 -0
- package/dist/router.js +515 -368
- package/dist/router.ts +1034 -0
- package/dist/runtime-env.js +10 -0
- package/package.json +47 -17
- package/src/adapter/bun.ts +4 -1
- package/src/build/entry-template.ts +13 -6
- package/src/build/hydrate.ts +7 -5
- package/src/build/scan-server.ts +32 -3
- package/src/dev-page-plugin.ts +6 -0
- package/src/link.tsx +43 -1297
- package/src/plugin/transform-client.ts +10 -8
- package/src/render/cache.ts +77 -67
- package/src/render/dev-cache.ts +106 -15
- package/src/render/index.ts +4 -3
- package/src/render/route-cache.ts +124 -0
- package/src/router-provider.tsx +1428 -0
package/dist/internal.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/internal.ts
|
|
3
|
+
var _compileCtx = null;
|
|
4
|
+
function __setCompileContext(ctx) {
|
|
5
|
+
_compileCtx = ctx;
|
|
6
|
+
}
|
|
7
|
+
function getCompileContext() {
|
|
8
|
+
return _compileCtx;
|
|
9
|
+
}
|
|
10
|
+
function __resetCompileContext() {
|
|
11
|
+
_compileCtx = null;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
getCompileContext,
|
|
15
|
+
__setCompileContext,
|
|
16
|
+
__resetCompileContext
|
|
17
|
+
};
|
package/dist/link.d.ts
CHANGED
|
@@ -1,444 +1,12 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
import type { NotFoundComponent } from "./not-found";
|
|
2
|
+
import { type LinkProps, type RouterContextValue, type RouteTo } from "./router-provider.tsx";
|
|
3
|
+
export * from "./router-provider.tsx";
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* // furin-env.d.ts (auto-generated by Furin at project root)
|
|
11
|
-
* import "@teyik0/furin/link";
|
|
12
|
-
* declare module "@teyik0/furin/link" {
|
|
13
|
-
* interface RouteManifest {
|
|
14
|
-
* "/blog": { search?: { page?: number; tag?: string } };
|
|
15
|
-
* "/": { search?: never };
|
|
16
|
-
* [key: `/blog/${string}`]: { search?: never };
|
|
17
|
-
* }
|
|
18
|
-
* }
|
|
19
|
-
*/
|
|
20
|
-
export interface RouteManifest {
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The valid `to` pathname union derived from the augmented RouteManifest.
|
|
24
|
-
* Falls back to `string` when furin-env.d.ts has not been generated yet.
|
|
25
|
-
* When augmented, also includes `https://` and `http://` for external links.
|
|
26
|
-
*/
|
|
27
|
-
export type RouteTo = keyof RouteManifest extends never ? string : keyof RouteManifest | `https://${string}` | `http://${string}`;
|
|
28
|
-
/**
|
|
29
|
-
* The typed search params for a given `to` pathname.
|
|
30
|
-
* Falls back to a permissive record when RouteManifest is not augmented.
|
|
31
|
-
*/
|
|
32
|
-
export type RouteSearch<To extends RouteTo> = keyof RouteManifest extends never ? Record<string, string | number | boolean | null | undefined> : To extends keyof RouteManifest ? RouteManifest[To] extends {
|
|
33
|
-
search?: infer S;
|
|
34
|
-
} ? S : undefined : undefined;
|
|
35
|
-
export type PreloadStrategy = false | "intent" | "viewport" | "render";
|
|
36
|
-
export interface LinkProps<To extends RouteTo = RouteTo> extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "children"> {
|
|
37
|
-
/**
|
|
38
|
-
* Extra props merged onto the anchor when the link is active.
|
|
39
|
-
* `isActive` is also passed so one function can handle both states.
|
|
40
|
-
* Styles and classNames from `activeProps` win over the static props.
|
|
41
|
-
*/
|
|
42
|
-
activeProps?: (opts: {
|
|
43
|
-
isActive: boolean;
|
|
44
|
-
}) => React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
45
|
-
/** Static children or a render function receiving active state. */
|
|
46
|
-
children?: React.ReactNode | ((state: {
|
|
47
|
-
isActive: boolean;
|
|
48
|
-
}) => React.ReactNode);
|
|
49
|
-
/** Prevents navigation and prefetch; adds aria-disabled="true". The href stays intact for right-click. */
|
|
50
|
-
disabled?: boolean;
|
|
51
|
-
/** Optional URL fragment (without the #). */
|
|
52
|
-
hash?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Extra props merged onto the anchor when the link is NOT active.
|
|
55
|
-
* Styles and classNames from `inactiveProps` win over the static props.
|
|
56
|
-
*/
|
|
57
|
-
inactiveProps?: () => React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
58
|
-
/** Preload strategy. Default: "intent" (preload on hover/focus). */
|
|
59
|
-
preload?: PreloadStrategy;
|
|
60
|
-
/** Delay in ms before intent preload triggers. Default: 50. */
|
|
61
|
-
preloadDelay?: number;
|
|
62
|
-
/** How long a preloaded entry stays fresh (ms). Default: 30_000. */
|
|
63
|
-
preloadStaleTime?: number;
|
|
64
|
-
/** If true, uses history.replaceState instead of pushState (no new history entry). */
|
|
65
|
-
replace?: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Whether to scroll after SPA navigation. Default: true.
|
|
68
|
-
* - If the destination href has a `#hash`, scrolls to that element.
|
|
69
|
-
* - Otherwise scrolls to the top of the page.
|
|
70
|
-
* Set to `false` to suppress all scroll behaviour (e.g. tab/drawer navigation).
|
|
71
|
-
*/
|
|
72
|
-
resetScroll?: boolean;
|
|
73
|
-
/** Typed search params for this route. Auto-completed from the route's query schema. */
|
|
74
|
-
search?: RouteSearch<To>;
|
|
75
|
-
to: To;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Builds a full href string from a pathname, optional search params, and optional hash.
|
|
79
|
-
* Null/undefined search values are omitted.
|
|
80
|
-
*
|
|
81
|
-
* @internal Exported for unit testing only.
|
|
82
|
-
*/
|
|
83
|
-
export declare function buildHref(to: string, search?: Record<string, unknown> | null, hash?: string): string;
|
|
84
|
-
/**
|
|
85
|
-
* Parses the `X-Furin-Revalidate` response header and calls `invalidate` for
|
|
86
|
-
* each path entry. Header format: `"/path1,/path2:layout,/path3"`
|
|
87
|
-
*
|
|
88
|
-
* Intended to be called from a `window.fetch` interceptor or SPA navigation
|
|
89
|
-
* handler so that client-side prefetch caches are busted automatically whenever
|
|
90
|
-
* a server-side `revalidatePath()` call is made within the same request.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* const res = await fetch("/api/publish");
|
|
95
|
-
* applyRevalidateHeader(res.headers, (path, type) => {
|
|
96
|
-
* console.log("invalidate", path, type);
|
|
97
|
-
* });
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
export declare function applyRevalidateHeader(headers: Headers, invalidate: (path: string, type?: "page" | "layout") => void): void;
|
|
101
|
-
/**
|
|
102
|
-
* Returns `true` when `currentPath` is targeted by at least one invalidation entry,
|
|
103
|
-
* using the same matching rules as `invalidatePrefetch`:
|
|
104
|
-
* - `type: 'page'` — exact pathname match (query string stripped)
|
|
105
|
-
* - `type: 'layout'` — prefix match: the path itself OR any descendant
|
|
106
|
-
*
|
|
107
|
-
* @internal Exported for unit testing only.
|
|
108
|
-
*/
|
|
109
|
-
export declare function shouldAutoRefreshPath(currentPath: string, invalidations: ReadonlyArray<{
|
|
110
|
-
path: string;
|
|
111
|
-
type: "page" | "layout";
|
|
112
|
-
}>): boolean;
|
|
113
|
-
export interface RouterContextValue {
|
|
114
|
-
/**
|
|
115
|
-
* Sub-path prefix for static deployments (e.g. "/furin").
|
|
116
|
-
* Empty string when the site is served from root.
|
|
117
|
-
* Used by `Link` to build correct physical hrefs for the `<a>` element.
|
|
118
|
-
*/
|
|
119
|
-
basePath: string;
|
|
120
|
-
/** Current **logical** pathname + search (basePath stripped). Used by Link for active-state detection. */
|
|
121
|
-
currentHref: string;
|
|
122
|
-
defaultPreload: PreloadStrategy;
|
|
123
|
-
defaultPreloadDelay: number;
|
|
124
|
-
defaultPreloadStaleTime: number;
|
|
125
|
-
/**
|
|
126
|
-
* Evicts one or more prefetch cache entries, mirroring a `revalidatePath()` call
|
|
127
|
-
* made on the server. Called automatically by the `window.fetch` interceptor when
|
|
128
|
-
* the server emits `X-Furin-Revalidate` headers.
|
|
129
|
-
*
|
|
130
|
-
* - `type: 'page'` (default) — exact URL match
|
|
131
|
-
* - `type: 'layout'` — prefix match (path + all nested children)
|
|
132
|
-
*/
|
|
133
|
-
invalidatePrefetch: (path: string, type?: "page" | "layout") => void;
|
|
134
|
-
isNavigating: boolean;
|
|
135
|
-
navigate: (href: string, opts?: {
|
|
136
|
-
replace?: boolean;
|
|
137
|
-
resetScroll?: boolean;
|
|
138
|
-
}) => Promise<void>;
|
|
139
|
-
prefetch: (href: string, opts?: {
|
|
140
|
-
staleTime?: number;
|
|
141
|
-
}) => void;
|
|
142
|
-
/**
|
|
143
|
-
* Re-fetches the current page in-place: busts the prefetch cache entry, re-runs
|
|
144
|
-
* loaders, and updates the rendered tree — without adding a history entry or
|
|
145
|
-
* resetting scroll (unless `resetScroll: true` is passed).
|
|
146
|
-
*
|
|
147
|
-
* Prefer this over `navigate(window.location.pathname)` after a mutation.
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```tsx
|
|
151
|
-
* const { refresh } = useRouter();
|
|
152
|
-
* await apiClient.api.boards.post({ name });
|
|
153
|
-
* await refresh();
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
refresh: (opts?: {
|
|
157
|
-
resetScroll?: boolean;
|
|
158
|
-
}) => Promise<void>;
|
|
159
|
-
}
|
|
160
|
-
export declare const RouterContext: React.Context<RouterContextValue | null>;
|
|
161
|
-
/**
|
|
162
|
-
* Returns the current router context.
|
|
163
|
-
* Provides a graceful fallback (full-page navigation) when used outside RouterProvider.
|
|
164
|
-
*/
|
|
165
|
-
export declare function useRouter(): RouterContextValue;
|
|
166
|
-
/**
|
|
167
|
-
* Client-side mirror of `SegmentBoundary` from router.ts. Unlike the server
|
|
168
|
-
* version this does NOT carry the directory path — it's purely a (depth,
|
|
169
|
-
* fallback) pair because the client never reads files, only renders.
|
|
170
|
-
*
|
|
171
|
-
* Emitted by `generateHydrateEntry` from the scanned `segmentBoundaries`
|
|
172
|
-
* array: each route's entry lists ONLY the directories on its path that
|
|
173
|
-
* declare a convention file, so routes with no error.tsx / not-found.tsx
|
|
174
|
-
* anywhere carry an empty list (or omit the field entirely).
|
|
175
|
-
*/
|
|
176
|
-
export interface ClientSegmentBoundary {
|
|
177
|
-
depth: number;
|
|
178
|
-
error?: ErrorComponent;
|
|
179
|
-
notFound?: NotFoundComponent;
|
|
180
|
-
}
|
|
181
|
-
export interface ClientRoute {
|
|
182
|
-
component?: React.ComponentType<Record<string, unknown>>;
|
|
183
|
-
load: () => Promise<{
|
|
184
|
-
default: {
|
|
185
|
-
component: React.ComponentType<Record<string, unknown>>;
|
|
186
|
-
_route: RuntimeRoute;
|
|
187
|
-
};
|
|
188
|
-
}>;
|
|
189
|
-
pageRoute?: RuntimeRoute;
|
|
190
|
-
pattern: string;
|
|
191
|
-
regex: RegExp;
|
|
192
|
-
/**
|
|
193
|
-
* Per-segment boundary chain, ordered shallow→deep. Each `depth` maps 1:1
|
|
194
|
-
* to the route-chain index used on the server side, so `buildPageElement`
|
|
195
|
-
* can interleave boundaries at the exact same positions that the server
|
|
196
|
-
* used in `buildElement` — guaranteeing hydration consistency.
|
|
197
|
-
*/
|
|
198
|
-
segmentBoundaries?: ClientSegmentBoundary[];
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* A ClientRoute that has been loaded — component and pageRoute are guaranteed defined.
|
|
202
|
-
* The initial route is eagerly loaded in the hydrate entry; subsequent routes are loaded
|
|
203
|
-
* on navigation via fetchPageState.
|
|
204
|
-
*/
|
|
205
|
-
export type LoadedClientRoute = ClientRoute & {
|
|
206
|
-
component: React.ComponentType<Record<string, unknown>>;
|
|
207
|
-
pageRoute: RuntimeRoute;
|
|
208
|
-
};
|
|
209
|
-
export interface RouterProviderProps {
|
|
210
|
-
/**
|
|
211
|
-
* When `true` (default), the router automatically re-fetches the current page
|
|
212
|
-
* whenever a server `revalidatePath()` call targets it. The signal is the
|
|
213
|
-
* `X-Furin-Revalidate` header detected on any `window.fetch` response.
|
|
214
|
-
*
|
|
215
|
-
* Set to `false` to opt out and call `router.refresh()` manually instead.
|
|
216
|
-
*/
|
|
217
|
-
autoRefresh?: boolean;
|
|
218
|
-
/**
|
|
219
|
-
* Sub-path prefix for static deployments (e.g. "/furin").
|
|
220
|
-
* Must start with "/" and have no trailing slash.
|
|
221
|
-
* Default: "" (site served from root).
|
|
222
|
-
*
|
|
223
|
-
* When set:
|
|
224
|
-
* - `currentHref` stores **logical** paths (prefix stripped) for correct active-state detection.
|
|
225
|
-
* - `navigate(logicalHref)` pushes `basePath + logicalHref` to browser history.
|
|
226
|
-
* - `fetch` calls use the physical path `basePath + logicalHref`.
|
|
227
|
-
*/
|
|
228
|
-
basePath?: string;
|
|
229
|
-
defaultPreload?: PreloadStrategy;
|
|
230
|
-
defaultPreloadDelay?: number;
|
|
231
|
-
defaultPreloadStaleTime?: number;
|
|
232
|
-
initialData: Record<string, unknown>;
|
|
233
|
-
/**
|
|
234
|
-
* Slice 10 — server-logged error digest threaded from
|
|
235
|
-
* `__FURIN_DATA__.__furinError.digest`. Forwarded onto the root-level
|
|
236
|
-
* `FurinErrorBoundary` so that if a client-side error escapes the
|
|
237
|
-
* per-segment boundaries (root layout crash, hydration mismatch, …), the
|
|
238
|
-
* fallback UI surfaces the id a user would find in server logs.
|
|
239
|
-
* Undefined when the initial SSR response was successful (no server-side
|
|
240
|
-
* error digest to correlate).
|
|
241
|
-
*/
|
|
242
|
-
initialDigest: string | undefined;
|
|
243
|
-
/**
|
|
244
|
-
* The route matched at hydration time. `null` is a valid value ONLY when
|
|
245
|
-
* `initialNotFound` is also provided — it signals the initial URL didn't
|
|
246
|
-
* match any registered route (direct load to an unknown URL). The provider
|
|
247
|
-
* then mounts in a "not-found" state so the root `not-found.tsx` hydrates
|
|
248
|
-
* inside a live RouterContext — critical for Links in the not-found UI to
|
|
249
|
-
* participate in SPA navigation instead of triggering a full-page reload.
|
|
250
|
-
*/
|
|
251
|
-
initialMatch: LoadedClientRoute | null;
|
|
252
|
-
/**
|
|
253
|
-
* When set, the provider boots into the inline not-found state as if a
|
|
254
|
-
* prior SPA navigation hit a 404. Callers set this when the server-rendered
|
|
255
|
-
* HTML carries `__FURIN_DATA__.__furinStatus === 404` — either because the
|
|
256
|
-
* loader threw `notFound()` (rare at hydration time) or, more commonly,
|
|
257
|
-
* because the URL didn't match any client route and `initialMatch` is
|
|
258
|
-
* `null`. In the unmatched-URL case the depth-0 `rootBoundaries` are used
|
|
259
|
-
* as the boundary chain, matching the server's `renderRootNotFound` choice.
|
|
260
|
-
*/
|
|
261
|
-
initialNotFound: {
|
|
262
|
-
data?: unknown;
|
|
263
|
-
message?: string;
|
|
264
|
-
} | undefined;
|
|
265
|
-
/** Maximum number of prefetch cache entries. Oldest entry is evicted when exceeded. Default: 50. */
|
|
266
|
-
prefetchCacheSize?: number;
|
|
267
|
-
root: RuntimeRoute | null;
|
|
268
|
-
routes: ClientRoute[];
|
|
269
|
-
}
|
|
270
|
-
interface RouterState {
|
|
271
|
-
data: Record<string, unknown>;
|
|
272
|
-
/** The canonical href after server-side redirects (e.g. query-default redirect). */
|
|
273
|
-
finalHref?: string;
|
|
274
|
-
/**
|
|
275
|
-
* The currently rendered route.
|
|
276
|
-
*
|
|
277
|
-
* `null` is a valid value ONLY when `notFound` is also set — it signals the
|
|
278
|
-
* initial URL didn't match any registered route (direct load to an unknown
|
|
279
|
-
* URL). In that case the provider renders the root `not-found.tsx` directly
|
|
280
|
-
* and waits for the next `navigate()` call to populate `match`. Every other
|
|
281
|
-
* state (including loader-triggered `notFound()` on a matched route) keeps a
|
|
282
|
-
* non-null `match`. Render code MUST guard on `notFound` before dereferencing.
|
|
283
|
-
*/
|
|
284
|
-
match: LoadedClientRoute | null;
|
|
285
|
-
/**
|
|
286
|
-
* Slice 8 — set when the matched route's loader threw `notFound()` on the
|
|
287
|
-
* server (signalled via `__FURIN_DATA__.__furinStatus === 404`). Triggers
|
|
288
|
-
* inline rendering of the deepest segment-level not-found.tsx instead of
|
|
289
|
-
* the normal layout+page tree, mirroring the server's `buildNotFoundElement`.
|
|
290
|
-
*/
|
|
291
|
-
notFound?: {
|
|
292
|
-
data?: unknown;
|
|
293
|
-
message?: string;
|
|
294
|
-
};
|
|
295
|
-
/**
|
|
296
|
-
* Explicit boundary chain to use for the not-found render.
|
|
297
|
-
*
|
|
298
|
-
* - **Set** (typically to depth-0 only) when no client-side route matched the
|
|
299
|
-
* navigation URL — the root `not-found.tsx` is the correct fallback and no
|
|
300
|
-
* page-specific segment context exists.
|
|
301
|
-
* - **Absent** when a matched route's loader called `notFound()`, in which
|
|
302
|
-
* case `match.segmentBoundaries` is used (preserves per-route not-found).
|
|
303
|
-
*/
|
|
304
|
-
notFoundBoundaries?: ClientSegmentBoundary[] | undefined;
|
|
305
|
-
title?: string;
|
|
306
|
-
}
|
|
307
|
-
/** @internal */
|
|
308
|
-
export interface CacheEntry {
|
|
309
|
-
createdAt: number;
|
|
310
|
-
promise: Promise<RouterState | null>;
|
|
311
|
-
staleTime: number;
|
|
312
|
-
}
|
|
313
|
-
/** @internal Exported for unit testing only. */
|
|
314
|
-
export declare function shouldRefetch(entry: CacheEntry): boolean;
|
|
315
|
-
/**
|
|
316
|
-
* Classification of a fetch response during SPA navigation. Returned by the
|
|
317
|
-
* pure `classifySpaResponse` so `fetchPageState` stays a thin orchestrator.
|
|
318
|
-
*
|
|
319
|
-
* - `ok` — 2xx response with usable loader data; render normally.
|
|
320
|
-
* - `not-found` — server signalled `__FURIN_DATA__.__furinStatus === 404`; the
|
|
321
|
-
* caller should render the not-found UI inline (no full-page reload).
|
|
322
|
-
* - `bail` — any other non-2xx (5xx, stale-deploy, unparseable payload…);
|
|
323
|
-
* the caller falls back to a full-page navigation so the browser picks up
|
|
324
|
-
* whatever the server wants to send (could be an error page, redirect, etc.).
|
|
325
|
-
*
|
|
326
|
-
* @internal Exported for unit testing only.
|
|
327
|
-
*/
|
|
328
|
-
export type SpaResponseKind = {
|
|
329
|
-
kind: "ok";
|
|
330
|
-
} | {
|
|
331
|
-
kind: "not-found";
|
|
332
|
-
error: {
|
|
333
|
-
data?: unknown;
|
|
334
|
-
message?: string;
|
|
335
|
-
};
|
|
336
|
-
} | {
|
|
337
|
-
kind: "bail";
|
|
338
|
-
};
|
|
339
|
-
/**
|
|
340
|
-
* Pure classifier for an SPA-nav fetch result. Takes the HTTP status and the
|
|
341
|
-
* already-parsed `__FURIN_DATA__` payload. The 404 signal is trusted over the
|
|
342
|
-
* HTTP status (guards against proxies that rewrite status but preserve body),
|
|
343
|
-
* while any other non-ok HTTP status triggers a bail even if the payload is
|
|
344
|
-
* well-formed.
|
|
345
|
-
*
|
|
346
|
-
* @internal Exported for unit testing only.
|
|
347
|
-
*/
|
|
348
|
-
export declare function classifySpaResponse(status: number, data: Record<string, unknown> | null): SpaResponseKind;
|
|
349
|
-
/**
|
|
350
|
-
* Picks the deepest not-found component declared on the match's boundary
|
|
351
|
-
* chain. Mirrors the server's `route.notFound ?? root.notFound` selection:
|
|
352
|
-
* since `segmentBoundaries` is ordered shallow→deep, the last entry with a
|
|
353
|
-
* `notFound` wins. Returns undefined when no boundary on the chain declares
|
|
354
|
-
* a not-found convention.
|
|
355
|
-
*
|
|
356
|
-
* @internal Exported for unit testing only.
|
|
357
|
-
*/
|
|
358
|
-
export declare function pickDeepestNotFound(boundaries: ClientSegmentBoundary[] | undefined): NotFoundComponent | undefined;
|
|
359
|
-
/**
|
|
360
|
-
* Builds the bare not-found element rendered inline by RouterProvider on SPA
|
|
361
|
-
* navigation when the server signalled a 404. Matches the server's
|
|
362
|
-
* `buildNotFoundElement` exactly — NO layouts, NO segment boundaries, just the
|
|
363
|
-
* deepest user-declared `not-found.tsx` (or the built-in default). Preserving
|
|
364
|
-
* layouts on 404 is a deliberate non-goal for this slice: it would diverge
|
|
365
|
-
* from the server's current behaviour and require coordinated changes on both
|
|
366
|
-
* sides.
|
|
367
|
-
*
|
|
368
|
-
* Accepts the boundary chain directly (rather than a full `LoadedClientRoute`)
|
|
369
|
-
* so callers can pass a subset (e.g. depth-0 only for unmatched URLs) without
|
|
370
|
-
* fabricating a synthetic route object.
|
|
371
|
-
*
|
|
372
|
-
* @internal Exported for unit testing only.
|
|
373
|
-
*/
|
|
374
|
-
export declare function buildNotFoundPageElement(boundaries: ClientSegmentBoundary[] | undefined, error: {
|
|
375
|
-
data?: unknown;
|
|
376
|
-
message?: string;
|
|
377
|
-
}): React.ReactNode;
|
|
378
|
-
/**
|
|
379
|
-
* Root-level safety-net options forwarded onto the outermost
|
|
380
|
-
* `FurinErrorBoundary` that wraps the entire RouterProvider tree. See
|
|
381
|
-
* `buildRouterTree` for the full rationale.
|
|
382
|
-
*/
|
|
383
|
-
export interface RootBoundaryOptions {
|
|
384
|
-
/**
|
|
385
|
-
* Server-logged error id propagated from `__FURIN_DATA__.__furinError.digest`.
|
|
386
|
-
* When the server's SSR response carried a digest (loader error or shell
|
|
387
|
-
* recovery) this value lets the client's fallback UI display the SAME id a
|
|
388
|
-
* user would find in the server logs — without having to recompute and
|
|
389
|
-
* potentially produce a different hash from a different error instance.
|
|
390
|
-
*/
|
|
391
|
-
digest?: string;
|
|
392
|
-
onReset?: () => void;
|
|
393
|
-
resetKey?: string | number;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Composes the outermost tree produced by `RouterProvider`:
|
|
397
|
-
*
|
|
398
|
-
* <FurinErrorBoundary digest onReset resetKey>
|
|
399
|
-
* <RouterContext.Provider value={context}>
|
|
400
|
-
* {pageElement}
|
|
401
|
-
* </RouterContext.Provider>
|
|
402
|
-
* </FurinErrorBoundary>
|
|
403
|
-
*
|
|
404
|
-
* This top boundary is the LAST line of defence. Per-segment
|
|
405
|
-
* `FurinErrorBoundary`s inserted by `buildPageElement` only wrap the page
|
|
406
|
-
* subtree BELOW the root layout, so they cannot catch errors thrown in:
|
|
407
|
-
* - the root layout itself,
|
|
408
|
-
* - hydration mismatches (these tear the whole tree before any inner
|
|
409
|
-
* boundary is reached),
|
|
410
|
-
* - the RouterProvider / page-building scaffolding code.
|
|
411
|
-
*
|
|
412
|
-
* We deliberately omit the `fallback` prop so the boundary falls back to its
|
|
413
|
-
* built-in `DefaultErrorFallback` — if a user-authored fallback crashed
|
|
414
|
-
* during its own render, we'd still have a guaranteed-to-render UI here.
|
|
415
|
-
* Users who want a custom *branded* global error UI author a root-level
|
|
416
|
-
* `error.tsx`; that convention is already picked up by `segmentBoundaries`
|
|
417
|
-
* at depth 0 and sits inside this top boundary.
|
|
418
|
-
*
|
|
419
|
-
* @internal Exported for unit testing only.
|
|
420
|
-
*/
|
|
421
|
-
export declare function buildRouterTree(context: RouterContextValue, pageElement: React.ReactNode, options: RootBoundaryOptions): React.ReactElement;
|
|
422
|
-
/**
|
|
423
|
-
* Options threaded from `RouterProvider` (or a test harness) into each
|
|
424
|
-
* boundary that `buildPageElement` inserts:
|
|
425
|
-
*
|
|
426
|
-
* - `onReset` — invoked by `FurinErrorBoundary.reset` after it clears local
|
|
427
|
-
* error state. RouterProvider wires this to `refresh()` so the user's
|
|
428
|
-
* `reset()` prop re-runs the current route's loaders in addition to
|
|
429
|
-
* remounting the subtree.
|
|
430
|
-
* - `resetKey` — when it changes, both boundary classes clear their latched
|
|
431
|
-
* error. RouterProvider passes `currentHref`, so navigating between
|
|
432
|
-
* sibling routes that share a boundary (e.g. /blog/a → /blog/b) auto-clears
|
|
433
|
-
* any stuck error state even when the boundary instance persists.
|
|
5
|
+
* Static fallback used by Link during SSR when there is no RouterProvider.
|
|
6
|
+
* Must not reference `window` — this object is created at module parse time.
|
|
434
7
|
*/
|
|
435
|
-
export interface BoundaryOptions {
|
|
436
|
-
onReset?: () => void;
|
|
437
|
-
resetKey?: string | number;
|
|
438
|
-
}
|
|
439
8
|
/** @internal Exported for unit testing only. */
|
|
440
|
-
export declare
|
|
441
|
-
export declare function RouterProvider({ routes, root, initialMatch, initialData, initialDigest, initialNotFound, autoRefresh, basePath, defaultPreload, defaultPreloadDelay, defaultPreloadStaleTime, prefetchCacheSize, }: RouterProviderProps): React.ReactElement;
|
|
9
|
+
export declare const SSR_FALLBACK_ROUTER: RouterContextValue;
|
|
442
10
|
/**
|
|
443
11
|
* SSR-aware Link component.
|
|
444
12
|
*
|
|
@@ -451,4 +19,3 @@ export declare function RouterProvider({ routes, root, initialMatch, initialData
|
|
|
451
19
|
* navigation, active-state tracking and all other interactive features.
|
|
452
20
|
*/
|
|
453
21
|
export declare function Link<To extends RouteTo>(props: LinkProps<To>): React.ReactElement;
|
|
454
|
-
export {};
|