@rshono/core 1.0.0-rc.2 → 1.0.0-rc.21
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 +348 -158
- package/bin/rshono.mjs +3 -4
- package/dist/builder/env-shadow-loader.cjs +123 -8
- package/dist/builder/page-entry-loader.cjs +28 -1
- package/dist/builder/page-files.d.ts +0 -1
- package/dist/builder/page-files.js +7 -3
- package/dist/builder/page-files.js.map +1 -1
- package/dist/builder/public-env.d.ts +7 -1
- package/dist/builder/public-env.js +7 -0
- package/dist/builder/public-env.js.map +1 -1
- package/dist/builder/react-versions.d.ts +12 -0
- package/dist/builder/react-versions.js +74 -0
- package/dist/builder/react-versions.js.map +1 -0
- package/dist/builder/rspack-config.d.ts +13 -4
- package/dist/builder/rspack-config.js +136 -53
- package/dist/builder/rspack-config.js.map +1 -1
- package/dist/builder/server-only-imports.d.ts +32 -0
- package/dist/builder/server-only-imports.js +51 -0
- package/dist/builder/server-only-imports.js.map +1 -0
- package/dist/cli/build.d.ts +2 -3
- package/dist/cli/build.js +51 -13
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/dev.d.ts +2 -3
- package/dist/cli/dev.js +149 -45
- package/dist/cli/dev.js.map +1 -1
- package/dist/cli/exit.d.ts +12 -0
- package/dist/cli/exit.js +16 -0
- package/dist/cli/exit.js.map +1 -0
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +91 -30
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/start.d.ts +0 -1
- package/dist/cli/start.js +15 -18
- package/dist/cli/start.js.map +1 -1
- package/dist/config.d.ts +72 -78
- package/dist/config.js +17 -1
- package/dist/config.js.map +1 -1
- package/dist/deploy/aws-lambda/runtime.d.ts +4 -7
- package/dist/deploy/aws-lambda/runtime.js +5 -8
- package/dist/deploy/aws-lambda/runtime.js.map +1 -1
- package/dist/deploy/build-marker.d.ts +9 -6
- package/dist/deploy/build-marker.js +8 -4
- package/dist/deploy/build-marker.js.map +1 -1
- package/dist/deploy/cloudflare/build.d.ts +0 -1
- package/dist/deploy/cloudflare/build.js +17 -13
- package/dist/deploy/cloudflare/build.js.map +1 -1
- package/dist/deploy/cloudflare/runtime.d.ts +2 -6
- package/dist/deploy/cloudflare/runtime.js +73 -68
- package/dist/deploy/cloudflare/runtime.js.map +1 -1
- package/dist/deploy/contract.d.ts +57 -41
- package/dist/deploy/contract.js.map +1 -1
- package/dist/deploy/filesystem.d.ts +3 -6
- package/dist/deploy/filesystem.js +23 -20
- package/dist/deploy/filesystem.js.map +1 -1
- package/dist/deploy/node/runtime.d.ts +5 -3
- package/dist/deploy/node/runtime.js +23 -9
- package/dist/deploy/node/runtime.js.map +1 -1
- package/dist/deploy/presets.d.ts +34 -30
- package/dist/deploy/presets.js +56 -44
- package/dist/deploy/presets.js.map +1 -1
- package/dist/deploy/public-paths.d.ts +42 -0
- package/dist/deploy/public-paths.js +66 -0
- package/dist/deploy/public-paths.js.map +1 -0
- package/dist/deploy/vercel/build.d.ts +0 -1
- package/dist/deploy/vercel/build.js +25 -16
- package/dist/deploy/vercel/build.js.map +1 -1
- package/dist/deploy/vercel/runtime.d.ts +10 -7
- package/dist/deploy/vercel/runtime.js +48 -11
- package/dist/deploy/vercel/runtime.js.map +1 -1
- package/dist/index.d.ts +19 -17
- package/dist/index.js +20 -10
- package/dist/index.js.map +1 -1
- package/dist/router.d.ts +212 -120
- package/dist/router.js +3 -8
- package/dist/router.js.map +1 -1
- package/dist/runtime/boundaries.d.ts +62 -48
- package/dist/runtime/boundaries.js +32 -34
- package/dist/runtime/boundaries.js.map +1 -1
- package/dist/runtime/client.d.ts +20 -11
- package/dist/runtime/client.js +20 -10
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/context.d.ts +304 -123
- package/dist/runtime/context.js +377 -149
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/control.d.ts +15 -1
- package/dist/runtime/control.js +24 -0
- package/dist/runtime/control.js.map +1 -1
- package/dist/runtime/dev-protocol.d.ts +4 -9
- package/dist/runtime/dev-protocol.js.map +1 -1
- package/dist/runtime/empty-server-app.d.ts +0 -1
- package/dist/runtime/entry.client.d.ts +4 -1
- package/dist/runtime/entry.client.js +455 -313
- package/dist/runtime/entry.client.js.map +1 -1
- package/dist/runtime/entry.rsc.d.ts +15 -7
- package/dist/runtime/entry.rsc.js +811 -252
- package/dist/runtime/entry.rsc.js.map +1 -1
- package/dist/runtime/entry.ssr.d.ts +27 -10
- package/dist/runtime/entry.ssr.js +30 -48
- package/dist/runtime/entry.ssr.js.map +1 -1
- package/dist/runtime/failure-document.d.ts +11 -0
- package/dist/runtime/failure-document.js +35 -0
- package/dist/runtime/failure-document.js.map +1 -0
- package/dist/runtime/flight-inject.d.ts +23 -0
- package/dist/runtime/flight-inject.js +403 -0
- package/dist/runtime/flight-inject.js.map +1 -0
- package/dist/runtime/hot-update.d.ts +44 -0
- package/dist/runtime/hot-update.js +44 -0
- package/dist/runtime/hot-update.js.map +1 -0
- package/dist/runtime/navigation.d.ts +46 -54
- package/dist/runtime/navigation.js +22 -63
- package/dist/runtime/navigation.js.map +1 -1
- package/dist/runtime/request.d.ts +42 -8
- package/dist/runtime/request.js +84 -7
- package/dist/runtime/request.js.map +1 -1
- package/dist/runtime/server.d.ts +20 -18
- package/dist/runtime/server.js +22 -17
- package/dist/runtime/server.js.map +1 -1
- package/dist/runtime/validate-entries.d.ts +77 -0
- package/dist/runtime/validate-entries.js +405 -0
- package/dist/runtime/validate-entries.js.map +1 -0
- package/dist/server/headers.d.ts +41 -15
- package/dist/server/headers.js +53 -24
- package/dist/server/headers.js.map +1 -1
- package/dist/server/load-config.d.ts +4 -5
- package/dist/server/load-config.js +22 -14
- package/dist/server/load-config.js.map +1 -1
- package/dist/server/load-env.d.ts +0 -1
- package/dist/server/prerendered.d.ts +88 -34
- package/dist/server/prerendered.js +184 -24
- package/dist/server/prerendered.js.map +1 -1
- package/dist/server/server-config.d.ts +35 -50
- package/dist/server/server-config.js +27 -74
- package/dist/server/server-config.js.map +1 -1
- package/dist/server/shutdown.d.ts +5 -4
- package/dist/server/shutdown.js +5 -3
- package/dist/server/shutdown.js.map +1 -1
- package/dist/server/ssg.d.ts +9 -7
- package/dist/server/ssg.js +209 -65
- package/dist/server/ssg.js.map +1 -1
- package/dist/server/static.d.ts +0 -1
- package/dist/server/static.js +7 -1
- package/dist/server/static.js.map +1 -1
- package/package.json +21 -23
- package/dist/builder/page-files.d.ts.map +0 -1
- package/dist/builder/public-env.d.ts.map +0 -1
- package/dist/builder/rspack-config.d.ts.map +0 -1
- package/dist/cli/build.d.ts.map +0 -1
- package/dist/cli/dev.d.ts.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/start.d.ts.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/deploy/aws-lambda/runtime.d.ts.map +0 -1
- package/dist/deploy/build-marker.d.ts.map +0 -1
- package/dist/deploy/bun/runtime.d.ts +0 -11
- package/dist/deploy/bun/runtime.d.ts.map +0 -1
- package/dist/deploy/bun/runtime.js +0 -22
- package/dist/deploy/bun/runtime.js.map +0 -1
- package/dist/deploy/cloudflare/build.d.ts.map +0 -1
- package/dist/deploy/cloudflare/runtime.d.ts.map +0 -1
- package/dist/deploy/contract.d.ts.map +0 -1
- package/dist/deploy/deno/runtime.d.ts +0 -11
- package/dist/deploy/deno/runtime.d.ts.map +0 -1
- package/dist/deploy/deno/runtime.js +0 -16
- package/dist/deploy/deno/runtime.js.map +0 -1
- package/dist/deploy/filesystem.d.ts.map +0 -1
- package/dist/deploy/listen.d.ts +0 -20
- package/dist/deploy/listen.d.ts.map +0 -1
- package/dist/deploy/listen.js +0 -24
- package/dist/deploy/listen.js.map +0 -1
- package/dist/deploy/netlify/build.d.ts +0 -8
- package/dist/deploy/netlify/build.d.ts.map +0 -1
- package/dist/deploy/netlify/build.js +0 -52
- package/dist/deploy/netlify/build.js.map +0 -1
- package/dist/deploy/netlify/runtime.d.ts +0 -13
- package/dist/deploy/netlify/runtime.d.ts.map +0 -1
- package/dist/deploy/netlify/runtime.js +0 -24
- package/dist/deploy/netlify/runtime.js.map +0 -1
- package/dist/deploy/node/runtime.d.ts.map +0 -1
- package/dist/deploy/presets.d.ts.map +0 -1
- package/dist/deploy/vercel/build.d.ts.map +0 -1
- package/dist/deploy/vercel/runtime.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/router.d.ts.map +0 -1
- package/dist/runtime/boundaries.d.ts.map +0 -1
- package/dist/runtime/client.d.ts.map +0 -1
- package/dist/runtime/context.d.ts.map +0 -1
- package/dist/runtime/control.d.ts.map +0 -1
- package/dist/runtime/dev-protocol.d.ts.map +0 -1
- package/dist/runtime/empty-server-app.d.ts.map +0 -1
- package/dist/runtime/entry.client.d.ts.map +0 -1
- package/dist/runtime/entry.rsc.d.ts.map +0 -1
- package/dist/runtime/entry.ssr.d.ts.map +0 -1
- package/dist/runtime/navigation.d.ts.map +0 -1
- package/dist/runtime/request.d.ts.map +0 -1
- package/dist/runtime/server.d.ts.map +0 -1
- package/dist/server/compress.d.ts +0 -15
- package/dist/server/compress.d.ts.map +0 -1
- package/dist/server/compress.js +0 -76
- package/dist/server/compress.js.map +0 -1
- package/dist/server/headers.d.ts.map +0 -1
- package/dist/server/load-config.d.ts.map +0 -1
- package/dist/server/load-env.d.ts.map +0 -1
- package/dist/server/prerendered.d.ts.map +0 -1
- package/dist/server/server-config.d.ts.map +0 -1
- package/dist/server/shutdown.d.ts.map +0 -1
- package/dist/server/ssg.d.ts.map +0 -1
- package/dist/server/static.d.ts.map +0 -1
|
@@ -1,102 +1,116 @@
|
|
|
1
1
|
import { Component, type ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
* What
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* What a {@link CatchBoundary} / {@link AsyncBoundary} renders once a child throws: either a static
|
|
4
|
+
* node, or a render function given the error and a `reset` callback that clears it and re-renders the
|
|
5
|
+
* children (a "Try again" button, say).
|
|
6
6
|
*
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
9
|
-
* server component, pass a `ReactNode`.
|
|
7
|
+
* The function form only works from a `'use client'` component — functions can't cross the
|
|
8
|
+
* server→client boundary. From a server component, pass a `ReactNode`.
|
|
10
9
|
*/
|
|
11
10
|
export type ErrorFallback = ReactNode | ((error: Error, reset: () => void) => ReactNode);
|
|
12
|
-
|
|
11
|
+
/** Props for {@link CatchBoundary}. */
|
|
12
|
+
export interface CatchBoundaryProps {
|
|
13
13
|
/**
|
|
14
|
-
* Rendered in place of the children after one of them throws. Omit it to
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* Rendered in place of the children after one of them throws. Omit it to report the error via
|
|
15
|
+
* `onError` and re-throw to the next boundary out — or the app's `error` page — instead of handling it
|
|
16
|
+
* here.
|
|
17
17
|
*/
|
|
18
18
|
fallback?: ErrorFallback;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Called with the caught error, for logging or reporting.
|
|
21
|
+
*
|
|
22
|
+
* A function prop, so — like {@link ErrorFallback}'s function form — it can only be passed from a
|
|
23
|
+
* `'use client'` component. React refuses one from a server component by name: "Event handlers cannot be
|
|
24
|
+
* passed to Client Component props".
|
|
25
|
+
*/
|
|
20
26
|
onError?: (error: Error) => void;
|
|
21
27
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
28
|
+
* Clears the error automatically when any value in this array changes while the fallback is showing.
|
|
29
|
+
* Pass the current pathname to recover when the user navigates away — `resetKeys={[url.pathname]}` from a
|
|
30
|
+
* page's `url` prop, which is the form that works from the server component rendering this boundary, or
|
|
31
|
+
* `resetKeys={[useNavigation().url.pathname]}` inside a `'use client'` component.
|
|
25
32
|
*/
|
|
26
33
|
resetKeys?: readonly unknown[];
|
|
34
|
+
/** The subtree this boundary protects. */
|
|
27
35
|
children: ReactNode;
|
|
28
36
|
}
|
|
29
|
-
interface
|
|
37
|
+
interface CatchBoundaryState {
|
|
30
38
|
error: Error | null;
|
|
31
39
|
}
|
|
32
40
|
/**
|
|
33
|
-
* A general-purpose error boundary
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* tearing down the whole page.
|
|
41
|
+
* A general-purpose error boundary: catches what its children throw — a client island that blew up, a
|
|
42
|
+
* server component that rejected on a soft navigation — and renders `fallback` in their place rather
|
|
43
|
+
* than tearing down the page.
|
|
37
44
|
*
|
|
38
|
-
* It
|
|
39
|
-
*
|
|
40
|
-
* when you also want a Suspense loading fallback in the same wrapper.
|
|
45
|
+
* It is a `'use client'` component (React error boundaries must be), so a server component can render
|
|
46
|
+
* it too. Reach for {@link AsyncBoundary} when you also want a Suspense loading fallback.
|
|
41
47
|
*
|
|
42
48
|
* @example
|
|
43
49
|
* ```tsx
|
|
44
|
-
* import {
|
|
50
|
+
* import { CatchBoundary } from '@rshono/core/client';
|
|
45
51
|
*
|
|
46
|
-
* <
|
|
52
|
+
* <CatchBoundary fallback={(error, reset) => (
|
|
47
53
|
* <div role="alert">
|
|
48
54
|
* <p>{error.message}</p>
|
|
49
55
|
* <button onClick={reset}>Try again</button>
|
|
50
56
|
* </div>
|
|
51
57
|
* )}>
|
|
52
58
|
* <RiskyWidget />
|
|
53
|
-
* </
|
|
59
|
+
* </CatchBoundary>
|
|
54
60
|
* ```
|
|
61
|
+
*
|
|
62
|
+
* @see {@link https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary | React — error boundaries}
|
|
63
|
+
* @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
|
|
55
64
|
*/
|
|
56
|
-
export declare class
|
|
57
|
-
state:
|
|
58
|
-
static getDerivedStateFromError(error: Error):
|
|
65
|
+
export declare class CatchBoundary extends Component<CatchBoundaryProps, CatchBoundaryState> {
|
|
66
|
+
state: CatchBoundaryState;
|
|
67
|
+
static getDerivedStateFromError(error: Error): CatchBoundaryState;
|
|
59
68
|
componentDidCatch(error: Error): void;
|
|
60
|
-
componentDidUpdate(prev:
|
|
69
|
+
componentDidUpdate(prev: CatchBoundaryProps): void;
|
|
61
70
|
reset: () => void;
|
|
62
71
|
render(): ReactNode;
|
|
63
72
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
/** Props for {@link AsyncBoundary}. */
|
|
74
|
+
export interface AsyncBoundaryProps {
|
|
75
|
+
/**
|
|
76
|
+
* Suspense fallback, shown while the children or their data are still loading. Required — a loading
|
|
77
|
+
* state is the reason to reach for this over {@link CatchBoundary}, so showing nothing is an explicit
|
|
78
|
+
* `loading={null}`.
|
|
79
|
+
*/
|
|
80
|
+
loading: ReactNode;
|
|
67
81
|
/** Error fallback, shown if a child throws. See {@link ErrorFallback}. */
|
|
68
82
|
error?: ErrorFallback;
|
|
69
|
-
/** Called with the caught error. */
|
|
83
|
+
/** Called with the caught error. From a `'use client'` component only — see {@link CatchBoundaryProps.onError}. */
|
|
70
84
|
onError?: (error: Error) => void;
|
|
71
|
-
/** Clears the error fallback when any value changes — see {@link
|
|
85
|
+
/** Clears the error fallback when any value changes — see {@link CatchBoundaryProps.resetKeys}. */
|
|
72
86
|
resetKeys?: readonly unknown[];
|
|
87
|
+
/** The subtree this boundary suspends on and protects. */
|
|
73
88
|
children: ReactNode;
|
|
74
89
|
}
|
|
75
90
|
/**
|
|
76
|
-
* A loading
|
|
77
|
-
*
|
|
91
|
+
* A loading and error boundary in one wrapper — the common case for an async section of a page. It
|
|
92
|
+
* always renders the same shape:
|
|
78
93
|
*
|
|
79
94
|
* ```tsx
|
|
80
|
-
* <
|
|
95
|
+
* <CatchBoundary fallback={error}>
|
|
81
96
|
* <Suspense fallback={loading}>{children}</Suspense>
|
|
82
|
-
* </
|
|
97
|
+
* </CatchBoundary>
|
|
83
98
|
* ```
|
|
84
99
|
*
|
|
85
|
-
* so `
|
|
86
|
-
* `
|
|
87
|
-
* `loading` and nothing shows while loading; omit `error` and thrown errors
|
|
88
|
-
* propagate to the next boundary out (or the global error page) rather than
|
|
89
|
-
* being caught here.
|
|
100
|
+
* so `loading` shows until the children resolve and `error` catches whatever they throw, suspended or
|
|
101
|
+
* not. `error` is optional: omit it and errors propagate to the next boundary out.
|
|
90
102
|
*
|
|
91
103
|
* @example
|
|
92
104
|
* ```tsx
|
|
93
|
-
* import {
|
|
105
|
+
* import { AsyncBoundary } from '@rshono/core/client';
|
|
94
106
|
*
|
|
95
|
-
* <
|
|
107
|
+
* <AsyncBoundary loading={<Spinner />} error={(e, reset) => <Retry onClick={reset} />}>
|
|
96
108
|
* <SlowServerComponent />
|
|
97
|
-
* </
|
|
109
|
+
* </AsyncBoundary>
|
|
98
110
|
* ```
|
|
111
|
+
*
|
|
112
|
+
* @see {@link https://react.dev/reference/react/Suspense | React — `<Suspense>`}
|
|
113
|
+
* @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
|
|
99
114
|
*/
|
|
100
|
-
export declare function
|
|
115
|
+
export declare function AsyncBoundary({ loading, error, onError, resetKeys, children }: AsyncBoundaryProps): ReactNode;
|
|
101
116
|
export {};
|
|
102
|
-
//# sourceMappingURL=boundaries.d.ts.map
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Component, Suspense } from 'react';
|
|
4
4
|
import { isControlDigest } from './control.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* a component inside a `<Boundary>` would render "something went wrong" instead of navigating.
|
|
9
|
-
* They're re-thrown to the root, where the runtime turns the digest into a real navigation.
|
|
10
|
-
*/
|
|
5
|
+
// `redirect()` and `notFound()` reach the browser as a thrown error carrying a control digest. They are
|
|
6
|
+
// navigation, not failure, so no boundary absorbs one — they are re-thrown to the root, where the
|
|
7
|
+
// runtime turns the digest into a real navigation.
|
|
11
8
|
function isControlError(error) {
|
|
12
9
|
return isControlDigest(error?.digest);
|
|
13
10
|
}
|
|
@@ -15,37 +12,38 @@ function keysChanged(a, b) {
|
|
|
15
12
|
return a.length !== b.length || a.some((value, i) => !Object.is(value, b[i]));
|
|
16
13
|
}
|
|
17
14
|
/**
|
|
18
|
-
* A general-purpose error boundary
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* tearing down the whole page.
|
|
15
|
+
* A general-purpose error boundary: catches what its children throw — a client island that blew up, a
|
|
16
|
+
* server component that rejected on a soft navigation — and renders `fallback` in their place rather
|
|
17
|
+
* than tearing down the page.
|
|
22
18
|
*
|
|
23
|
-
* It
|
|
24
|
-
*
|
|
25
|
-
* when you also want a Suspense loading fallback in the same wrapper.
|
|
19
|
+
* It is a `'use client'` component (React error boundaries must be), so a server component can render
|
|
20
|
+
* it too. Reach for {@link AsyncBoundary} when you also want a Suspense loading fallback.
|
|
26
21
|
*
|
|
27
22
|
* @example
|
|
28
23
|
* ```tsx
|
|
29
|
-
* import {
|
|
24
|
+
* import { CatchBoundary } from '@rshono/core/client';
|
|
30
25
|
*
|
|
31
|
-
* <
|
|
26
|
+
* <CatchBoundary fallback={(error, reset) => (
|
|
32
27
|
* <div role="alert">
|
|
33
28
|
* <p>{error.message}</p>
|
|
34
29
|
* <button onClick={reset}>Try again</button>
|
|
35
30
|
* </div>
|
|
36
31
|
* )}>
|
|
37
32
|
* <RiskyWidget />
|
|
38
|
-
* </
|
|
33
|
+
* </CatchBoundary>
|
|
39
34
|
* ```
|
|
35
|
+
*
|
|
36
|
+
* @see {@link https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary | React — error boundaries}
|
|
37
|
+
* @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
|
|
40
38
|
*/
|
|
41
|
-
export class
|
|
39
|
+
export class CatchBoundary extends Component {
|
|
42
40
|
state = { error: null };
|
|
43
41
|
static getDerivedStateFromError(error) {
|
|
44
42
|
return { error };
|
|
45
43
|
}
|
|
46
44
|
componentDidCatch(error) {
|
|
47
45
|
if (isControlError(error))
|
|
48
|
-
return;
|
|
46
|
+
return;
|
|
49
47
|
this.props.onError?.(error);
|
|
50
48
|
}
|
|
51
49
|
componentDidUpdate(prev) {
|
|
@@ -61,41 +59,41 @@ export class ErrorBoundary extends Component {
|
|
|
61
59
|
const { error } = this.state;
|
|
62
60
|
if (error !== null) {
|
|
63
61
|
if (isControlError(error))
|
|
64
|
-
throw error;
|
|
62
|
+
throw error;
|
|
65
63
|
const { fallback } = this.props;
|
|
66
64
|
if (fallback === undefined)
|
|
67
|
-
throw error; //
|
|
65
|
+
throw error; // propagate to an outer boundary
|
|
68
66
|
return typeof fallback === 'function' ? fallback(error, this.reset) : fallback;
|
|
69
67
|
}
|
|
70
68
|
return this.props.children;
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
|
-
* A loading
|
|
75
|
-
*
|
|
72
|
+
* A loading and error boundary in one wrapper — the common case for an async section of a page. It
|
|
73
|
+
* always renders the same shape:
|
|
76
74
|
*
|
|
77
75
|
* ```tsx
|
|
78
|
-
* <
|
|
76
|
+
* <CatchBoundary fallback={error}>
|
|
79
77
|
* <Suspense fallback={loading}>{children}</Suspense>
|
|
80
|
-
* </
|
|
78
|
+
* </CatchBoundary>
|
|
81
79
|
* ```
|
|
82
80
|
*
|
|
83
|
-
* so `
|
|
84
|
-
* `
|
|
85
|
-
* `loading` and nothing shows while loading; omit `error` and thrown errors
|
|
86
|
-
* propagate to the next boundary out (or the global error page) rather than
|
|
87
|
-
* being caught here.
|
|
81
|
+
* so `loading` shows until the children resolve and `error` catches whatever they throw, suspended or
|
|
82
|
+
* not. `error` is optional: omit it and errors propagate to the next boundary out.
|
|
88
83
|
*
|
|
89
84
|
* @example
|
|
90
85
|
* ```tsx
|
|
91
|
-
* import {
|
|
86
|
+
* import { AsyncBoundary } from '@rshono/core/client';
|
|
92
87
|
*
|
|
93
|
-
* <
|
|
88
|
+
* <AsyncBoundary loading={<Spinner />} error={(e, reset) => <Retry onClick={reset} />}>
|
|
94
89
|
* <SlowServerComponent />
|
|
95
|
-
* </
|
|
90
|
+
* </AsyncBoundary>
|
|
96
91
|
* ```
|
|
92
|
+
*
|
|
93
|
+
* @see {@link https://react.dev/reference/react/Suspense | React — `<Suspense>`}
|
|
94
|
+
* @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
|
|
97
95
|
*/
|
|
98
|
-
export function
|
|
99
|
-
return (_jsx(
|
|
96
|
+
export function AsyncBoundary({ loading, error, onError, resetKeys, children }) {
|
|
97
|
+
return (_jsx(CatchBoundary, { fallback: error, onError: onError, resetKeys: resetKeys, children: _jsx(Suspense, { fallback: loading, children: children }) }));
|
|
100
98
|
}
|
|
101
99
|
//# sourceMappingURL=boundaries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundaries.js","sourceRoot":"","sources":["../../src/runtime/boundaries.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"boundaries.js","sourceRoot":"","sources":["../../src/runtime/boundaries.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,wGAAwG;AACxG,kGAAkG;AAClG,mDAAmD;AACnD,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,eAAe,CAAE,KAAqC,EAAE,MAAM,CAAC,CAAC;AACzE,CAAC;AA2CD,SAAS,WAAW,CAAC,CAAqB,EAAE,CAAqB;IAC/D,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,aAAc,SAAQ,SAAiD;IAClF,KAAK,GAAuB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAE5C,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC1C,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;IAED,iBAAiB,CAAC,KAAY;QAC5B,IAAI,cAAc,CAAC,KAAK,CAAC;YAAE,OAAO;QAClC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,kBAAkB,CAAC,IAAwB;QACzC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACjC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,IAAI,SAAS,IAAI,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;YAC9F,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,GAAG,GAAS,EAAE;QACjB,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,MAAM;QACJ,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC7B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,IAAI,cAAc,CAAC,KAAK,CAAC;gBAAE,MAAM,KAAK,CAAC;YACvC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAChC,IAAI,QAAQ,KAAK,SAAS;gBAAE,MAAM,KAAK,CAAC,CAAC,iCAAiC;YAC1E,OAAO,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACjF,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;CACF;AAoBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,aAAa,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAsB;IAChG,OAAO,CACL,KAAC,aAAa,IAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,YACpE,KAAC,QAAQ,IAAC,QAAQ,EAAE,OAAO,YAAG,QAAQ,GAAY,GACpC,CACjB,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { Component, Suspense, type ReactNode } from 'react';\nimport { isControlDigest } from './control.js';\n\n// `redirect()` and `notFound()` reach the browser as a thrown error carrying a control digest. They are\n// navigation, not failure, so no boundary absorbs one — they are re-thrown to the root, where the\n// runtime turns the digest into a real navigation.\nfunction isControlError(error: unknown): boolean {\n return isControlDigest((error as { digest?: unknown } | null)?.digest);\n}\n\n/**\n * What a {@link CatchBoundary} / {@link AsyncBoundary} renders once a child throws: either a static\n * node, or a render function given the error and a `reset` callback that clears it and re-renders the\n * children (a \"Try again\" button, say).\n *\n * The function form only works from a `'use client'` component — functions can't cross the\n * server→client boundary. From a server component, pass a `ReactNode`.\n */\nexport type ErrorFallback = ReactNode | ((error: Error, reset: () => void) => ReactNode);\n\n/** Props for {@link CatchBoundary}. */\nexport interface CatchBoundaryProps {\n /**\n * Rendered in place of the children after one of them throws. Omit it to report the error via\n * `onError` and re-throw to the next boundary out — or the app's `error` page — instead of handling it\n * here.\n */\n fallback?: ErrorFallback;\n /**\n * Called with the caught error, for logging or reporting.\n *\n * A function prop, so — like {@link ErrorFallback}'s function form — it can only be passed from a\n * `'use client'` component. React refuses one from a server component by name: \"Event handlers cannot be\n * passed to Client Component props\".\n */\n onError?: (error: Error) => void;\n /**\n * Clears the error automatically when any value in this array changes while the fallback is showing.\n * Pass the current pathname to recover when the user navigates away — `resetKeys={[url.pathname]}` from a\n * page's `url` prop, which is the form that works from the server component rendering this boundary, or\n * `resetKeys={[useNavigation().url.pathname]}` inside a `'use client'` component.\n */\n resetKeys?: readonly unknown[];\n /** The subtree this boundary protects. */\n children: ReactNode;\n}\n\ninterface CatchBoundaryState {\n error: Error | null;\n}\n\nfunction keysChanged(a: readonly unknown[], b: readonly unknown[]): boolean {\n return a.length !== b.length || a.some((value, i) => !Object.is(value, b[i]));\n}\n\n/**\n * A general-purpose error boundary: catches what its children throw — a client island that blew up, a\n * server component that rejected on a soft navigation — and renders `fallback` in their place rather\n * than tearing down the page.\n *\n * It is a `'use client'` component (React error boundaries must be), so a server component can render\n * it too. Reach for {@link AsyncBoundary} when you also want a Suspense loading fallback.\n *\n * @example\n * ```tsx\n * import { CatchBoundary } from '@rshono/core/client';\n *\n * <CatchBoundary fallback={(error, reset) => (\n * <div role=\"alert\">\n * <p>{error.message}</p>\n * <button onClick={reset}>Try again</button>\n * </div>\n * )}>\n * <RiskyWidget />\n * </CatchBoundary>\n * ```\n *\n * @see {@link https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary | React — error boundaries}\n * @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}\n */\nexport class CatchBoundary extends Component<CatchBoundaryProps, CatchBoundaryState> {\n state: CatchBoundaryState = { error: null };\n\n static getDerivedStateFromError(error: Error): CatchBoundaryState {\n return { error };\n }\n\n componentDidCatch(error: Error): void {\n if (isControlError(error)) return;\n this.props.onError?.(error);\n }\n\n componentDidUpdate(prev: CatchBoundaryProps): void {\n const { resetKeys } = this.props;\n if (this.state.error && prev.resetKeys && resetKeys && keysChanged(prev.resetKeys, resetKeys)) {\n this.reset();\n }\n }\n\n reset = (): void => {\n this.setState({ error: null });\n };\n\n render(): ReactNode {\n const { error } = this.state;\n if (error !== null) {\n if (isControlError(error)) throw error;\n const { fallback } = this.props;\n if (fallback === undefined) throw error; // propagate to an outer boundary\n return typeof fallback === 'function' ? fallback(error, this.reset) : fallback;\n }\n return this.props.children;\n }\n}\n\n/** Props for {@link AsyncBoundary}. */\nexport interface AsyncBoundaryProps {\n /**\n * Suspense fallback, shown while the children or their data are still loading. Required — a loading\n * state is the reason to reach for this over {@link CatchBoundary}, so showing nothing is an explicit\n * `loading={null}`.\n */\n loading: ReactNode;\n /** Error fallback, shown if a child throws. See {@link ErrorFallback}. */\n error?: ErrorFallback;\n /** Called with the caught error. From a `'use client'` component only — see {@link CatchBoundaryProps.onError}. */\n onError?: (error: Error) => void;\n /** Clears the error fallback when any value changes — see {@link CatchBoundaryProps.resetKeys}. */\n resetKeys?: readonly unknown[];\n /** The subtree this boundary suspends on and protects. */\n children: ReactNode;\n}\n\n/**\n * A loading and error boundary in one wrapper — the common case for an async section of a page. It\n * always renders the same shape:\n *\n * ```tsx\n * <CatchBoundary fallback={error}>\n * <Suspense fallback={loading}>{children}</Suspense>\n * </CatchBoundary>\n * ```\n *\n * so `loading` shows until the children resolve and `error` catches whatever they throw, suspended or\n * not. `error` is optional: omit it and errors propagate to the next boundary out.\n *\n * @example\n * ```tsx\n * import { AsyncBoundary } from '@rshono/core/client';\n *\n * <AsyncBoundary loading={<Spinner />} error={(e, reset) => <Retry onClick={reset} />}>\n * <SlowServerComponent />\n * </AsyncBoundary>\n * ```\n *\n * @see {@link https://react.dev/reference/react/Suspense | React — `<Suspense>`}\n * @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}\n */\nexport function AsyncBoundary({ loading, error, onError, resetKeys, children }: AsyncBoundaryProps): ReactNode {\n return (\n <CatchBoundary fallback={error} onError={onError} resetKeys={resetKeys}>\n <Suspense fallback={loading}>{children}</Suspense>\n </CatchBoundary>\n );\n}\n"]}
|
package/dist/runtime/client.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@rshono/core/client` — the browser-side surface
|
|
3
|
-
*
|
|
4
|
-
* {@link Boundary} / {@link ErrorBoundary} / {@link NavigationProgress} as
|
|
5
|
-
* components.
|
|
2
|
+
* `@rshono/core/client` — the browser-side surface: `useNavigation()` for the current URL and soft
|
|
3
|
+
* navigation, plus the `<AsyncBoundary>` and `<CatchBoundary>` components.
|
|
6
4
|
*
|
|
7
|
-
* Every export is itself a `'use client'` module, so a server component can
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Every export is itself a `'use client'` module, so a server component can render `<AsyncBoundary>`
|
|
6
|
+
* directly — but the hook needs a client component. In a server component, read the same request data
|
|
7
|
+
* from `getRequestContext()` in `@rshono/core/server`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* 'use client';
|
|
12
|
+
* import { useNavigation } from '@rshono/core/client';
|
|
13
|
+
*
|
|
14
|
+
* export function Tab() {
|
|
15
|
+
* const { url, router } = useNavigation();
|
|
16
|
+
* return <button onClick={() => router.push(`${url.pathname}?tab=details`)}>Details</button>;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
|
|
11
21
|
*
|
|
12
22
|
* @packageDocumentation
|
|
13
23
|
*/
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
//# sourceMappingURL=client.d.ts.map
|
|
24
|
+
export { useNavigation, type NavigationRouter, type NavigationState } from './navigation.js';
|
|
25
|
+
export { AsyncBoundary, CatchBoundary, type AsyncBoundaryProps, type CatchBoundaryProps, type ErrorFallback } from './boundaries.js';
|
package/dist/runtime/client.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@rshono/core/client` — the browser-side surface
|
|
3
|
-
*
|
|
4
|
-
* {@link Boundary} / {@link ErrorBoundary} / {@link NavigationProgress} as
|
|
5
|
-
* components.
|
|
2
|
+
* `@rshono/core/client` — the browser-side surface: `useNavigation()` for the current URL and soft
|
|
3
|
+
* navigation, plus the `<AsyncBoundary>` and `<CatchBoundary>` components.
|
|
6
4
|
*
|
|
7
|
-
* Every export is itself a `'use client'` module, so a server component can
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Every export is itself a `'use client'` module, so a server component can render `<AsyncBoundary>`
|
|
6
|
+
* directly — but the hook needs a client component. In a server component, read the same request data
|
|
7
|
+
* from `getRequestContext()` in `@rshono/core/server`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* 'use client';
|
|
12
|
+
* import { useNavigation } from '@rshono/core/client';
|
|
13
|
+
*
|
|
14
|
+
* export function Tab() {
|
|
15
|
+
* const { url, router } = useNavigation();
|
|
16
|
+
* return <button onClick={() => router.push(`${url.pathname}?tab=details`)}>Details</button>;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
|
|
11
21
|
*
|
|
12
22
|
* @packageDocumentation
|
|
13
23
|
*/
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
24
|
+
export { useNavigation } from './navigation.js';
|
|
25
|
+
export { AsyncBoundary, CatchBoundary } from './boundaries.js';
|
|
16
26
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/runtime/client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/runtime/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,aAAa,EAA+C,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,aAAa,EAAwE,MAAM,iBAAiB,CAAC","sourcesContent":["/**\n * `@rshono/core/client` — the browser-side surface: `useNavigation()` for the current URL and soft\n * navigation, plus the `<AsyncBoundary>` and `<CatchBoundary>` components.\n *\n * Every export is itself a `'use client'` module, so a server component can render `<AsyncBoundary>`\n * directly — but the hook needs a client component. In a server component, read the same request data\n * from `getRequestContext()` in `@rshono/core/server`.\n *\n * @example\n * ```tsx\n * 'use client';\n * import { useNavigation } from '@rshono/core/client';\n *\n * export function Tab() {\n * const { url, router } = useNavigation();\n * return <button onClick={() => router.push(`${url.pathname}?tab=details`)}>Details</button>;\n * }\n * ```\n *\n * @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}\n *\n * @packageDocumentation\n */\n\nexport { useNavigation, type NavigationRouter, type NavigationState } from './navigation.js';\nexport { AsyncBoundary, CatchBoundary, type AsyncBoundaryProps, type CatchBoundaryProps, type ErrorFallback } from './boundaries.js';\n"]}
|