@teyik0/furin 0.1.0-alpha.10

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.
Files changed (87) hide show
  1. package/dist/adapter/bun.d.ts +3 -0
  2. package/dist/adapter/static.d.ts +3 -0
  3. package/dist/build/client.d.ts +25 -0
  4. package/dist/build/compile-entry.d.ts +35 -0
  5. package/dist/build/entry-template.d.ts +26 -0
  6. package/dist/build/hydrate.d.ts +24 -0
  7. package/dist/build/index.d.ts +7 -0
  8. package/dist/build/index.js +4716 -0
  9. package/dist/build/route-types.d.ts +21 -0
  10. package/dist/build/scan-server.d.ts +8 -0
  11. package/dist/build/server-routes-entry.d.ts +35 -0
  12. package/dist/build/shared.d.ts +11 -0
  13. package/dist/build/types.d.ts +76 -0
  14. package/dist/cli/config.d.ts +9 -0
  15. package/dist/cli/index.d.ts +2 -0
  16. package/dist/cli/index.js +4751 -0
  17. package/dist/client.d.ts +195 -0
  18. package/dist/client.js +20 -0
  19. package/dist/config.d.ts +50 -0
  20. package/dist/config.js +28 -0
  21. package/dist/context-logger.d.ts +28 -0
  22. package/dist/dev-page-plugin.d.ts +109 -0
  23. package/dist/error.d.ts +23 -0
  24. package/dist/furin.d.ts +52 -0
  25. package/dist/furin.js +3948 -0
  26. package/dist/internal.d.ts +33 -0
  27. package/dist/link.d.ts +454 -0
  28. package/dist/link.js +1790 -0
  29. package/dist/not-found.d.ts +19 -0
  30. package/dist/plugin/index.d.ts +20 -0
  31. package/dist/plugin/index.js +1408 -0
  32. package/dist/plugin/transform-client.d.ts +9 -0
  33. package/dist/render/assemble.d.ts +15 -0
  34. package/dist/render/boundaries.d.ts +79 -0
  35. package/dist/render/cache.d.ts +96 -0
  36. package/dist/render/default-screens.d.ts +11 -0
  37. package/dist/render/digest.d.ts +16 -0
  38. package/dist/render/element.d.ts +8 -0
  39. package/dist/render/index.d.ts +53 -0
  40. package/dist/render/loaders.d.ts +21 -0
  41. package/dist/render/shell.d.ts +29 -0
  42. package/dist/render/template.d.ts +6 -0
  43. package/dist/router.d.ts +96 -0
  44. package/dist/router.js +2693 -0
  45. package/dist/runtime-env.d.ts +3 -0
  46. package/dist/utils.d.ts +6 -0
  47. package/package.json +77 -0
  48. package/src/adapter/README.md +13 -0
  49. package/src/adapter/bun.ts +239 -0
  50. package/src/adapter/static.ts +341 -0
  51. package/src/build/client.ts +153 -0
  52. package/src/build/compile-entry.ts +129 -0
  53. package/src/build/entry-template.ts +126 -0
  54. package/src/build/hydrate.ts +250 -0
  55. package/src/build/index.ts +151 -0
  56. package/src/build/route-types.ts +89 -0
  57. package/src/build/scan-server.ts +110 -0
  58. package/src/build/server-routes-entry.ts +55 -0
  59. package/src/build/shared.ts +78 -0
  60. package/src/build/types.ts +85 -0
  61. package/src/cli/config.ts +68 -0
  62. package/src/cli/index.ts +115 -0
  63. package/src/client.ts +278 -0
  64. package/src/config.ts +66 -0
  65. package/src/context-logger.ts +74 -0
  66. package/src/dev-page-plugin.ts +434 -0
  67. package/src/env.d.ts +49 -0
  68. package/src/error.ts +32 -0
  69. package/src/furin.ts +383 -0
  70. package/src/internal.ts +51 -0
  71. package/src/link.tsx +1578 -0
  72. package/src/not-found.ts +40 -0
  73. package/src/plugin/index.ts +80 -0
  74. package/src/plugin/transform-client.ts +372 -0
  75. package/src/render/assemble.ts +66 -0
  76. package/src/render/boundaries.tsx +176 -0
  77. package/src/render/cache.ts +251 -0
  78. package/src/render/default-screens.tsx +299 -0
  79. package/src/render/digest.ts +71 -0
  80. package/src/render/element.tsx +119 -0
  81. package/src/render/index.ts +867 -0
  82. package/src/render/loaders.ts +127 -0
  83. package/src/render/shell.ts +187 -0
  84. package/src/render/template.ts +55 -0
  85. package/src/router.ts +779 -0
  86. package/src/runtime-env.ts +6 -0
  87. package/src/utils.ts +68 -0
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Built-in fallback UIs for the framework's default 404 and 500 pages.
3
+ *
4
+ * Design constraints:
5
+ * 1. INLINE STYLES ONLY. We can't assume the user has Tailwind / a CSS
6
+ * reset / any stylesheet at all — the page must look identical whether
7
+ * this renders before or after the user's stylesheets.
8
+ * 2. ZERO RUNTIME DEPENDENCIES. These render server-side as static HTML and
9
+ * hydrate without needing any JS to look right. Only the "Try again"
10
+ * button needs hydration to function (it falls back to a no-op on SSR).
11
+ * 3. NO EXTERNAL FONTS. Use the system monospace + sans stacks so the
12
+ * typography is consistent without a network round-trip.
13
+ *
14
+ * Visual language: terminal/dev-tool aesthetic — black background, faint
15
+ * grid, monospace for technical bits, no chrome. Hierarchy is carried by
16
+ * typography + spacing alone so the screen feels at-home in any project
17
+ * regardless of brand.
18
+ */
19
+ import type { CSSProperties, ReactNode } from "react";
20
+ import { Link } from "../link";
21
+
22
+ const FONT_SANS =
23
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
24
+ const FONT_MONO =
25
+ 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace';
26
+
27
+ const COLOR_BG = "#000000";
28
+ const COLOR_TEXT = "#ffffff";
29
+ const COLOR_TEXT_DIM = "rgba(255, 255, 255, 0.7)";
30
+ const COLOR_TEXT_MUTED = "rgba(255, 255, 255, 0.45)";
31
+ const COLOR_GRID = "rgba(255, 255, 255, 0.04)";
32
+ const COLOR_BRACKET = "rgba(255, 255, 255, 0.55)";
33
+ const COLOR_DANGER_DIM = "rgba(239, 68, 68, 0.6)";
34
+
35
+ const PAGE_STYLE: CSSProperties = {
36
+ alignItems: "center",
37
+ backgroundColor: COLOR_BG,
38
+ // Faint grid: two repeating gradients crossed for the lattice look.
39
+ backgroundImage: `
40
+ linear-gradient(${COLOR_GRID} 1px, transparent 1px),
41
+ linear-gradient(90deg, ${COLOR_GRID} 1px, transparent 1px)
42
+ `,
43
+ backgroundSize: "32px 32px, 32px 32px",
44
+ boxSizing: "border-box",
45
+ color: COLOR_TEXT,
46
+ display: "flex",
47
+ fontFamily: FONT_SANS,
48
+ fontSize: "16px",
49
+ justifyContent: "center",
50
+ lineHeight: 1.5,
51
+ margin: 0,
52
+ minHeight: "100vh",
53
+ padding: "32px",
54
+ width: "100%",
55
+ };
56
+
57
+ const FRAME_STYLE: CSSProperties = {
58
+ boxSizing: "border-box",
59
+ maxWidth: "880px",
60
+ position: "relative",
61
+ width: "100%",
62
+ };
63
+
64
+ const BRACKET_BASE: CSSProperties = {
65
+ height: "40px",
66
+ position: "absolute",
67
+ width: "40px",
68
+ };
69
+
70
+ function CornerBracket({ corner }: { corner: "tl" | "tr" | "bl" | "br" }) {
71
+ // L-shaped bracket built from two 2px borders on the inside corners.
72
+ const top = corner === "tl" || corner === "tr";
73
+ const left = corner === "tl" || corner === "bl";
74
+ const style: CSSProperties = {
75
+ ...BRACKET_BASE,
76
+ [top ? "top" : "bottom"]: 0,
77
+ [left ? "left" : "right"]: 0,
78
+ [`border${top ? "Top" : "Bottom"}`]: `2px solid ${COLOR_BRACKET}`,
79
+ [`border${left ? "Left" : "Right"}`]: `2px solid ${COLOR_BRACKET}`,
80
+ };
81
+ return <span aria-hidden="true" style={style} />;
82
+ }
83
+
84
+ const CARD_STYLE: CSSProperties = {
85
+ boxSizing: "border-box",
86
+ margin: "0 auto",
87
+ maxWidth: "640px",
88
+ padding: "64px 24px",
89
+ textAlign: "center",
90
+ };
91
+
92
+ // Borders are deliberately absent on every element except the danger-coloured
93
+ // error badge. The visual hierarchy is carried by typography + spacing alone.
94
+
95
+ const BADGE_STYLE: CSSProperties = {
96
+ border: `1px solid ${COLOR_DANGER_DIM}`,
97
+ color: COLOR_TEXT,
98
+ display: "inline-block",
99
+ fontFamily: FONT_SANS,
100
+ fontSize: "32px",
101
+ fontWeight: 600,
102
+ letterSpacing: "0.08em",
103
+ marginBottom: "16px",
104
+ padding: "12px 36px",
105
+ };
106
+
107
+ // 404 isn't an "error" in the same sense as a 500, so we drop the danger ring
108
+ // entirely and let the typography stand on its own.
109
+ const NOT_FOUND_BADGE_STYLE: CSSProperties = {
110
+ ...BADGE_STYLE,
111
+ border: 0,
112
+ padding: 0,
113
+ };
114
+
115
+ const HEADING_STYLE: CSSProperties = {
116
+ color: COLOR_TEXT,
117
+ fontFamily: FONT_SANS,
118
+ fontSize: "24px",
119
+ fontWeight: 600,
120
+ margin: "0 0 24px 0",
121
+ };
122
+
123
+ const CODE_BOX_STYLE: CSSProperties = {
124
+ color: COLOR_TEXT_DIM,
125
+ display: "inline-block",
126
+ fontFamily: FONT_MONO,
127
+ fontSize: "13px",
128
+ letterSpacing: "0.02em",
129
+ margin: "0 0 32px 0",
130
+ padding: "8px 0",
131
+ };
132
+
133
+ const CODE_LABEL_STYLE: CSSProperties = {
134
+ color: COLOR_TEXT_MUTED,
135
+ marginRight: "10px",
136
+ textTransform: "uppercase",
137
+ };
138
+
139
+ const DESCRIPTION_WRAPPER_STYLE: CSSProperties = {
140
+ color: COLOR_TEXT_DIM,
141
+ fontSize: "15px",
142
+ margin: "0 auto 40px auto",
143
+ maxWidth: "440px",
144
+ padding: 0,
145
+ textAlign: "center",
146
+ };
147
+
148
+ const ACTIONS_STYLE: CSSProperties = {
149
+ display: "flex",
150
+ flexWrap: "wrap",
151
+ gap: "16px",
152
+ justifyContent: "center",
153
+ };
154
+
155
+ const BUTTON_BASE: CSSProperties = {
156
+ border: 0,
157
+ cursor: "pointer",
158
+ display: "inline-flex",
159
+ fontFamily: FONT_SANS,
160
+ fontSize: "14px",
161
+ fontWeight: 500,
162
+ lineHeight: 1,
163
+ minWidth: "120px",
164
+ padding: "10px 16px",
165
+ textAlign: "center",
166
+ textDecoration: "none",
167
+ transition: "background-color 120ms ease, color 120ms ease, opacity 120ms ease",
168
+ appearance: "none",
169
+ alignItems: "center",
170
+ justifyContent: "center",
171
+ boxSizing: "border-box",
172
+ };
173
+
174
+ // Outlined buttons: thin neutral border, no fill — discreet enough to blend
175
+ // with the dark canvas while still reading as a clickable affordance.
176
+ const BUTTON_PRIMARY: CSSProperties = {
177
+ ...BUTTON_BASE,
178
+ backgroundColor: COLOR_TEXT,
179
+ border: `1px solid ${COLOR_TEXT}`,
180
+ boxShadow: "0 10px 24px rgba(255, 255, 255, 0.08)",
181
+ color: COLOR_BG,
182
+ fontWeight: 600,
183
+ };
184
+
185
+ const BUTTON_SECONDARY: CSSProperties = {
186
+ ...BUTTON_BASE,
187
+ backgroundColor: "transparent",
188
+ border: "1px solid rgba(255, 255, 255, 0.22)",
189
+ color: COLOR_TEXT_DIM,
190
+ };
191
+
192
+ // Hairline rule under the badge — the only neutral chrome line we keep, just
193
+ // to anchor the badge visually without competing with it.
194
+ const DIVIDER_STYLE: CSSProperties = {
195
+ backgroundColor: "rgba(255, 255, 255, 0.12)",
196
+ border: 0,
197
+ height: "1px",
198
+ margin: "0 0 40px 0",
199
+ width: "100%",
200
+ };
201
+
202
+ interface ScreenFrameProps {
203
+ badge: ReactNode;
204
+ children: ReactNode;
205
+ }
206
+
207
+ /**
208
+ * Reset the host page's chrome so the dark background covers the entire
209
+ * viewport — including the area behind the scrollbar and the default 8px
210
+ * margin browsers apply to <body>. We can't do this with inline styles
211
+ * alone (they only target the element they're on, not html/body), and we
212
+ * can't ship a CSS file (the user might not have Tailwind / a bundler
213
+ * step). React 19 hoists <style> nodes to <head> automatically, so this
214
+ * works in both SSR and hydration without a flash of white chrome.
215
+ *
216
+ * `overscroll-behavior: none` also prevents the white "bounce" area on
217
+ * macOS Safari / Chrome when scrolling past the viewport edges.
218
+ */
219
+ const RESET_CSS = `
220
+ html, body {
221
+ margin: 0;
222
+ padding: 0;
223
+ background-color: ${COLOR_BG};
224
+ overscroll-behavior: none;
225
+ }
226
+ `;
227
+
228
+ function ScreenFrame({ badge, children }: ScreenFrameProps) {
229
+ return (
230
+ <div style={PAGE_STYLE}>
231
+ {/* biome-ignore lint/security/noDangerouslySetInnerHtml: literal CSS string, no user input */}
232
+ <style dangerouslySetInnerHTML={{ __html: RESET_CSS }} />
233
+ <div style={FRAME_STYLE}>
234
+ <CornerBracket corner="tl" />
235
+ <CornerBracket corner="tr" />
236
+ <CornerBracket corner="bl" />
237
+ <CornerBracket corner="br" />
238
+ <div style={CARD_STYLE}>
239
+ {badge}
240
+ <hr style={DIVIDER_STYLE} />
241
+ {children}
242
+ </div>
243
+ </div>
244
+ </div>
245
+ );
246
+ }
247
+
248
+ interface DefaultErrorScreenProps {
249
+ digest: string;
250
+ message: string;
251
+ reset: () => void;
252
+ }
253
+
254
+ export function DefaultErrorScreen({ message, digest, reset }: DefaultErrorScreenProps) {
255
+ return (
256
+ <ScreenFrame badge={<div style={BADGE_STYLE}>500 — ERROR</div>}>
257
+ <h1 style={HEADING_STYLE}>Something went wrong</h1>
258
+ <div style={CODE_BOX_STYLE}>
259
+ <span style={CODE_LABEL_STYLE}>CODE:</span>
260
+ <span>{digest}</span>
261
+ </div>
262
+ <p style={DESCRIPTION_WRAPPER_STYLE}>
263
+ {message
264
+ ? message
265
+ : "We encountered an unexpected error. Please try again or return to the home page."}
266
+ </p>
267
+ <div style={ACTIONS_STYLE}>
268
+ <Link style={BUTTON_PRIMARY} to="/">
269
+ Go Home
270
+ </Link>
271
+ <button onClick={reset} style={BUTTON_SECONDARY} type="button">
272
+ Try again
273
+ </button>
274
+ </div>
275
+ </ScreenFrame>
276
+ );
277
+ }
278
+
279
+ interface DefaultNotFoundScreenProps {
280
+ message: string | undefined;
281
+ }
282
+
283
+ export function DefaultNotFoundScreen({ message }: DefaultNotFoundScreenProps) {
284
+ return (
285
+ <ScreenFrame badge={<div style={NOT_FOUND_BADGE_STYLE}>404 — NOT FOUND</div>}>
286
+ <h1 style={HEADING_STYLE}>This page does not exist</h1>
287
+ <p style={DESCRIPTION_WRAPPER_STYLE}>
288
+ {message
289
+ ? message
290
+ : "The page you are looking for could not be found. It may have been moved or removed."}
291
+ </p>
292
+ <div style={ACTIONS_STYLE}>
293
+ <Link style={BUTTON_PRIMARY} to="/">
294
+ Go Home
295
+ </Link>
296
+ </div>
297
+ </ScreenFrame>
298
+ );
299
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Computes a deterministic, opaque 10-hex-character digest for an error.
3
+ *
4
+ * Purpose: render this digest in client-facing error UIs (e.g. `Error ID:
5
+ * a3f2b9c1d8`) and log the same digest alongside the full stack on the server,
6
+ * so support can correlate user reports with server logs without leaking stack
7
+ * traces or sensitive message content to the browser.
8
+ *
9
+ * Deterministic: identical error message + stack ⇒ identical digest across
10
+ * restarts, processes, and environments (server + client).
11
+ *
12
+ * Uses a pure-JS 53-bit hash so the function works identically in Bun and in
13
+ * the browser — `computeErrorDigest` is called from `FurinErrorBoundary`, which
14
+ * runs on both sides.
15
+ */
16
+ export function computeErrorDigest(err: unknown): string {
17
+ let message = "";
18
+ let stack = "";
19
+
20
+ if (err instanceof Error) {
21
+ message = err.message;
22
+ stack = err.stack ?? "";
23
+ } else if (typeof err === "string") {
24
+ message = err;
25
+ } else {
26
+ // Non-Error, non-string throws (e.g. `throw { code: 401 }`, `throw 42`,
27
+ // `throw null`). Without this branch every such value would collapse to
28
+ // the same empty `message`/`stack` and therefore the same digest, defeating
29
+ // the whole point of correlating distinct failures with distinct IDs.
30
+ // Prefer JSON.stringify for stable shape-aware hashing of plain objects;
31
+ // fall back to String(err) when the value isn't JSON-serialisable
32
+ // (circular refs, BigInt, symbols, …).
33
+ try {
34
+ message = JSON.stringify(err) ?? String(err);
35
+ } catch {
36
+ message = String(err);
37
+ }
38
+ }
39
+
40
+ const input = `${message}\n${stack}`;
41
+ const hash = cyrb53(input);
42
+ const hex = hash.toString(16).padStart(14, "0");
43
+ return hex.slice(0, 10);
44
+ }
45
+
46
+ /**
47
+ * cyrb53 (c) 2018 bryc (github.com/bryc)
48
+ * A fast, deterministic 53-bit string hash that works in any JS environment.
49
+ * Produces a Number safe for JS integer arithmetic (max 2^53 - 1).
50
+ * Licensed under Public Domain.
51
+ */
52
+ function cyrb53(input: string): number {
53
+ let h1 = 0xde_ad_be_ef;
54
+ let h2 = 0x41_c6_ce_57;
55
+
56
+ for (let i = 0; i < input.length; i++) {
57
+ const ch = input.charCodeAt(i);
58
+ // biome-ignore lint/suspicious/noBitwiseOperators: cyrb53 hash requires XOR
59
+ h1 = Math.imul(h1 ^ ch, 2_654_435_761);
60
+ // biome-ignore lint/suspicious/noBitwiseOperators: cyrb53 hash requires XOR
61
+ h2 = Math.imul(h2 ^ ch, 1_597_334_677);
62
+ }
63
+
64
+ // biome-ignore lint/suspicious/noBitwiseOperators: cyrb53 finalization requires XOR and unsigned shift
65
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2_246_822_507) ^ Math.imul(h2 ^ (h2 >>> 13), 3_266_489_909);
66
+ // biome-ignore lint/suspicious/noBitwiseOperators: cyrb53 finalization requires XOR and unsigned shift
67
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2_246_822_507) ^ Math.imul(h1 ^ (h1 >>> 13), 3_266_489_909);
68
+
69
+ // biome-ignore lint/suspicious/noBitwiseOperators: cyrb53 combines 32-bit halves with bitwise AND
70
+ return 4_294_967_296 * (2_097_151 & h2) + (4_294_967_295 & h1);
71
+ }
@@ -0,0 +1,119 @@
1
+ import type { ReactNode } from "react";
2
+ import type { RuntimeRoute } from "../client";
3
+ import type { ErrorComponent } from "../error";
4
+ import type { FurinNotFoundError, NotFoundComponent } from "../not-found";
5
+ import type { ResolvedRoute, SegmentBoundary } from "../router";
6
+ import { FurinErrorBoundary, FurinNotFoundBoundary } from "./boundaries.tsx";
7
+ import { DefaultErrorScreen, DefaultNotFoundScreen } from "./default-screens.tsx";
8
+
9
+ /**
10
+ * Wraps `inner` with the boundary components declared at a single segment
11
+ * depth, if any. The ordering is deliberate:
12
+ *
13
+ * <FurinErrorBoundary>
14
+ * <FurinNotFoundBoundary>{inner}</FurinNotFoundBoundary>
15
+ * </FurinErrorBoundary>
16
+ *
17
+ * FurinErrorBoundary must be OUTSIDE FurinNotFoundBoundary at the same depth:
18
+ * the error boundary RE-THROWS FurinNotFoundError from render so an ancestor
19
+ * not-found boundary can catch it. Placing the not-found boundary inside
20
+ * would mean the same-depth error boundary catches a notFound() throw first
21
+ * (it still latches onto the error in state), and while it re-throws in
22
+ * render, the re-throw would not find a NotFoundBoundary deeper than itself
23
+ * — it needs one higher up the tree.
24
+ */
25
+ function wrapInBoundaries(inner: ReactNode, segment: SegmentBoundary | undefined): ReactNode {
26
+ if (!segment) {
27
+ return inner;
28
+ }
29
+ let wrapped: ReactNode = inner;
30
+ if (segment.notFound) {
31
+ wrapped = <FurinNotFoundBoundary fallback={segment.notFound}>{wrapped}</FurinNotFoundBoundary>;
32
+ }
33
+ if (segment.error) {
34
+ wrapped = <FurinErrorBoundary fallback={segment.error}>{wrapped}</FurinErrorBoundary>;
35
+ }
36
+ return wrapped;
37
+ }
38
+
39
+ export function buildElement(
40
+ route: ResolvedRoute,
41
+ data: Record<string, unknown>,
42
+ rootLayout: RuntimeRoute
43
+ ): ReactNode {
44
+ const Component = route.page.component;
45
+ let element: ReactNode = <Component {...data} />;
46
+
47
+ // Index segmentBoundaries by depth for O(1) lookup during the wrap loop.
48
+ // Directory depth `d` maps 1:1 to routeChain[d] in Furin's model (routeChain
49
+ // is ordered shallow→deep, with index 0 being the root).
50
+ const byDepth = new Map<number, SegmentBoundary>();
51
+ // Defensive fallback: some legacy callers / tests construct a ResolvedRoute
52
+ // without the segmentBoundaries field.
53
+ for (const segment of route.segmentBoundaries ?? []) {
54
+ byDepth.set(segment.depth, segment);
55
+ }
56
+
57
+ // Build inside-out. At each level we first wrap the accumulated subtree
58
+ // with the boundary declared at this depth (so the boundary sits INSIDE
59
+ // the layout at the same depth), THEN wrap with the layout itself.
60
+ for (let i = route.routeChain.length - 1; i >= 1; i--) {
61
+ element = wrapInBoundaries(element, byDepth.get(i));
62
+ const routeEntry = route.routeChain[i];
63
+ if (routeEntry?.layout) {
64
+ const Layout = routeEntry.layout;
65
+ element = <Layout {...data}>{element}</Layout>;
66
+ }
67
+ }
68
+
69
+ // Depth 0 = pagesDir itself = the root layout directory. Boundary wraps
70
+ // everything below the root layout; root layout wraps the boundary.
71
+ element = wrapInBoundaries(element, byDepth.get(0));
72
+
73
+ if (rootLayout.layout) {
74
+ const RootLayoutComponent = rootLayout.layout;
75
+ element = <RootLayoutComponent {...data}>{element}</RootLayoutComponent>;
76
+ }
77
+
78
+ return element;
79
+ }
80
+
81
+ const DefaultNotFoundComponent: NotFoundComponent = ({ error }) => (
82
+ <DefaultNotFoundScreen message={error.message} />
83
+ );
84
+
85
+ export function buildNotFoundElement(
86
+ component: NotFoundComponent | undefined,
87
+ error: FurinNotFoundError
88
+ ): ReactNode {
89
+ const NotFound = component ?? DefaultNotFoundComponent;
90
+ return <NotFound error={{ message: error.message, data: error.data }} />;
91
+ }
92
+
93
+ const DefaultErrorComponent: ErrorComponent = ({ error, reset }) => (
94
+ <DefaultErrorScreen digest={error.digest} message={error.message} reset={reset} />
95
+ );
96
+
97
+ function errorMessageOf(err: unknown): string {
98
+ if (err instanceof Error) {
99
+ return err.message;
100
+ }
101
+ if (typeof err === "string") {
102
+ return err;
103
+ }
104
+ return "";
105
+ }
106
+
107
+ const SERVER_RESET_NOOP = () => {
108
+ /* reset is a client-only action; the response is already committed here */
109
+ };
110
+
111
+ export function buildErrorElement(
112
+ component: ErrorComponent | undefined,
113
+ error: unknown,
114
+ digest: string
115
+ ): ReactNode {
116
+ const ErrorView = component ?? DefaultErrorComponent;
117
+ const message = component ? errorMessageOf(error) : "An unexpected error occurred.";
118
+ return <ErrorView error={{ message, digest }} reset={SERVER_RESET_NOOP} />;
119
+ }