react-error-boundary 4.1.2 → 6.0.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/dist/declarations/src/types.d.ts +1 -2
- package/dist/declarations/src/withErrorBoundary.d.ts +2 -2
- package/dist/react-error-boundary.d.ts +2 -0
- package/package.json +32 -43
- package/dist/react-error-boundary.cjs.d.mts +0 -2
- package/dist/react-error-boundary.cjs.d.mts.map +0 -1
- package/dist/react-error-boundary.cjs.d.ts +0 -2
- package/dist/react-error-boundary.cjs.d.ts.map +0 -1
- package/dist/react-error-boundary.cjs.js +0 -158
- package/dist/react-error-boundary.cjs.mjs +0 -6
- package/dist/react-error-boundary.development.cjs.js +0 -161
- package/dist/react-error-boundary.development.cjs.mjs +0 -6
- /package/dist/{react-error-boundary.development.esm.js → react-error-boundary.development.js} +0 -0
- /package/dist/{react-error-boundary.esm.js → react-error-boundary.js} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ComponentType, ErrorInfo, PropsWithChildren, ReactNode } from "react";
|
|
2
|
-
declare function FallbackRender(props: FallbackProps): ReactNode;
|
|
3
2
|
export type FallbackProps = {
|
|
4
3
|
error: any;
|
|
5
4
|
resetErrorBoundary: (...args: any[]) => void;
|
|
@@ -24,7 +23,7 @@ export type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {
|
|
|
24
23
|
export type ErrorBoundaryPropsWithRender = ErrorBoundarySharedProps & {
|
|
25
24
|
fallback?: never;
|
|
26
25
|
FallbackComponent?: never;
|
|
27
|
-
fallbackRender:
|
|
26
|
+
fallbackRender: (props: FallbackProps) => ReactNode;
|
|
28
27
|
};
|
|
29
28
|
export type ErrorBoundaryPropsWithFallback = ErrorBoundarySharedProps & {
|
|
30
29
|
fallback: ReactNode;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RefAttributes, ForwardRefExoticComponent, PropsWithoutRef, ComponentType } from "react";
|
|
1
|
+
import { RefAttributes, ForwardRefExoticComponent, PropsWithoutRef, ComponentType, ComponentRef, ComponentProps } from "react";
|
|
2
2
|
import { ErrorBoundaryProps } from "./types.js";
|
|
3
|
-
export declare function withErrorBoundary<
|
|
3
|
+
export declare function withErrorBoundary<T extends ComponentType<any>>(component: T, errorBoundaryProps: ErrorBoundaryProps): ForwardRefExoticComponent<PropsWithoutRef<ComponentProps<T>> & RefAttributes<ComponentRef<T>>>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "./declarations/src/index.js";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVhY3QtZXJyb3ItYm91bmRhcnkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-error-boundary",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Simple reusable React error boundary component",
|
|
5
6
|
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
|
|
6
7
|
"license": "MIT",
|
|
@@ -8,23 +9,11 @@
|
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "https://github.com/bvaughn/react-error-boundary"
|
|
10
11
|
},
|
|
11
|
-
"packageManager": "pnpm@9.6.0",
|
|
12
|
-
"main": "dist/react-error-boundary.cjs.js",
|
|
13
|
-
"module": "dist/react-error-boundary.esm.js",
|
|
14
12
|
"exports": {
|
|
15
13
|
".": {
|
|
16
|
-
"types":
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
"development": {
|
|
21
|
-
"module": "./dist/react-error-boundary.development.esm.js",
|
|
22
|
-
"import": "./dist/react-error-boundary.development.cjs.mjs",
|
|
23
|
-
"default": "./dist/react-error-boundary.development.cjs.js"
|
|
24
|
-
},
|
|
25
|
-
"module": "./dist/react-error-boundary.esm.js",
|
|
26
|
-
"import": "./dist/react-error-boundary.cjs.mjs",
|
|
27
|
-
"default": "./dist/react-error-boundary.cjs.js"
|
|
14
|
+
"types": "./dist/react-error-boundary.js",
|
|
15
|
+
"development": "./dist/react-error-boundary.development.js",
|
|
16
|
+
"default": "./dist/react-error-boundary.js"
|
|
28
17
|
},
|
|
29
18
|
"./package.json": "./package.json"
|
|
30
19
|
},
|
|
@@ -34,49 +23,35 @@
|
|
|
34
23
|
"default": "./src/env-conditions/production.ts"
|
|
35
24
|
}
|
|
36
25
|
},
|
|
37
|
-
"types": "dist/react-error-boundary.
|
|
26
|
+
"types": "dist/react-error-boundary.d.ts",
|
|
38
27
|
"files": [
|
|
39
28
|
"dist"
|
|
40
29
|
],
|
|
41
30
|
"sideEffects": false,
|
|
42
|
-
"scripts": {
|
|
43
|
-
"clear": "pnpm clear:builds & pnpm clear:node_modules",
|
|
44
|
-
"clear:builds": "rimraf ./dist",
|
|
45
|
-
"clear:node_modules": "rimraf ./node_modules",
|
|
46
|
-
"prerelease": "preconstruct build",
|
|
47
|
-
"lint": "eslint .",
|
|
48
|
-
"lint:fix": "eslint . --fix",
|
|
49
|
-
"test": "jest",
|
|
50
|
-
"test:watch": "jest --watch",
|
|
51
|
-
"typescript": "tsc --noEmit",
|
|
52
|
-
"typescript:watch": "tsc --noEmit --watch"
|
|
53
|
-
},
|
|
54
31
|
"dependencies": {
|
|
55
32
|
"@babel/runtime": "^7.12.5"
|
|
56
33
|
},
|
|
57
34
|
"devDependencies": {
|
|
58
35
|
"@babel/preset-env": "^7.22.5",
|
|
59
36
|
"@babel/preset-typescript": "^7.21.5",
|
|
60
|
-
"@preconstruct/cli": "^2.8.
|
|
37
|
+
"@preconstruct/cli": "^2.8.12",
|
|
61
38
|
"@types/assert": "^1.5.10",
|
|
62
|
-
"@types/
|
|
63
|
-
"@types/react": "^18",
|
|
39
|
+
"@types/react": "^18.3.17",
|
|
64
40
|
"@types/react-dom": "^18",
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
|
66
41
|
"assert": "^2.0.0",
|
|
67
|
-
"eslint": "^
|
|
68
|
-
"eslint-config-prettier": "^9.
|
|
42
|
+
"eslint": "^9.13.0",
|
|
43
|
+
"eslint-config-prettier": "^9.1.0",
|
|
69
44
|
"eslint-plugin-import": "^2.25.2",
|
|
70
|
-
"eslint-plugin-prettier": "^5.
|
|
71
|
-
"eslint-plugin-react": "^7.
|
|
72
|
-
"
|
|
73
|
-
"jest-environment-jsdom": "^29.4.3",
|
|
45
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
46
|
+
"eslint-plugin-react": "^7.37.2",
|
|
47
|
+
"globals": "^15.11.0",
|
|
74
48
|
"prettier": "^3.0.1",
|
|
75
49
|
"react": "^18",
|
|
76
50
|
"react-dom": "^18",
|
|
77
51
|
"rimraf": "^6.0.1",
|
|
78
|
-
"
|
|
79
|
-
"typescript": "^5.
|
|
52
|
+
"vitest": "^3.1.2",
|
|
53
|
+
"typescript": "^5.8.3",
|
|
54
|
+
"typescript-eslint": "^8.18.0"
|
|
80
55
|
},
|
|
81
56
|
"peerDependencies": {
|
|
82
57
|
"react": ">=16.13.1"
|
|
@@ -86,7 +61,21 @@
|
|
|
86
61
|
"importConditionDefaultExport": "default"
|
|
87
62
|
},
|
|
88
63
|
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
|
|
89
|
-
"
|
|
64
|
+
"distInRoot": true,
|
|
65
|
+
"importsConditions": true,
|
|
66
|
+
"typeModule": true
|
|
90
67
|
}
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"clear": "pnpm clear:builds & pnpm clear:node_modules",
|
|
71
|
+
"clear:builds": "rimraf ./dist",
|
|
72
|
+
"clear:node_modules": "rimraf ./node_modules",
|
|
73
|
+
"prerelease": "preconstruct build",
|
|
74
|
+
"lint": "eslint .",
|
|
75
|
+
"lint:fix": "eslint . --fix",
|
|
76
|
+
"test": "vitest --environment=jsdom --watch=false",
|
|
77
|
+
"test:watch": "vitest --environment=jsdom --watch",
|
|
78
|
+
"typescript": "tsc --noEmit",
|
|
79
|
+
"typescript:watch": "tsc --noEmit --watch"
|
|
91
80
|
}
|
|
92
|
-
}
|
|
81
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react-error-boundary.cjs.d.mts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react-error-boundary.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var react = require('react');
|
|
7
|
-
|
|
8
|
-
const ErrorBoundaryContext = react.createContext(null);
|
|
9
|
-
|
|
10
|
-
const initialState = {
|
|
11
|
-
didCatch: false,
|
|
12
|
-
error: null
|
|
13
|
-
};
|
|
14
|
-
class ErrorBoundary extends react.Component {
|
|
15
|
-
constructor(props) {
|
|
16
|
-
super(props);
|
|
17
|
-
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
18
|
-
this.state = initialState;
|
|
19
|
-
}
|
|
20
|
-
static getDerivedStateFromError(error) {
|
|
21
|
-
return {
|
|
22
|
-
didCatch: true,
|
|
23
|
-
error
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
resetErrorBoundary() {
|
|
27
|
-
const {
|
|
28
|
-
error
|
|
29
|
-
} = this.state;
|
|
30
|
-
if (error !== null) {
|
|
31
|
-
var _this$props$onReset, _this$props;
|
|
32
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
33
|
-
args[_key] = arguments[_key];
|
|
34
|
-
}
|
|
35
|
-
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
36
|
-
args,
|
|
37
|
-
reason: "imperative-api"
|
|
38
|
-
});
|
|
39
|
-
this.setState(initialState);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
componentDidCatch(error, info) {
|
|
43
|
-
var _this$props$onError, _this$props2;
|
|
44
|
-
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
45
|
-
}
|
|
46
|
-
componentDidUpdate(prevProps, prevState) {
|
|
47
|
-
const {
|
|
48
|
-
didCatch
|
|
49
|
-
} = this.state;
|
|
50
|
-
const {
|
|
51
|
-
resetKeys
|
|
52
|
-
} = this.props;
|
|
53
|
-
|
|
54
|
-
// There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,
|
|
55
|
-
// we'd end up resetting the error boundary immediately.
|
|
56
|
-
// This would likely trigger a second error to be thrown.
|
|
57
|
-
// So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.
|
|
58
|
-
|
|
59
|
-
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
60
|
-
var _this$props$onReset2, _this$props3;
|
|
61
|
-
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
62
|
-
next: resetKeys,
|
|
63
|
-
prev: prevProps.resetKeys,
|
|
64
|
-
reason: "keys"
|
|
65
|
-
});
|
|
66
|
-
this.setState(initialState);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
render() {
|
|
70
|
-
const {
|
|
71
|
-
children,
|
|
72
|
-
fallbackRender,
|
|
73
|
-
FallbackComponent,
|
|
74
|
-
fallback
|
|
75
|
-
} = this.props;
|
|
76
|
-
const {
|
|
77
|
-
didCatch,
|
|
78
|
-
error
|
|
79
|
-
} = this.state;
|
|
80
|
-
let childToRender = children;
|
|
81
|
-
if (didCatch) {
|
|
82
|
-
const props = {
|
|
83
|
-
error,
|
|
84
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
85
|
-
};
|
|
86
|
-
if (typeof fallbackRender === "function") {
|
|
87
|
-
childToRender = fallbackRender(props);
|
|
88
|
-
} else if (FallbackComponent) {
|
|
89
|
-
childToRender = react.createElement(FallbackComponent, props);
|
|
90
|
-
} else if (fallback !== undefined) {
|
|
91
|
-
childToRender = fallback;
|
|
92
|
-
} else {
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return react.createElement(ErrorBoundaryContext.Provider, {
|
|
97
|
-
value: {
|
|
98
|
-
didCatch,
|
|
99
|
-
error,
|
|
100
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
101
|
-
}
|
|
102
|
-
}, childToRender);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function hasArrayChanged() {
|
|
106
|
-
let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
107
|
-
let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
108
|
-
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function assertErrorBoundaryContext(value) {
|
|
112
|
-
if (value == null || typeof value.didCatch !== "boolean" || typeof value.resetErrorBoundary !== "function") {
|
|
113
|
-
throw new Error("ErrorBoundaryContext not found");
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function useErrorBoundary() {
|
|
118
|
-
const context = react.useContext(ErrorBoundaryContext);
|
|
119
|
-
assertErrorBoundaryContext(context);
|
|
120
|
-
const [state, setState] = react.useState({
|
|
121
|
-
error: null,
|
|
122
|
-
hasError: false
|
|
123
|
-
});
|
|
124
|
-
const memoized = react.useMemo(() => ({
|
|
125
|
-
resetBoundary: () => {
|
|
126
|
-
context.resetErrorBoundary();
|
|
127
|
-
setState({
|
|
128
|
-
error: null,
|
|
129
|
-
hasError: false
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
showBoundary: error => setState({
|
|
133
|
-
error,
|
|
134
|
-
hasError: true
|
|
135
|
-
})
|
|
136
|
-
}), [context.resetErrorBoundary]);
|
|
137
|
-
if (state.hasError) {
|
|
138
|
-
throw state.error;
|
|
139
|
-
}
|
|
140
|
-
return memoized;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function withErrorBoundary(component, errorBoundaryProps) {
|
|
144
|
-
const Wrapped = react.forwardRef((props, ref) => react.createElement(ErrorBoundary, errorBoundaryProps, react.createElement(component, {
|
|
145
|
-
...props,
|
|
146
|
-
ref
|
|
147
|
-
})));
|
|
148
|
-
|
|
149
|
-
// Format for display in DevTools
|
|
150
|
-
const name = component.displayName || component.name || "Unknown";
|
|
151
|
-
Wrapped.displayName = "withErrorBoundary(".concat(name, ")");
|
|
152
|
-
return Wrapped;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
exports.ErrorBoundary = ErrorBoundary;
|
|
156
|
-
exports.ErrorBoundaryContext = ErrorBoundaryContext;
|
|
157
|
-
exports.useErrorBoundary = useErrorBoundary;
|
|
158
|
-
exports.withErrorBoundary = withErrorBoundary;
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var react = require('react');
|
|
7
|
-
|
|
8
|
-
const ErrorBoundaryContext = react.createContext(null);
|
|
9
|
-
|
|
10
|
-
const initialState = {
|
|
11
|
-
didCatch: false,
|
|
12
|
-
error: null
|
|
13
|
-
};
|
|
14
|
-
class ErrorBoundary extends react.Component {
|
|
15
|
-
constructor(props) {
|
|
16
|
-
super(props);
|
|
17
|
-
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
18
|
-
this.state = initialState;
|
|
19
|
-
}
|
|
20
|
-
static getDerivedStateFromError(error) {
|
|
21
|
-
return {
|
|
22
|
-
didCatch: true,
|
|
23
|
-
error
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
resetErrorBoundary() {
|
|
27
|
-
const {
|
|
28
|
-
error
|
|
29
|
-
} = this.state;
|
|
30
|
-
if (error !== null) {
|
|
31
|
-
var _this$props$onReset, _this$props;
|
|
32
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
33
|
-
args[_key] = arguments[_key];
|
|
34
|
-
}
|
|
35
|
-
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
36
|
-
args,
|
|
37
|
-
reason: "imperative-api"
|
|
38
|
-
});
|
|
39
|
-
this.setState(initialState);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
componentDidCatch(error, info) {
|
|
43
|
-
var _this$props$onError, _this$props2;
|
|
44
|
-
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
45
|
-
}
|
|
46
|
-
componentDidUpdate(prevProps, prevState) {
|
|
47
|
-
const {
|
|
48
|
-
didCatch
|
|
49
|
-
} = this.state;
|
|
50
|
-
const {
|
|
51
|
-
resetKeys
|
|
52
|
-
} = this.props;
|
|
53
|
-
|
|
54
|
-
// There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,
|
|
55
|
-
// we'd end up resetting the error boundary immediately.
|
|
56
|
-
// This would likely trigger a second error to be thrown.
|
|
57
|
-
// So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.
|
|
58
|
-
|
|
59
|
-
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
60
|
-
var _this$props$onReset2, _this$props3;
|
|
61
|
-
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
62
|
-
next: resetKeys,
|
|
63
|
-
prev: prevProps.resetKeys,
|
|
64
|
-
reason: "keys"
|
|
65
|
-
});
|
|
66
|
-
this.setState(initialState);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
render() {
|
|
70
|
-
const {
|
|
71
|
-
children,
|
|
72
|
-
fallbackRender,
|
|
73
|
-
FallbackComponent,
|
|
74
|
-
fallback
|
|
75
|
-
} = this.props;
|
|
76
|
-
const {
|
|
77
|
-
didCatch,
|
|
78
|
-
error
|
|
79
|
-
} = this.state;
|
|
80
|
-
let childToRender = children;
|
|
81
|
-
if (didCatch) {
|
|
82
|
-
const props = {
|
|
83
|
-
error,
|
|
84
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
85
|
-
};
|
|
86
|
-
if (typeof fallbackRender === "function") {
|
|
87
|
-
childToRender = fallbackRender(props);
|
|
88
|
-
} else if (FallbackComponent) {
|
|
89
|
-
childToRender = react.createElement(FallbackComponent, props);
|
|
90
|
-
} else if (fallback !== undefined) {
|
|
91
|
-
childToRender = fallback;
|
|
92
|
-
} else {
|
|
93
|
-
{
|
|
94
|
-
console.error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");
|
|
95
|
-
}
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return react.createElement(ErrorBoundaryContext.Provider, {
|
|
100
|
-
value: {
|
|
101
|
-
didCatch,
|
|
102
|
-
error,
|
|
103
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
104
|
-
}
|
|
105
|
-
}, childToRender);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function hasArrayChanged() {
|
|
109
|
-
let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
110
|
-
let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
111
|
-
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function assertErrorBoundaryContext(value) {
|
|
115
|
-
if (value == null || typeof value.didCatch !== "boolean" || typeof value.resetErrorBoundary !== "function") {
|
|
116
|
-
throw new Error("ErrorBoundaryContext not found");
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function useErrorBoundary() {
|
|
121
|
-
const context = react.useContext(ErrorBoundaryContext);
|
|
122
|
-
assertErrorBoundaryContext(context);
|
|
123
|
-
const [state, setState] = react.useState({
|
|
124
|
-
error: null,
|
|
125
|
-
hasError: false
|
|
126
|
-
});
|
|
127
|
-
const memoized = react.useMemo(() => ({
|
|
128
|
-
resetBoundary: () => {
|
|
129
|
-
context.resetErrorBoundary();
|
|
130
|
-
setState({
|
|
131
|
-
error: null,
|
|
132
|
-
hasError: false
|
|
133
|
-
});
|
|
134
|
-
},
|
|
135
|
-
showBoundary: error => setState({
|
|
136
|
-
error,
|
|
137
|
-
hasError: true
|
|
138
|
-
})
|
|
139
|
-
}), [context.resetErrorBoundary]);
|
|
140
|
-
if (state.hasError) {
|
|
141
|
-
throw state.error;
|
|
142
|
-
}
|
|
143
|
-
return memoized;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function withErrorBoundary(component, errorBoundaryProps) {
|
|
147
|
-
const Wrapped = react.forwardRef((props, ref) => react.createElement(ErrorBoundary, errorBoundaryProps, react.createElement(component, {
|
|
148
|
-
...props,
|
|
149
|
-
ref
|
|
150
|
-
})));
|
|
151
|
-
|
|
152
|
-
// Format for display in DevTools
|
|
153
|
-
const name = component.displayName || component.name || "Unknown";
|
|
154
|
-
Wrapped.displayName = "withErrorBoundary(".concat(name, ")");
|
|
155
|
-
return Wrapped;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
exports.ErrorBoundary = ErrorBoundary;
|
|
159
|
-
exports.ErrorBoundaryContext = ErrorBoundaryContext;
|
|
160
|
-
exports.useErrorBoundary = useErrorBoundary;
|
|
161
|
-
exports.withErrorBoundary = withErrorBoundary;
|
/package/dist/{react-error-boundary.development.esm.js → react-error-boundary.development.js}
RENAMED
|
File without changes
|
|
File without changes
|