@rsc-kit/core 0.1.0
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/README.md +95 -0
- package/SECURITY.md +60 -0
- package/dist/action.d.ts +90 -0
- package/dist/action.d.ts.map +1 -0
- package/dist/action.js +137 -0
- package/dist/action.js.map +1 -0
- package/dist/build-rsc-vite.d.ts +39 -0
- package/dist/build-rsc-vite.d.ts.map +1 -0
- package/dist/build-rsc-vite.js +172 -0
- package/dist/build-rsc-vite.js.map +1 -0
- package/dist/cache.d.ts +25 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +108 -0
- package/dist/cache.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +85 -0
- package/dist/cli.js.map +1 -0
- package/dist/compile.d.ts +55 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +141 -0
- package/dist/compile.js.map +1 -0
- package/dist/devServer.d.ts +18 -0
- package/dist/devServer.d.ts.map +1 -0
- package/dist/devServer.js +70 -0
- package/dist/devServer.js.map +1 -0
- package/dist/devUrls.d.ts +11 -0
- package/dist/devUrls.d.ts.map +1 -0
- package/dist/devUrls.js +68 -0
- package/dist/devUrls.js.map +1 -0
- package/dist/embed.d.ts +21 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +119 -0
- package/dist/embed.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +38 -0
- package/dist/errors.js.map +1 -0
- package/dist/export.d.ts +41 -0
- package/dist/export.d.ts.map +1 -0
- package/dist/export.js +100 -0
- package/dist/export.js.map +1 -0
- package/dist/files.d.ts +39 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +146 -0
- package/dist/files.js.map +1 -0
- package/dist/headers.d.ts +81 -0
- package/dist/headers.d.ts.map +1 -0
- package/dist/headers.js +96 -0
- package/dist/headers.js.map +1 -0
- package/dist/host.d.ts +86 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +590 -0
- package/dist/host.js.map +1 -0
- package/dist/js/ActivityRouter.d.ts +47 -0
- package/dist/js/ActivityRouter.d.ts.map +1 -0
- package/dist/js/ActivityRouter.js +87 -0
- package/dist/js/ActivityRouter.js.map +1 -0
- package/dist/js/DocumentTitle.d.ts +22 -0
- package/dist/js/DocumentTitle.d.ts.map +1 -0
- package/dist/js/DocumentTitle.js +28 -0
- package/dist/js/DocumentTitle.js.map +1 -0
- package/dist/js/Form.d.ts +54 -0
- package/dist/js/Form.d.ts.map +1 -0
- package/dist/js/Form.js +225 -0
- package/dist/js/Form.js.map +1 -0
- package/dist/js/Link.d.ts +29 -0
- package/dist/js/Link.d.ts.map +1 -0
- package/dist/js/Link.js +112 -0
- package/dist/js/Link.js.map +1 -0
- package/dist/js/PathnameProvider.d.ts +8 -0
- package/dist/js/PathnameProvider.d.ts.map +1 -0
- package/dist/js/PathnameProvider.js +24 -0
- package/dist/js/PathnameProvider.js.map +1 -0
- package/dist/js/RedirectBoundary.d.ts +18 -0
- package/dist/js/RedirectBoundary.d.ts.map +1 -0
- package/dist/js/RedirectBoundary.js +34 -0
- package/dist/js/RedirectBoundary.js.map +1 -0
- package/dist/js/SegmentBoundary.d.ts +8 -0
- package/dist/js/SegmentBoundary.d.ts.map +1 -0
- package/dist/js/SegmentBoundary.js +38 -0
- package/dist/js/SegmentBoundary.js.map +1 -0
- package/dist/js/SlotBoundary.d.ts +15 -0
- package/dist/js/SlotBoundary.d.ts.map +1 -0
- package/dist/js/SlotBoundary.js +17 -0
- package/dist/js/SlotBoundary.js.map +1 -0
- package/dist/js/createViteRscApp.d.ts +8 -0
- package/dist/js/createViteRscApp.d.ts.map +1 -0
- package/dist/js/createViteRscApp.js +185 -0
- package/dist/js/createViteRscApp.js.map +1 -0
- package/dist/js/errors.d.ts +51 -0
- package/dist/js/errors.d.ts.map +1 -0
- package/dist/js/errors.js +93 -0
- package/dist/js/errors.js.map +1 -0
- package/dist/js/navigate.d.ts +118 -0
- package/dist/js/navigate.d.ts.map +1 -0
- package/dist/js/navigate.js +780 -0
- package/dist/js/navigate.js.map +1 -0
- package/dist/js/onlineStore.d.ts +23 -0
- package/dist/js/onlineStore.d.ts.map +1 -0
- package/dist/js/onlineStore.js +42 -0
- package/dist/js/onlineStore.js.map +1 -0
- package/dist/js/pagePayload.d.ts +15 -0
- package/dist/js/pagePayload.d.ts.map +1 -0
- package/dist/js/pagePayload.js +39 -0
- package/dist/js/pagePayload.js.map +1 -0
- package/dist/js/router.d.ts +29 -0
- package/dist/js/router.d.ts.map +1 -0
- package/dist/js/router.js +40 -0
- package/dist/js/router.js.map +1 -0
- package/dist/js/section.d.ts +16 -0
- package/dist/js/section.d.ts.map +1 -0
- package/dist/js/section.js +55 -0
- package/dist/js/section.js.map +1 -0
- package/dist/js/segmentStore.d.ts +69 -0
- package/dist/js/segmentStore.d.ts.map +1 -0
- package/dist/js/segmentStore.js +127 -0
- package/dist/js/segmentStore.js.map +1 -0
- package/dist/js/slotStore.d.ts +35 -0
- package/dist/js/slotStore.d.ts.map +1 -0
- package/dist/js/slotStore.js +46 -0
- package/dist/js/slotStore.js.map +1 -0
- package/dist/js/standardSchema.d.ts +47 -0
- package/dist/js/standardSchema.d.ts.map +1 -0
- package/dist/js/standardSchema.js +41 -0
- package/dist/js/standardSchema.js.map +1 -0
- package/dist/js/useForm.d.ts +43 -0
- package/dist/js/useForm.d.ts.map +1 -0
- package/dist/js/useForm.js +164 -0
- package/dist/js/useForm.js.map +1 -0
- package/dist/js/useLinkStatus.d.ts +2 -0
- package/dist/js/useLinkStatus.d.ts.map +1 -0
- package/dist/js/useLinkStatus.js +3 -0
- package/dist/js/useLinkStatus.js.map +1 -0
- package/dist/js/useOnline.d.ts +8 -0
- package/dist/js/useOnline.d.ts.map +1 -0
- package/dist/js/useOnline.js +20 -0
- package/dist/js/useOnline.js.map +1 -0
- package/dist/js/usePathname.d.ts +9 -0
- package/dist/js/usePathname.d.ts.map +1 -0
- package/dist/js/usePathname.js +32 -0
- package/dist/js/usePathname.js.map +1 -0
- package/dist/js/useSearchParams.d.ts +2 -0
- package/dist/js/useSearchParams.d.ts.map +1 -0
- package/dist/js/useSearchParams.js +60 -0
- package/dist/js/useSearchParams.js.map +1 -0
- package/dist/manifest.d.ts +66 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +13 -0
- package/dist/manifest.js.map +1 -0
- package/dist/prerender.d.ts +138 -0
- package/dist/prerender.d.ts.map +1 -0
- package/dist/prerender.js +387 -0
- package/dist/prerender.js.map +1 -0
- package/dist/redirect.d.ts +34 -0
- package/dist/redirect.d.ts.map +1 -0
- package/dist/redirect.js +108 -0
- package/dist/redirect.js.map +1 -0
- package/dist/redirectDigest.d.ts +20 -0
- package/dist/redirectDigest.d.ts.map +1 -0
- package/dist/redirectDigest.js +66 -0
- package/dist/redirectDigest.js.map +1 -0
- package/dist/request.d.ts +93 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +308 -0
- package/dist/request.js.map +1 -0
- package/dist/revalidate.d.ts +43 -0
- package/dist/revalidate.d.ts.map +1 -0
- package/dist/revalidate.js +99 -0
- package/dist/revalidate.js.map +1 -0
- package/dist/routes.d.ts +37 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +28 -0
- package/dist/routes.js.map +1 -0
- package/dist/routing.d.ts +52 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +146 -0
- package/dist/routing.js.map +1 -0
- package/dist/runtime.d.ts +36 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +86 -0
- package/dist/runtime.js.map +1 -0
- package/dist/safeUrl.d.ts +10 -0
- package/dist/safeUrl.d.ts.map +1 -0
- package/dist/safeUrl.js +40 -0
- package/dist/safeUrl.js.map +1 -0
- package/dist/streaming.d.ts +62 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +108 -0
- package/dist/streaming.js.map +1 -0
- package/dist/types.d.ts +82 -0
- package/dist/vite.d.ts +109 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +1909 -0
- package/dist/vite.js.map +1 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +863 -0
- package/dist/worker.js.map +1 -0
- package/package.json +223 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/js/Link.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAIL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AAyBf,MAAM,iBAAiB,GAAG,aAAa,CAAuB,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAElF,MAAM,UAAU,aAAa;IAC3B,OAAO,UAAU,CAAC,iBAAiB,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,CAAgC;IAC5D,OAAO,CACL,CAAC,CAAC,CAAC,gBAAgB;QACnB,CAAC,CAAC,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC,OAAO;QACV,CAAC,CAAC,CAAC,OAAO;QACV,CAAC,CAAC,CAAC,QAAQ;QACX,CAAC,CAAC,CAAC,MAAM,CACV,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAC3B,IAAI,EACJ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AChC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACjC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAC5B,CAAC;QAED,yEAAyE;QACzE,wEAAwE;QACxE,IAAI,aAAa,CAAC,IAAI,CAAC;YAAE,OAAO;QAC/B,MAAc,CAAC,qBAAqB,EAAE,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC,EACD,CAAC,IAAI,EAAE,YAAY,CAAC,CACrB,CAAC;IAEF,yEAAyE;IACzE,wEAAwE;IACxE,qEAAqE;IACrE,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE;QACxC,IAAI,gBAAgB,KAAK,OAAO,IAAI,gBAAgB,KAAK,OAAO,EAAE,CAAC;YACjE,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC,EAAE,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAAC;IAEnC,6EAA6E;IAC7E,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE;QACnB,IAAI,UAAU,CAAC,OAAO,KAAK,IAAI;YAAE,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,YAC5C,YACE,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,WAAW,EACpB,YAAY,EAAE,gBAAgB,EAC9B,YAAY,EAAE,gBAAgB,EAC9B,YAAY,EAAE,gBAAgB,kBAChB,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAClC,IAAI,YAEP,QAAQ,GACP,GACuB,CAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export declare function PathnameProvider({ value, children }: {
|
|
3
|
+
value: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
/** What the server rendered. On the client this is the url it was hydrated with. */
|
|
7
|
+
export declare function useRenderedPathname(): string;
|
|
8
|
+
//# sourceMappingURL=PathnameProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathnameProvider.d.ts","sourceRoot":"","sources":["../../src/js/PathnameProvider.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,+BAE3F;AAED,oFAAoF;AACpF,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* The url the server rendered, handed to the client hooks.
|
|
5
|
+
*
|
|
6
|
+
* usePathname used to answer "/" during a server render, because a hook has no
|
|
7
|
+
* props and the module had nothing else to go on. Every prerendered page
|
|
8
|
+
* therefore shipped with the wrong link marked active, corrected only once
|
|
9
|
+
* hydration ran — a visible flash, and simply wrong on a route that ships no
|
|
10
|
+
* client runtime at all.
|
|
11
|
+
*
|
|
12
|
+
* A context rather than a module-level variable: two requests render at once
|
|
13
|
+
* in the same process, and a variable would hand one page the other's url.
|
|
14
|
+
*/
|
|
15
|
+
import { createContext, useContext } from "react";
|
|
16
|
+
const PathnameContext = createContext("/");
|
|
17
|
+
export function PathnameProvider({ value, children }) {
|
|
18
|
+
return _jsx(PathnameContext.Provider, { value: value, children: children });
|
|
19
|
+
}
|
|
20
|
+
/** What the server rendered. On the client this is the url it was hydrated with. */
|
|
21
|
+
export function useRenderedPathname() {
|
|
22
|
+
return useContext(PathnameContext);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=PathnameProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathnameProvider.js","sourceRoot":"","sources":["../../src/js/PathnameProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGlD,MAAM,eAAe,GAAG,aAAa,CAAS,GAAG,CAAC,CAAC;AAEnD,MAAM,UAAU,gBAAgB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAA0C;IAC1F,OAAO,KAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA4B,CAAC;AACvF,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,mBAAmB;IACjC,OAAO,UAAU,CAAC,eAAe,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Component } from "react";
|
|
2
|
+
import type { ErrorInfo, ReactNode } from "react";
|
|
3
|
+
interface Props {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/** Shown while the navigation is in flight. Null keeps the space empty. */
|
|
6
|
+
fallback?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
interface State {
|
|
9
|
+
redirecting: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class RedirectBoundary extends Component<Props, State> {
|
|
12
|
+
state: State;
|
|
13
|
+
static getDerivedStateFromError(error: unknown): State | null;
|
|
14
|
+
componentDidCatch(error: unknown, _info: ErrorInfo): void;
|
|
15
|
+
render(): ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=RedirectBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedirectBoundary.d.ts","sourceRoot":"","sources":["../../src/js/RedirectBoundary.tsx"],"names":[],"mappings":"AAqBA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlD,UAAU,KAAK;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,UAAU,KAAK;IACb,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IAC3D,KAAK,EAAE,KAAK,CAA0B;IAEtC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,IAAI,CAM5D;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAcxD;IAED,MAAM,IAAI,SAAS,CAIlB;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Component } from "react";
|
|
3
|
+
import { parseRedirectDigest } from "../redirectDigest.js";
|
|
4
|
+
import { visit } from "./router";
|
|
5
|
+
export class RedirectBoundary extends Component {
|
|
6
|
+
state = { redirecting: false };
|
|
7
|
+
static getDerivedStateFromError(error) {
|
|
8
|
+
// Reading `digest` rather than the message: React replaces a server
|
|
9
|
+
// error's message in production and transmits the digest either way.
|
|
10
|
+
return parseRedirectDigest(error?.digest)
|
|
11
|
+
? { redirecting: true }
|
|
12
|
+
: null;
|
|
13
|
+
}
|
|
14
|
+
componentDidCatch(error, _info) {
|
|
15
|
+
const target = parseRedirectDigest(error?.digest);
|
|
16
|
+
if (!target)
|
|
17
|
+
throw error;
|
|
18
|
+
// An SPA navigation, not a location assignment: the layouts above this
|
|
19
|
+
// boundary are already mounted and correct, so replacing the document
|
|
20
|
+
// would throw away state the user can see — including whatever they had
|
|
21
|
+
// typed into a page that is only being redirected past.
|
|
22
|
+
//
|
|
23
|
+
// replace, because the url being left never became a page the user was
|
|
24
|
+
// on; leaving a history entry for it means Back returns to a redirect.
|
|
25
|
+
// The server chose this, so it is not one of the app's authored hrefs.
|
|
26
|
+
void visit(target.location, { replace: true });
|
|
27
|
+
}
|
|
28
|
+
render() {
|
|
29
|
+
if (this.state.redirecting)
|
|
30
|
+
return this.props.fallback ?? null;
|
|
31
|
+
return this.props.children;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=RedirectBoundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedirectBoundary.js","sourceRoot":"","sources":["../../src/js/RedirectBoundary.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAqBb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAYjC,MAAM,OAAO,gBAAiB,SAAQ,SAAuB;IAC3D,KAAK,GAAU,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IAEtC,MAAM,CAAC,wBAAwB,CAAC,KAAc;QAC5C,oEAAoE;QACpE,qEAAqE;QACrE,OAAO,mBAAmB,CAAE,KAA8B,EAAE,MAAM,CAAC;YACjE,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE;YACvB,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,KAAgB;QAChD,MAAM,MAAM,GAAG,mBAAmB,CAAE,KAA8B,EAAE,MAAM,CAAC,CAAC;QAE5E,IAAI,CAAC,MAAM;YAAE,MAAM,KAAK,CAAC;QAEzB,uEAAuE;QACvE,sEAAsE;QACtE,wEAAwE;QACxE,wDAAwD;QACxD,EAAE;QACF,uEAAuE;QACvE,uEAAuE;QACvE,uEAAuE;QACvE,KAAK,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC;QAE/D,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export declare function SegmentBoundary({ depth, pageKey, children, }: {
|
|
3
|
+
depth: number;
|
|
4
|
+
/** The page these server-rendered children belong to. */
|
|
5
|
+
pageKey?: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=SegmentBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SegmentBoundary.d.ts","sourceRoot":"","sources":["../../src/js/SegmentBoundary.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,OAAO,EACP,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,SAAS,CAAA;CACpB,+BA8BA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* The point in the tree a navigation can replace on its own.
|
|
5
|
+
*
|
|
6
|
+
* Sits between a layout and its children, so showing a different segment
|
|
7
|
+
* re-renders from here down and leaves the layouts above it mounted. Server
|
|
8
|
+
* components cannot be re-rendered on the client, which is why the seam has to
|
|
9
|
+
* be a client component reading from a store rather than the layout itself.
|
|
10
|
+
*
|
|
11
|
+
* Pages it has already shown stay mounted behind <Activity mode="hidden">.
|
|
12
|
+
* Hidden is not unmounted: effects are torn down but state survives, so
|
|
13
|
+
* returning to a page brings back the form you were filling in. Rendering only
|
|
14
|
+
* the current one would throw that away, which is what replacing the root did.
|
|
15
|
+
*/
|
|
16
|
+
import { Activity, useEffect, useSyncExternalStore } from 'react';
|
|
17
|
+
import { RedirectBoundary } from './RedirectBoundary';
|
|
18
|
+
import { getSegmentState, seedSegment, subscribeToSegment } from './segmentStore';
|
|
19
|
+
export function SegmentBoundary({ depth, pageKey, children, }) {
|
|
20
|
+
const state = useSyncExternalStore((listener) => subscribeToSegment(depth, listener), () => getSegmentState(depth),
|
|
21
|
+
// On the server the tree being rendered IS the current one, so there is
|
|
22
|
+
// never an override; returning null keeps hydration from mismatching.
|
|
23
|
+
() => null);
|
|
24
|
+
// Record the page we arrived on, so a later navigation away and back can
|
|
25
|
+
// return to it. Without this the first page is the one page you cannot keep.
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (pageKey)
|
|
28
|
+
seedSegment(depth, pageKey, children);
|
|
29
|
+
}, [depth, pageKey, children]);
|
|
30
|
+
// Wrapped here rather than around the whole app because this is the closest
|
|
31
|
+
// client component above a page: a redirect thrown inside the page's own
|
|
32
|
+
// Suspense boundary surfaces at the nearest error boundary, and catching it
|
|
33
|
+
// here leaves the layouts above mounted while the navigation runs.
|
|
34
|
+
if (!state)
|
|
35
|
+
return _jsx(RedirectBoundary, { children: children });
|
|
36
|
+
return (_jsx(RedirectBoundary, { children: state.entries.map((entry) => (_jsx(Activity, { mode: entry.key === state.activeKey ? 'visible' : 'hidden', children: entry.tree }, entry.key))) }));
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=SegmentBoundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SegmentBoundary.js","sourceRoot":"","sources":["../../src/js/SegmentBoundary.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,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|
4
|
+
*
|
|
5
|
+
* Server components cannot be re-rendered in the browser, so the swap point
|
|
6
|
+
* has to be a client component reading from a store. With nothing stored it
|
|
7
|
+
* renders what the server sent with the page — which is the behaviour that
|
|
8
|
+
* existed before slots could be revalidated, and is what makes this safe to
|
|
9
|
+
* wrap every slot in.
|
|
10
|
+
*/
|
|
11
|
+
export declare function SlotBoundary({ name, children }: {
|
|
12
|
+
name: string;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}): ReactNode;
|
|
15
|
+
//# sourceMappingURL=SlotBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlotBoundary.d.ts","sourceRoot":"","sources":["../../src/js/SlotBoundary.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,GAOvB,SAAS,CACvE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { getSlotState, subscribeToSlot } from "./slotStore";
|
|
4
|
+
/**
|
|
5
|
+
* The seam a re-rendered slot is swapped in at.
|
|
6
|
+
*
|
|
7
|
+
* Server components cannot be re-rendered in the browser, so the swap point
|
|
8
|
+
* has to be a client component reading from a store. With nothing stored it
|
|
9
|
+
* renders what the server sent with the page — which is the behaviour that
|
|
10
|
+
* existed before slots could be revalidated, and is what makes this safe to
|
|
11
|
+
* wrap every slot in.
|
|
12
|
+
*/
|
|
13
|
+
export function SlotBoundary({ name, children }) {
|
|
14
|
+
const state = useSyncExternalStore((listener) => subscribeToSlot(name, listener), () => getSlotState(name), () => getSlotState(name));
|
|
15
|
+
return (state.tree === undefined ? children : state.tree);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=SlotBoundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlotBoundary.js","sourceRoot":"","sources":["../../src/js/SlotBoundary.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAyC;IACpF,MAAM,KAAK,GAAG,oBAAoB,CAChC,CAAC,QAAQ,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,EAC7C,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EACxB,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CACzB,CAAC;IAEF,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAc,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function createViteRscApp(container?: Document | Element, interceptEntries?: {
|
|
2
|
+
urlPattern: string;
|
|
3
|
+
slot: string;
|
|
4
|
+
}[], options?: {
|
|
5
|
+
staticPayloads?: string | null;
|
|
6
|
+
routes?: unknown[] | null;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=createViteRscApp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createViteRscApp.d.ts","sourceRoot":"","sources":["../../src/js/createViteRscApp.ts"],"names":[],"mappings":"AAoCA,wBAAsB,gBAAgB,CACpC,SAAS,GAAE,QAAQ,GAAG,OAAkB,EACxC,gBAAgB,GAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAO,EAC7D,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;CAAO,GAC1E,OAAO,CAAC,IAAI,CAAC,CA0Mf"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { isSafeRedirect } from "../safeUrl.js";
|
|
2
|
+
import { createFromReadableStream, encodeReply, setServerCallback } from "@vitejs/plugin-rsc/browser";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
import { hydrateRoot } from "react-dom/client";
|
|
5
|
+
import { ActivityRoot } from "./ActivityRouter";
|
|
6
|
+
import { ServerRedirectError, throwForFailedAction } from "./errors";
|
|
7
|
+
import { fetchPagePayload } from "./pagePayload";
|
|
8
|
+
import { clearSegments, restoreSegments, setSegment } from "./segmentStore";
|
|
9
|
+
import { cancelPrefetch, isPrefetched, navigate, refresh, applyRevalidated, prefetch, retentionKey, setCallServer, setHeldLayouts, setStaticPayloads, setStaticRoutes, seedStaticChain, payloadUrl, setDeserializer, setInterceptManifest, setNavigateHandler, setRestoreHandler, setVersion, } from "./navigate";
|
|
10
|
+
export async function createViteRscApp(container = document, interceptEntries = [], options = {}) {
|
|
11
|
+
// An exported build has no server to negotiate with, so payloads live at
|
|
12
|
+
// their own urls rather than behind a header on the page's url.
|
|
13
|
+
setStaticPayloads(options.staticPayloads ?? null);
|
|
14
|
+
// Only an exported build ships this: with no server to negotiate with, the
|
|
15
|
+
// client works out for itself how much of a page it still holds.
|
|
16
|
+
if (options.routes)
|
|
17
|
+
setStaticRoutes(options.routes);
|
|
18
|
+
// The router has to recognise an intercepted link before it asks the server,
|
|
19
|
+
// so the patterns are baked into the generated browser entry. Without them
|
|
20
|
+
// every intercepted route falls through to a full-page navigation.
|
|
21
|
+
setInterceptManifest(interceptEntries);
|
|
22
|
+
async function callServer(id, args) {
|
|
23
|
+
const encoded = await encodeReply(args);
|
|
24
|
+
// encodeReply returns FormData as soon as an argument contains a File.
|
|
25
|
+
// Sending that as multipart would make PHP consume php://input while
|
|
26
|
+
// parsing it, leaving the action with an empty body — so serialize it to
|
|
27
|
+
// raw bytes under an opaque content-type and send the real one in
|
|
28
|
+
// X-RSC-Content-Type for the worker to rebuild FormData from.
|
|
29
|
+
let body;
|
|
30
|
+
let realContentType;
|
|
31
|
+
if (encoded instanceof FormData) {
|
|
32
|
+
const serialized = new Response(encoded);
|
|
33
|
+
body = await serialized.arrayBuffer();
|
|
34
|
+
realContentType = serialized.headers.get("content-type") ?? "multipart/form-data";
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
body = encoded;
|
|
38
|
+
realContentType = "text/plain;charset=UTF-8";
|
|
39
|
+
}
|
|
40
|
+
const res = await fetch("/_rsc/action", {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: {
|
|
43
|
+
"X-RSC-Action": id,
|
|
44
|
+
// Where the action was invoked from. The host resolves it to the
|
|
45
|
+
// components that render the page, so anything the action says it
|
|
46
|
+
// invalidated can come back with the answer instead of being fetched
|
|
47
|
+
// afterwards.
|
|
48
|
+
"X-RSC-Referer": window.location.pathname + window.location.search,
|
|
49
|
+
"X-RSC-Content-Type": realContentType,
|
|
50
|
+
"Content-Type": "application/octet-stream",
|
|
51
|
+
"X-XSRF-TOKEN": decodeURIComponent(document.cookie.match(/XSRF-TOKEN=([^;]+)/)?.[1] ?? ""),
|
|
52
|
+
},
|
|
53
|
+
body,
|
|
54
|
+
});
|
|
55
|
+
// A failed action does not answer with a Flight stream, and the decoder
|
|
56
|
+
// cannot tell — it reports its own parse failure instead of what the
|
|
57
|
+
// server said.
|
|
58
|
+
try {
|
|
59
|
+
await throwForFailedAction(res);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
// A redirect is an instruction, not something for a form to display:
|
|
63
|
+
// an expired session answers this way, and the destination is the login
|
|
64
|
+
// page rather than a message about one.
|
|
65
|
+
if (err instanceof ServerRedirectError) {
|
|
66
|
+
// The destination came off a response header, so it is checked here
|
|
67
|
+
// too — the engine refuses these at the source, but a proxy or a host
|
|
68
|
+
// in front of it can write whatever it likes.
|
|
69
|
+
if (isSafeRedirect(err.location))
|
|
70
|
+
window.location.href = err.location;
|
|
71
|
+
}
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
const answer = await createFromReadableStream(res.body, { callServer });
|
|
75
|
+
return unwrapRevalidated(answer);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Put anything the action re-rendered on screen, and hand back its result.
|
|
79
|
+
*
|
|
80
|
+
* The trees travel with the answer rather than being fetched afterwards, so
|
|
81
|
+
* the caller sees only what its action returned and never knows the page
|
|
82
|
+
* was updated around it.
|
|
83
|
+
*/
|
|
84
|
+
function unwrapRevalidated(answer) {
|
|
85
|
+
if (answer === null || typeof answer !== "object" || !("__rscRevalidated" in answer)) {
|
|
86
|
+
return answer;
|
|
87
|
+
}
|
|
88
|
+
const envelope = answer;
|
|
89
|
+
for (const [target, tree] of Object.entries(envelope.__rscRevalidated)) {
|
|
90
|
+
applyRevalidated(target, tree);
|
|
91
|
+
}
|
|
92
|
+
return envelope.result;
|
|
93
|
+
}
|
|
94
|
+
setDeserializer(createFromReadableStream);
|
|
95
|
+
setCallServer(callServer);
|
|
96
|
+
// The plugin's own "use server" client stubs route through its registered
|
|
97
|
+
// server callback — register the same transport there too.
|
|
98
|
+
setServerCallback(callServer);
|
|
99
|
+
// Link / Form / router live in a separate build graph and reach the SPA
|
|
100
|
+
// engine through these globals.
|
|
101
|
+
window.__rsc_navigate = navigate;
|
|
102
|
+
window.__rsc_prefetch = prefetch;
|
|
103
|
+
window.__rsc_cancel_prefetch =
|
|
104
|
+
cancelPrefetch;
|
|
105
|
+
window.__rsc_is_prefetched =
|
|
106
|
+
isPrefetched;
|
|
107
|
+
window.__rsc_refresh = refresh;
|
|
108
|
+
// Hydrate from the RSC endpoint (same url + X-RSC, no version header).
|
|
109
|
+
//
|
|
110
|
+
// Everything from here to the decode is failure handling, because this is
|
|
111
|
+
// the one request with nothing watching it. A page whose shell is already
|
|
112
|
+
// rendered looks fine while this fails, and its fallbacks stay on screen
|
|
113
|
+
// indefinitely with nothing reported anywhere.
|
|
114
|
+
const res = await fetchPagePayload(payloadUrl(window.location.href));
|
|
115
|
+
// Seed the SPA engine with the build this page was served from, so a
|
|
116
|
+
// redeploy mid-session is caught on the next navigation. This matters most
|
|
117
|
+
// behind a CDN, where the shell may be cached from an older build.
|
|
118
|
+
const servedVersion = res.headers.get("X-RSC-Version");
|
|
119
|
+
if (servedVersion) {
|
|
120
|
+
setVersion(servedVersion);
|
|
121
|
+
}
|
|
122
|
+
// The chain this page is built from, so the next navigation can say what is
|
|
123
|
+
// already mounted and be sent only what changed.
|
|
124
|
+
// A server says what this page is built from; a file server says nothing,
|
|
125
|
+
// so an exported build works it out from the table it was given.
|
|
126
|
+
const servedLayouts = res.headers.get("X-RSC-Layouts");
|
|
127
|
+
if (servedLayouts !== null) {
|
|
128
|
+
setHeldLayouts(servedLayouts.split(","));
|
|
129
|
+
}
|
|
130
|
+
else if (!seedStaticChain(window.location.href)) {
|
|
131
|
+
setHeldLayouts([]);
|
|
132
|
+
}
|
|
133
|
+
const tree = await createFromReadableStream(res.body, { callServer });
|
|
134
|
+
// Retaining the previous page behind <Activity> needs a wrapper above the
|
|
135
|
+
// page, and React will not hydrate a *document* container through one: the
|
|
136
|
+
// root child of a document has to be <html>, and wrapping it hangs the
|
|
137
|
+
// renderer outright (React 19.2.7). An app whose root layout owns <html>
|
|
138
|
+
// therefore hydrates the tree directly and navigations replace it, as before.
|
|
139
|
+
//
|
|
140
|
+
// Apps that hydrate into an element get retention. Giving it to document-
|
|
141
|
+
// rooted apps means SPA navigation returning only the changed segment rather
|
|
142
|
+
// than a whole document, which is an engine change, not a client one.
|
|
143
|
+
const retains = container !== document;
|
|
144
|
+
const shell = retains
|
|
145
|
+
? createElement(ActivityRoot, {
|
|
146
|
+
initialKey: retentionKey(window.location.href, null),
|
|
147
|
+
initialTree: tree,
|
|
148
|
+
})
|
|
149
|
+
: tree;
|
|
150
|
+
const root = hydrateRoot(container, shell, {
|
|
151
|
+
onRecoverableError(error, errorInfo) {
|
|
152
|
+
// A PPR shell is served with its Suspense boundaries deliberately
|
|
153
|
+
// unfinished — the build aborts the render once the static part is out.
|
|
154
|
+
// React reports that as #419 and client-renders the boundary from the
|
|
155
|
+
// Flight payload, which is the intended path, not a fault to report.
|
|
156
|
+
const message = String(error?.message ?? error);
|
|
157
|
+
if (message.includes("419") || message.includes("did not finish this Suspense boundary")) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
console.error(error, errorInfo);
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
// Depth 0 is a whole document and replaces the root. Anything deeper is one
|
|
164
|
+
// segment: handing it to the boundary at that depth leaves the layouts above
|
|
165
|
+
// it mounted, which is the point of asking for a partial render at all.
|
|
166
|
+
setNavigateHandler((tree, key, segmentDepth) => {
|
|
167
|
+
const newTree = tree;
|
|
168
|
+
if (segmentDepth > 0) {
|
|
169
|
+
setSegment(segmentDepth, key, newTree);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
clearSegments();
|
|
173
|
+
root.render(newTree);
|
|
174
|
+
});
|
|
175
|
+
// Back and forward reveal a page the boundaries are still holding, with the
|
|
176
|
+
// form you were filling in still filled in, and without asking the server.
|
|
177
|
+
setRestoreHandler((key) => restoreSegments(key));
|
|
178
|
+
window.addEventListener("popstate", () => {
|
|
179
|
+
// restore: back and forward reveal the page you were on, with its state.
|
|
180
|
+
// Wherever the browser just went; not a literal this app wrote.
|
|
181
|
+
navigate(window.location.href, { replace: true, restore: true });
|
|
182
|
+
});
|
|
183
|
+
history.replaceState({ rscUrl: window.location.href }, "", window.location.href);
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=createViteRscApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AE,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare class ServerValidationError extends Error {
|
|
2
|
+
readonly errors: Record<string, string[]>;
|
|
3
|
+
constructor(message: string, errors: Record<string, string[]>);
|
|
4
|
+
}
|
|
5
|
+
/** An action answered with a location instead of a result. */
|
|
6
|
+
export declare class ServerRedirectError extends Error {
|
|
7
|
+
readonly location: string;
|
|
8
|
+
constructor(location: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class ServerAuthenticationError extends Error {
|
|
11
|
+
constructor(message?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class ServerAuthorizationError extends Error {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class ServerDumpError extends Error {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
19
|
+
export declare class ServerSessionExpiredError extends Error {
|
|
20
|
+
constructor(message?: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Turn a failed server-action response into the error it describes.
|
|
24
|
+
*
|
|
25
|
+
* A server action that does not succeed answers with JSON or a redirect
|
|
26
|
+
* header rather than a Flight stream. Passing one of those to the Flight
|
|
27
|
+
* decoder does not produce the server's message — it produces an internal
|
|
28
|
+
* parser failure ("enqueueModel is not a function") or a truncated read
|
|
29
|
+
* ("Connection closed."), which is what reached onError before this existed.
|
|
30
|
+
*
|
|
31
|
+
* Returns without throwing when the response is a stream to be decoded.
|
|
32
|
+
*/
|
|
33
|
+
export declare function throwForFailedAction(response: Response): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Reject a payload response that is not one.
|
|
36
|
+
*
|
|
37
|
+
* The page a PPR route serves is a static shell: real HTML, status 200, with
|
|
38
|
+
* its Suspense fallbacks showing. Everything below them arrives in a second
|
|
39
|
+
* request. If that request fails there is nothing on screen to say so — the
|
|
40
|
+
* skeletons simply stay, for ever — and handing the failure body to the Flight
|
|
41
|
+
* decoder reports the decoder's confusion rather than the status.
|
|
42
|
+
*/
|
|
43
|
+
export declare function throwForFailedPayload(response: Response): void;
|
|
44
|
+
/**
|
|
45
|
+
* Announce a failure that nothing else will.
|
|
46
|
+
*
|
|
47
|
+
* Dispatched as well as logged: an app that wants to replace a stuck skeleton
|
|
48
|
+
* with something honest has no other way to find out.
|
|
49
|
+
*/
|
|
50
|
+
export declare function reportClientFailure(scope: string, error: unknown): void;
|
|
51
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/js/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,SAAgB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAEjD,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAI5D;CACF;AAED,8DAA8D;AAC9D,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,QAAQ,EAAE,MAAM,CAAC;IAEjC,YAAY,QAAQ,EAAE,MAAM,EAI3B;CACF;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAO,GAAE,MAA2B,EAG/C;CACF;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAO,GAAE,MAAuC,EAG3D;CACF;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,cAGC;CACF;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAO,GAAE,MAA6D,EAGjF;CACF;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAI9D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAMvE"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export class ServerValidationError extends Error {
|
|
2
|
+
errors;
|
|
3
|
+
constructor(message, errors) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "ServerValidationError";
|
|
6
|
+
this.errors = errors;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** An action answered with a location instead of a result. */
|
|
10
|
+
export class ServerRedirectError extends Error {
|
|
11
|
+
location;
|
|
12
|
+
constructor(location) {
|
|
13
|
+
super(`Server action redirected to ${location}`);
|
|
14
|
+
this.name = "ServerRedirectError";
|
|
15
|
+
this.location = location;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class ServerAuthenticationError extends Error {
|
|
19
|
+
constructor(message = "Unauthenticated.") {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "ServerAuthenticationError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class ServerAuthorizationError extends Error {
|
|
25
|
+
constructor(message = "This action is unauthorized.") {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "ServerAuthorizationError";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class ServerDumpError extends Error {
|
|
31
|
+
constructor() {
|
|
32
|
+
super("Server returned a dump response.");
|
|
33
|
+
this.name = "ServerDumpError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class ServerSessionExpiredError extends Error {
|
|
37
|
+
constructor(message = "Your session has expired. Please refresh the page.") {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = "ServerSessionExpiredError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Turn a failed server-action response into the error it describes.
|
|
44
|
+
*
|
|
45
|
+
* A server action that does not succeed answers with JSON or a redirect
|
|
46
|
+
* header rather than a Flight stream. Passing one of those to the Flight
|
|
47
|
+
* decoder does not produce the server's message — it produces an internal
|
|
48
|
+
* parser failure ("enqueueModel is not a function") or a truncated read
|
|
49
|
+
* ("Connection closed."), which is what reached onError before this existed.
|
|
50
|
+
*
|
|
51
|
+
* Returns without throwing when the response is a stream to be decoded.
|
|
52
|
+
*/
|
|
53
|
+
export async function throwForFailedAction(response) {
|
|
54
|
+
if (response.ok)
|
|
55
|
+
return;
|
|
56
|
+
// Auth and explicit redirects travel as a header, whatever the status.
|
|
57
|
+
const location = response.headers.get("X-RSC-Redirect");
|
|
58
|
+
if (location !== null && location !== "") {
|
|
59
|
+
throw new ServerRedirectError(location);
|
|
60
|
+
}
|
|
61
|
+
if (response.status === 422) {
|
|
62
|
+
const payload = (await response.json().catch(() => null));
|
|
63
|
+
throw new ServerValidationError(payload?.message ?? "Validation failed", payload?.errors ?? {});
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Server action failed with ${response.status}`);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Reject a payload response that is not one.
|
|
69
|
+
*
|
|
70
|
+
* The page a PPR route serves is a static shell: real HTML, status 200, with
|
|
71
|
+
* its Suspense fallbacks showing. Everything below them arrives in a second
|
|
72
|
+
* request. If that request fails there is nothing on screen to say so — the
|
|
73
|
+
* skeletons simply stay, for ever — and handing the failure body to the Flight
|
|
74
|
+
* decoder reports the decoder's confusion rather than the status.
|
|
75
|
+
*/
|
|
76
|
+
export function throwForFailedPayload(response) {
|
|
77
|
+
if (response.ok)
|
|
78
|
+
return;
|
|
79
|
+
throw new Error(`RSC payload request failed with ${response.status}`);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Announce a failure that nothing else will.
|
|
83
|
+
*
|
|
84
|
+
* Dispatched as well as logged: an app that wants to replace a stuck skeleton
|
|
85
|
+
* with something honest has no other way to find out.
|
|
86
|
+
*/
|
|
87
|
+
export function reportClientFailure(scope, error) {
|
|
88
|
+
if (typeof window !== "undefined") {
|
|
89
|
+
window.dispatchEvent(new CustomEvent("rsc-client-error", { detail: { scope, error } }));
|
|
90
|
+
}
|
|
91
|
+
console.error(`[rsc-kit] ${scope}`, error);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/js/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9B,MAAM,CAA2B;IAEjD,YAAY,OAAe,EAAE,MAAgC;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,8DAA8D;AAC9D,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5B,QAAQ,CAAS;IAEjC,YAAY,QAAgB;QAC1B,KAAK,CAAC,+BAA+B,QAAQ,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAO,GAAW,kBAAkB;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAO,GAAW,8BAA8B;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF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