@ovineko/spa-guard-react-router 0.0.1-alpha-18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ // src/react-router/index.tsx
2
+ import { useEffect } from "react";
3
+ import { useRouteError } from "react-router";
4
+ import {
5
+ DefaultErrorFallback,
6
+ useSpaGuardState
7
+ } from "@ovineko/spa-guard-react";
8
+ import { handleErrorWithSpaGuard, isChunkError } from "@ovineko/spa-guard/_internal";
9
+ import { jsx } from "react/jsx-runtime";
10
+ var DefaultRouterFallback = ({
11
+ error,
12
+ isChunkError: isChunk,
13
+ isRetrying,
14
+ spaGuardState
15
+ }) => /* @__PURE__ */ jsx(
16
+ DefaultErrorFallback,
17
+ {
18
+ error,
19
+ isChunkError: isChunk,
20
+ isRetrying,
21
+ spaGuardState
22
+ }
23
+ );
24
+ var ErrorBoundaryReactRouter = ({
25
+ autoRetryChunkErrors = true,
26
+ fallback: Fallback,
27
+ onError,
28
+ sendBeacon: shouldSendBeacon = true
29
+ }) => {
30
+ const routeError = useRouteError();
31
+ const spaGuardState = useSpaGuardState();
32
+ useEffect(() => {
33
+ handleErrorWithSpaGuard(routeError, {
34
+ autoRetryChunkErrors,
35
+ eventName: "react-router-error",
36
+ onError,
37
+ sendBeaconOnError: shouldSendBeacon
38
+ });
39
+ }, [routeError]);
40
+ const isChunk = isChunkError(routeError);
41
+ const isRetrying = spaGuardState.isWaiting && spaGuardState.currentAttempt > 0;
42
+ const fallbackProps = {
43
+ error: routeError,
44
+ isChunkError: isChunk,
45
+ isRetrying,
46
+ spaGuardState
47
+ };
48
+ if (Fallback) {
49
+ return /* @__PURE__ */ jsx(Fallback, { ...fallbackProps });
50
+ }
51
+ return /* @__PURE__ */ jsx(DefaultRouterFallback, { ...fallbackProps });
52
+ };
53
+ export {
54
+ ErrorBoundaryReactRouter
55
+ };
@@ -0,0 +1,25 @@
1
+ import { type SpaGuardState } from "@ovineko/spa-guard-react";
2
+ /**
3
+ * Props for the ErrorBoundaryReactRouter component
4
+ */
5
+ export interface ErrorBoundaryReactRouterProps {
6
+ autoRetryChunkErrors?: boolean;
7
+ fallback?: ((props: RouterFallbackProps) => React.ReactElement) | React.ComponentType<RouterFallbackProps>;
8
+ onError?: (error: unknown) => void;
9
+ sendBeacon?: boolean;
10
+ }
11
+ /**
12
+ * Props passed to the fallback component when a route error occurs
13
+ */
14
+ export interface RouterFallbackProps {
15
+ error: unknown;
16
+ isChunkError: boolean;
17
+ isRetrying: boolean;
18
+ spaGuardState: SpaGuardState;
19
+ }
20
+ /**
21
+ * Error boundary for React Router with spa-guard integration.
22
+ *
23
+ * Uses `useRouteError()` to catch route errors and automatically retries chunk loading errors.
24
+ */
25
+ export declare const ErrorBoundaryReactRouter: React.FC<ErrorBoundaryReactRouterProps>;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@ovineko/spa-guard-react-router",
3
+ "version": "0.0.1-alpha-18",
4
+ "description": "React Router v7 error boundary integration for spa-guard",
5
+ "keywords": [
6
+ "spa",
7
+ "react",
8
+ "react-router",
9
+ "error-boundary"
10
+ ],
11
+ "homepage": "https://github.com/ovineko/ovineko/tree/main/spa-guard/react-router",
12
+ "bugs": {
13
+ "url": "https://github.com/ovineko/ovineko/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ovineko/ovineko.git",
18
+ "directory": "spa-guard/react-router"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Alexander Svinarev <shibanet0@gmail.com> (shibanet0.com)",
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/react-router/index.d.ts",
27
+ "default": "./dist/react-router/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "dependencies": {
35
+ "@ovineko/spa-guard": "0.0.1-alpha-18",
36
+ "@ovineko/spa-guard-react": "0.0.1-alpha-18"
37
+ },
38
+ "peerDependencies": {
39
+ "react": "^19",
40
+ "react-router": "^7"
41
+ },
42
+ "engines": {
43
+ "node": ">=22.15.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }