react-error-boundary 3.1.0 → 3.1.4
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 +6 -2
- package/dist/index.d.ts +9 -4
- package/dist/react-error-boundary.cjs.d.ts +1 -1
- package/dist/react-error-boundary.cjs.js +33 -21
- package/dist/react-error-boundary.esm.d.ts +1 -1
- package/dist/react-error-boundary.esm.js +14 -21
- package/dist/react-error-boundary.umd.d.ts +1 -1
- package/dist/react-error-boundary.umd.js +45 -23
- package/dist/react-error-boundary.umd.js.map +1 -1
- package/dist/react-error-boundary.umd.min.d.ts +1 -1
- package/dist/react-error-boundary.umd.min.js +1 -1
- package/dist/react-error-boundary.umd.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ react-error-boundary
|
|
|
43
43
|
- [Error Recovery](#error-recovery)
|
|
44
44
|
- [API](#api)
|
|
45
45
|
- [`ErrorBoundary` props](#errorboundary-props)
|
|
46
|
-
- [`useErrorHandler(error?:
|
|
46
|
+
- [`useErrorHandler(error?: unknown)`](#useerrorhandlererror-unknown)
|
|
47
47
|
- [Issues](#issues)
|
|
48
48
|
- [🐛 Bugs](#-bugs)
|
|
49
49
|
- [💡 Feature Requests](#-feature-requests)
|
|
@@ -289,7 +289,7 @@ See the recovery examples above.
|
|
|
289
289
|
This is called when the `resetKeys` are changed (triggering a reset of the
|
|
290
290
|
`ErrorBoundary`). It's called with the `prevResetKeys` and the `resetKeys`.
|
|
291
291
|
|
|
292
|
-
### `useErrorHandler(error?:
|
|
292
|
+
### `useErrorHandler(error?: unknown)`
|
|
293
293
|
|
|
294
294
|
React's error boundaries feature is limited in that the boundaries can only
|
|
295
295
|
handle errors thrown during React's lifecycles. To quote
|
|
@@ -316,6 +316,8 @@ There are two ways to use `useErrorHandler`:
|
|
|
316
316
|
Here's an example:
|
|
317
317
|
|
|
318
318
|
```javascript
|
|
319
|
+
import { useErrorHandler } from 'react-error-boundary'
|
|
320
|
+
|
|
319
321
|
function Greeting() {
|
|
320
322
|
const [greeting, setGreeting] = React.useState(null)
|
|
321
323
|
const handleError = useErrorHandler()
|
|
@@ -358,6 +360,8 @@ function handleSubmit(event) {
|
|
|
358
360
|
Alternatively, let's say you're using a hook that gives you the error:
|
|
359
361
|
|
|
360
362
|
```javascript
|
|
363
|
+
import { useErrorHandler } from 'react-error-boundary'
|
|
364
|
+
|
|
361
365
|
function Greeting() {
|
|
362
366
|
const [name, setName] = React.useState('')
|
|
363
367
|
const {greeting, error} = useGreeting(name)
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ interface ErrorBoundaryPropsWithComponent {
|
|
|
10
10
|
componentStack: string;
|
|
11
11
|
}) => void;
|
|
12
12
|
resetKeys?: Array<unknown>;
|
|
13
|
+
fallback?: never;
|
|
13
14
|
FallbackComponent: React.ComponentType<FallbackProps>;
|
|
15
|
+
fallbackRender?: never;
|
|
14
16
|
}
|
|
15
17
|
declare function FallbackRender(props: FallbackProps): React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
|
|
16
18
|
interface ErrorBoundaryPropsWithRender {
|
|
@@ -20,6 +22,8 @@ interface ErrorBoundaryPropsWithRender {
|
|
|
20
22
|
componentStack: string;
|
|
21
23
|
}) => void;
|
|
22
24
|
resetKeys?: Array<unknown>;
|
|
25
|
+
fallback?: never;
|
|
26
|
+
FallbackComponent?: never;
|
|
23
27
|
fallbackRender: typeof FallbackRender;
|
|
24
28
|
}
|
|
25
29
|
interface ErrorBoundaryPropsWithFallback {
|
|
@@ -30,6 +34,8 @@ interface ErrorBoundaryPropsWithFallback {
|
|
|
30
34
|
}) => void;
|
|
31
35
|
resetKeys?: Array<unknown>;
|
|
32
36
|
fallback: React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
|
|
37
|
+
FallbackComponent?: never;
|
|
38
|
+
fallbackRender?: never;
|
|
33
39
|
}
|
|
34
40
|
declare type ErrorBoundaryProps = ErrorBoundaryPropsWithFallback | ErrorBoundaryPropsWithComponent | ErrorBoundaryPropsWithRender;
|
|
35
41
|
declare type ErrorBoundaryState = {
|
|
@@ -40,14 +46,13 @@ declare class ErrorBoundary extends React.Component<React.PropsWithRef<React.Pro
|
|
|
40
46
|
error: Error;
|
|
41
47
|
};
|
|
42
48
|
state: ErrorBoundaryState;
|
|
43
|
-
updatedWithError: boolean;
|
|
44
49
|
resetErrorBoundary: (...args: Array<unknown>) => void;
|
|
45
50
|
reset(): void;
|
|
46
51
|
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
47
|
-
componentDidUpdate(prevProps: ErrorBoundaryProps): void;
|
|
48
|
-
render():
|
|
52
|
+
componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState): void;
|
|
53
|
+
render(): React.ReactNode;
|
|
49
54
|
}
|
|
50
55
|
declare function withErrorBoundary<P>(Component: React.ComponentType<P>, errorBoundaryProps: ErrorBoundaryProps): React.ComponentType<P>;
|
|
51
|
-
declare function useErrorHandler
|
|
56
|
+
declare function useErrorHandler(givenError?: unknown): (error: unknown) => void;
|
|
52
57
|
export { ErrorBoundary, withErrorBoundary, useErrorHandler };
|
|
53
58
|
export type { FallbackProps, ErrorBoundaryPropsWithComponent, ErrorBoundaryPropsWithRender, ErrorBoundaryPropsWithFallback, ErrorBoundaryProps, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "../dist/index";
|
|
@@ -7,9 +7,28 @@ var React = require('react');
|
|
|
7
7
|
|
|
8
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
9
|
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n["default"] = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
10
28
|
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
|
|
29
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
11
30
|
|
|
12
|
-
var changedArray = function (a, b) {
|
|
31
|
+
var changedArray = function changedArray(a, b) {
|
|
13
32
|
if (a === void 0) {
|
|
14
33
|
a = [];
|
|
15
34
|
}
|
|
@@ -28,7 +47,7 @@ var initialState = {
|
|
|
28
47
|
};
|
|
29
48
|
|
|
30
49
|
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
31
|
-
_inheritsLoose__default[
|
|
50
|
+
_inheritsLoose__default["default"](ErrorBoundary, _React$Component);
|
|
32
51
|
|
|
33
52
|
function ErrorBoundary() {
|
|
34
53
|
var _this;
|
|
@@ -39,7 +58,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
39
58
|
|
|
40
59
|
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
|
41
60
|
_this.state = initialState;
|
|
42
|
-
_this.updatedWithError = false;
|
|
43
61
|
|
|
44
62
|
_this.resetErrorBoundary = function () {
|
|
45
63
|
var _this$props;
|
|
@@ -65,7 +83,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
65
83
|
var _proto = ErrorBoundary.prototype;
|
|
66
84
|
|
|
67
85
|
_proto.reset = function reset() {
|
|
68
|
-
this.updatedWithError = false;
|
|
69
86
|
this.setState(initialState);
|
|
70
87
|
};
|
|
71
88
|
|
|
@@ -75,7 +92,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
75
92
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
76
93
|
};
|
|
77
94
|
|
|
78
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
95
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
79
96
|
var error = this.state.error;
|
|
80
97
|
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
|
|
81
98
|
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
@@ -84,12 +101,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
84
101
|
// So we make sure that we don't check the resetKeys on the first call
|
|
85
102
|
// of cDU after the error is set
|
|
86
103
|
|
|
87
|
-
if (error !== null &&
|
|
88
|
-
this.updatedWithError = true;
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
104
|
+
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
93
105
|
var _this$props$onResetKe, _this$props3;
|
|
94
106
|
|
|
95
107
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -98,8 +110,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
98
110
|
};
|
|
99
111
|
|
|
100
112
|
_proto.render = function render() {
|
|
101
|
-
var error = this.state.error;
|
|
102
|
-
|
|
113
|
+
var error = this.state.error;
|
|
103
114
|
var _this$props4 = this.props,
|
|
104
115
|
fallbackRender = _this$props4.fallbackRender,
|
|
105
116
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
@@ -111,12 +122,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
111
122
|
resetErrorBoundary: this.resetErrorBoundary
|
|
112
123
|
};
|
|
113
124
|
|
|
114
|
-
if ( /*#__PURE__*/
|
|
125
|
+
if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
|
|
115
126
|
return fallback;
|
|
116
127
|
} else if (typeof fallbackRender === 'function') {
|
|
117
128
|
return fallbackRender(_props);
|
|
118
129
|
} else if (FallbackComponent) {
|
|
119
|
-
return /*#__PURE__*/
|
|
130
|
+
return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
|
|
120
131
|
} else {
|
|
121
132
|
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
122
133
|
}
|
|
@@ -126,11 +137,11 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
126
137
|
};
|
|
127
138
|
|
|
128
139
|
return ErrorBoundary;
|
|
129
|
-
}(
|
|
140
|
+
}(React__namespace.Component);
|
|
130
141
|
|
|
131
142
|
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
132
|
-
var Wrapped = function (props) {
|
|
133
|
-
return /*#__PURE__*/
|
|
143
|
+
var Wrapped = function Wrapped(props) {
|
|
144
|
+
return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props));
|
|
134
145
|
}; // Format for display in DevTools
|
|
135
146
|
|
|
136
147
|
|
|
@@ -140,16 +151,17 @@ function withErrorBoundary(Component, errorBoundaryProps) {
|
|
|
140
151
|
}
|
|
141
152
|
|
|
142
153
|
function useErrorHandler(givenError) {
|
|
143
|
-
var _React$useState =
|
|
154
|
+
var _React$useState = React__namespace.useState(null),
|
|
144
155
|
error = _React$useState[0],
|
|
145
156
|
setError = _React$useState[1];
|
|
146
157
|
|
|
147
|
-
if (givenError) throw givenError;
|
|
148
|
-
if (error) throw error;
|
|
158
|
+
if (givenError != null) throw givenError;
|
|
159
|
+
if (error != null) throw error;
|
|
149
160
|
return setError;
|
|
150
161
|
}
|
|
151
162
|
/*
|
|
152
163
|
eslint
|
|
164
|
+
@typescript-eslint/sort-type-union-intersection-members: "off",
|
|
153
165
|
@typescript-eslint/no-throw-literal: "off",
|
|
154
166
|
@typescript-eslint/prefer-nullish-coalescing: "off"
|
|
155
167
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "../dist/index";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
|
|
2
|
-
import
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
|
|
4
|
-
var changedArray = function (a, b) {
|
|
4
|
+
var changedArray = function changedArray(a, b) {
|
|
5
5
|
if (a === void 0) {
|
|
6
6
|
a = [];
|
|
7
7
|
}
|
|
@@ -31,7 +31,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
31
31
|
|
|
32
32
|
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
|
33
33
|
_this.state = initialState;
|
|
34
|
-
_this.updatedWithError = false;
|
|
35
34
|
|
|
36
35
|
_this.resetErrorBoundary = function () {
|
|
37
36
|
var _this$props;
|
|
@@ -57,7 +56,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
57
56
|
var _proto = ErrorBoundary.prototype;
|
|
58
57
|
|
|
59
58
|
_proto.reset = function reset() {
|
|
60
|
-
this.updatedWithError = false;
|
|
61
59
|
this.setState(initialState);
|
|
62
60
|
};
|
|
63
61
|
|
|
@@ -67,7 +65,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
67
65
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
68
66
|
};
|
|
69
67
|
|
|
70
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
68
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
71
69
|
var error = this.state.error;
|
|
72
70
|
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
|
|
73
71
|
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
@@ -76,12 +74,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
76
74
|
// So we make sure that we don't check the resetKeys on the first call
|
|
77
75
|
// of cDU after the error is set
|
|
78
76
|
|
|
79
|
-
if (error !== null &&
|
|
80
|
-
this.updatedWithError = true;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
77
|
+
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
85
78
|
var _this$props$onResetKe, _this$props3;
|
|
86
79
|
|
|
87
80
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -90,8 +83,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
90
83
|
};
|
|
91
84
|
|
|
92
85
|
_proto.render = function render() {
|
|
93
|
-
var error = this.state.error;
|
|
94
|
-
|
|
86
|
+
var error = this.state.error;
|
|
95
87
|
var _this$props4 = this.props,
|
|
96
88
|
fallbackRender = _this$props4.fallbackRender,
|
|
97
89
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
@@ -103,12 +95,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
103
95
|
resetErrorBoundary: this.resetErrorBoundary
|
|
104
96
|
};
|
|
105
97
|
|
|
106
|
-
if ( /*#__PURE__*/isValidElement(fallback)) {
|
|
98
|
+
if ( /*#__PURE__*/React.isValidElement(fallback)) {
|
|
107
99
|
return fallback;
|
|
108
100
|
} else if (typeof fallbackRender === 'function') {
|
|
109
101
|
return fallbackRender(_props);
|
|
110
102
|
} else if (FallbackComponent) {
|
|
111
|
-
return /*#__PURE__*/createElement(FallbackComponent, _props);
|
|
103
|
+
return /*#__PURE__*/React.createElement(FallbackComponent, _props);
|
|
112
104
|
} else {
|
|
113
105
|
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
114
106
|
}
|
|
@@ -118,11 +110,11 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
118
110
|
};
|
|
119
111
|
|
|
120
112
|
return ErrorBoundary;
|
|
121
|
-
}(Component);
|
|
113
|
+
}(React.Component);
|
|
122
114
|
|
|
123
115
|
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
124
|
-
var Wrapped = function (props) {
|
|
125
|
-
return /*#__PURE__*/createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/createElement(Component, props));
|
|
116
|
+
var Wrapped = function Wrapped(props) {
|
|
117
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props));
|
|
126
118
|
}; // Format for display in DevTools
|
|
127
119
|
|
|
128
120
|
|
|
@@ -132,16 +124,17 @@ function withErrorBoundary(Component, errorBoundaryProps) {
|
|
|
132
124
|
}
|
|
133
125
|
|
|
134
126
|
function useErrorHandler(givenError) {
|
|
135
|
-
var _React$useState = useState(null),
|
|
127
|
+
var _React$useState = React.useState(null),
|
|
136
128
|
error = _React$useState[0],
|
|
137
129
|
setError = _React$useState[1];
|
|
138
130
|
|
|
139
|
-
if (givenError) throw givenError;
|
|
140
|
-
if (error) throw error;
|
|
131
|
+
if (givenError != null) throw givenError;
|
|
132
|
+
if (error != null) throw error;
|
|
141
133
|
return setError;
|
|
142
134
|
}
|
|
143
135
|
/*
|
|
144
136
|
eslint
|
|
137
|
+
@typescript-eslint/sort-type-union-intersection-members: "off",
|
|
145
138
|
@typescript-eslint/no-throw-literal: "off",
|
|
146
139
|
@typescript-eslint/prefer-nullish-coalescing: "off"
|
|
147
140
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "../dist/index";
|
|
@@ -2,15 +2,44 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactErrorBoundary = {}, global.React));
|
|
5
|
-
}(this, (function (exports, React) { 'use strict';
|
|
5
|
+
})(this, (function (exports, React) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n["default"] = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
26
|
+
|
|
27
|
+
function _setPrototypeOf(o, p) {
|
|
28
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
29
|
+
o.__proto__ = p;
|
|
30
|
+
return o;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return _setPrototypeOf(o, p);
|
|
34
|
+
}
|
|
6
35
|
|
|
7
36
|
function _inheritsLoose(subClass, superClass) {
|
|
8
37
|
subClass.prototype = Object.create(superClass.prototype);
|
|
9
38
|
subClass.prototype.constructor = subClass;
|
|
10
|
-
subClass
|
|
39
|
+
_setPrototypeOf(subClass, superClass);
|
|
11
40
|
}
|
|
12
41
|
|
|
13
|
-
var changedArray = function (a, b) {
|
|
42
|
+
var changedArray = function changedArray(a, b) {
|
|
14
43
|
if (a === void 0) {
|
|
15
44
|
a = [];
|
|
16
45
|
}
|
|
@@ -40,7 +69,6 @@
|
|
|
40
69
|
|
|
41
70
|
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
|
42
71
|
_this.state = initialState;
|
|
43
|
-
_this.updatedWithError = false;
|
|
44
72
|
|
|
45
73
|
_this.resetErrorBoundary = function () {
|
|
46
74
|
var _this$props;
|
|
@@ -66,7 +94,6 @@
|
|
|
66
94
|
var _proto = ErrorBoundary.prototype;
|
|
67
95
|
|
|
68
96
|
_proto.reset = function reset() {
|
|
69
|
-
this.updatedWithError = false;
|
|
70
97
|
this.setState(initialState);
|
|
71
98
|
};
|
|
72
99
|
|
|
@@ -76,7 +103,7 @@
|
|
|
76
103
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
77
104
|
};
|
|
78
105
|
|
|
79
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
106
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
80
107
|
var error = this.state.error;
|
|
81
108
|
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
|
|
82
109
|
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
@@ -85,12 +112,7 @@
|
|
|
85
112
|
// So we make sure that we don't check the resetKeys on the first call
|
|
86
113
|
// of cDU after the error is set
|
|
87
114
|
|
|
88
|
-
if (error !== null &&
|
|
89
|
-
this.updatedWithError = true;
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
115
|
+
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
94
116
|
var _this$props$onResetKe, _this$props3;
|
|
95
117
|
|
|
96
118
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -99,8 +121,7 @@
|
|
|
99
121
|
};
|
|
100
122
|
|
|
101
123
|
_proto.render = function render() {
|
|
102
|
-
var error = this.state.error;
|
|
103
|
-
|
|
124
|
+
var error = this.state.error;
|
|
104
125
|
var _this$props4 = this.props,
|
|
105
126
|
fallbackRender = _this$props4.fallbackRender,
|
|
106
127
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
@@ -112,12 +133,12 @@
|
|
|
112
133
|
resetErrorBoundary: this.resetErrorBoundary
|
|
113
134
|
};
|
|
114
135
|
|
|
115
|
-
if ( /*#__PURE__*/
|
|
136
|
+
if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
|
|
116
137
|
return fallback;
|
|
117
138
|
} else if (typeof fallbackRender === 'function') {
|
|
118
139
|
return fallbackRender(_props);
|
|
119
140
|
} else if (FallbackComponent) {
|
|
120
|
-
return /*#__PURE__*/
|
|
141
|
+
return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
|
|
121
142
|
} else {
|
|
122
143
|
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
123
144
|
}
|
|
@@ -127,11 +148,11 @@
|
|
|
127
148
|
};
|
|
128
149
|
|
|
129
150
|
return ErrorBoundary;
|
|
130
|
-
}(
|
|
151
|
+
}(React__namespace.Component);
|
|
131
152
|
|
|
132
153
|
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
133
|
-
var Wrapped = function (props) {
|
|
134
|
-
return /*#__PURE__*/
|
|
154
|
+
var Wrapped = function Wrapped(props) {
|
|
155
|
+
return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props));
|
|
135
156
|
}; // Format for display in DevTools
|
|
136
157
|
|
|
137
158
|
|
|
@@ -141,16 +162,17 @@
|
|
|
141
162
|
}
|
|
142
163
|
|
|
143
164
|
function useErrorHandler(givenError) {
|
|
144
|
-
var _React$useState =
|
|
165
|
+
var _React$useState = React__namespace.useState(null),
|
|
145
166
|
error = _React$useState[0],
|
|
146
167
|
setError = _React$useState[1];
|
|
147
168
|
|
|
148
|
-
if (givenError) throw givenError;
|
|
149
|
-
if (error) throw error;
|
|
169
|
+
if (givenError != null) throw givenError;
|
|
170
|
+
if (error != null) throw error;
|
|
150
171
|
return setError;
|
|
151
172
|
}
|
|
152
173
|
/*
|
|
153
174
|
eslint
|
|
175
|
+
@typescript-eslint/sort-type-union-intersection-members: "off",
|
|
154
176
|
@typescript-eslint/no-throw-literal: "off",
|
|
155
177
|
@typescript-eslint/prefer-nullish-coalescing: "off"
|
|
156
178
|
*/
|
|
@@ -161,5 +183,5 @@
|
|
|
161
183
|
|
|
162
184
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
163
185
|
|
|
164
|
-
}))
|
|
186
|
+
}));
|
|
165
187
|
//# sourceMappingURL=react-error-boundary.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-error-boundary.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","../src/index.tsx"],"sourcesContent":["export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass
|
|
1
|
+
{"version":3,"file":"react-error-boundary.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js","../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","../src/index.tsx"],"sourcesContent":["export default function _setPrototypeOf(o, p) {\n _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}","import setPrototypeOf from \"./setPrototypeOf.js\";\nexport default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n setPrototypeOf(subClass, superClass);\n}","import * as React from 'react'\n\nconst changedArray = (a: Array<unknown> = [], b: Array<unknown> = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\ninterface FallbackProps {\n error: Error\n resetErrorBoundary: (...args: Array<unknown>) => void\n}\n\ninterface ErrorBoundaryPropsWithComponent {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n fallback?: never\n FallbackComponent: React.ComponentType<FallbackProps>\n fallbackRender?: never\n}\n\ndeclare function FallbackRender(\n props: FallbackProps,\n): React.ReactElement<\n unknown,\n string | React.FunctionComponent | typeof React.Component\n> | null\n\ninterface ErrorBoundaryPropsWithRender {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n fallback?: never\n FallbackComponent?: never\n fallbackRender: typeof FallbackRender\n}\n\ninterface ErrorBoundaryPropsWithFallback {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n fallback: React.ReactElement<\n unknown,\n string | React.FunctionComponent | typeof React.Component\n > | null\n FallbackComponent?: never\n fallbackRender?: never\n}\n\ntype ErrorBoundaryProps =\n | ErrorBoundaryPropsWithFallback\n | ErrorBoundaryPropsWithComponent\n | ErrorBoundaryPropsWithRender\n\ntype ErrorBoundaryState = {error: Error | null}\n\nconst initialState: ErrorBoundaryState = {error: null}\n\nclass ErrorBoundary extends React.Component<\n React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>,\n ErrorBoundaryState\n> {\n static getDerivedStateFromError(error: Error) {\n return {error}\n }\n\n state = initialState\n resetErrorBoundary = (...args: Array<unknown>) => {\n this.props.onReset?.(...args)\n this.reset()\n }\n\n reset() {\n this.setState(initialState)\n }\n\n componentDidCatch(error: Error, info: React.ErrorInfo) {\n this.props.onError?.(error, info)\n }\n\n componentDidUpdate(\n prevProps: ErrorBoundaryProps,\n prevState: ErrorBoundaryState,\n ) {\n const {error} = this.state\n const {resetKeys} = this.props\n\n // There's an edge case where if the thing that triggered the error\n // happens to *also* be in the resetKeys array, we'd end up resetting\n // the error boundary immediately. This would likely trigger a second\n // error to be thrown.\n // So we make sure that we don't check the resetKeys on the first call\n // of cDU after the error is set\n\n if (\n error !== null &&\n prevState.error !== null &&\n changedArray(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onResetKeysChange?.(prevProps.resetKeys, resetKeys)\n this.reset()\n }\n }\n\n render() {\n const {error} = this.state\n\n const {fallbackRender, FallbackComponent, fallback} = this.props\n\n if (error !== null) {\n const props = {\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n }\n if (React.isValidElement(fallback)) {\n return fallback\n } else if (typeof fallbackRender === 'function') {\n return fallbackRender(props)\n } else if (FallbackComponent) {\n return <FallbackComponent {...props} />\n } else {\n throw new Error(\n 'react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop',\n )\n }\n }\n\n return this.props.children\n }\n}\n\nfunction withErrorBoundary<P>(\n Component: React.ComponentType<P>,\n errorBoundaryProps: ErrorBoundaryProps,\n): React.ComponentType<P> {\n const Wrapped: React.ComponentType<P> = props => {\n return (\n <ErrorBoundary {...errorBoundaryProps}>\n <Component {...props} />\n </ErrorBoundary>\n )\n }\n\n // Format for display in DevTools\n const name = Component.displayName || Component.name || 'Unknown'\n Wrapped.displayName = `withErrorBoundary(${name})`\n\n return Wrapped\n}\n\nfunction useErrorHandler(givenError?: unknown): (error: unknown) => void {\n const [error, setError] = React.useState<unknown>(null)\n if (givenError != null) throw givenError\n if (error != null) throw error\n return setError\n}\n\nexport {ErrorBoundary, withErrorBoundary, useErrorHandler}\nexport type {\n FallbackProps,\n ErrorBoundaryPropsWithComponent,\n ErrorBoundaryPropsWithRender,\n ErrorBoundaryPropsWithFallback,\n ErrorBoundaryProps,\n}\n\n/*\neslint\n @typescript-eslint/sort-type-union-intersection-members: \"off\",\n @typescript-eslint/no-throw-literal: \"off\",\n @typescript-eslint/prefer-nullish-coalescing: \"off\"\n*/\n"],"names":["_setPrototypeOf","o","p","Object","setPrototypeOf","__proto__","_inheritsLoose","subClass","superClass","prototype","create","constructor","changedArray","a","b","length","some","item","index","is","initialState","error","ErrorBoundary","state","resetErrorBoundary","args","props","onReset","reset","getDerivedStateFromError","setState","componentDidCatch","info","onError","componentDidUpdate","prevProps","prevState","resetKeys","onResetKeysChange","render","fallbackRender","FallbackComponent","fallback","React","isValidElement","Error","children","Component","withErrorBoundary","errorBoundaryProps","Wrapped","name","displayName","useErrorHandler","givenError","useState","setError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EAAe,SAASA,eAAT,CAAyBC,CAAzB,EAA4BC,CAA5B,EAA+B;EAC5CF,EAAAA,eAAe,GAAGG,MAAM,CAACC,cAAP,IAAyB,SAASJ,eAAT,CAAyBC,CAAzB,EAA4BC,CAA5B,EAA+B;EACxED,IAAAA,CAAC,CAACI,SAAF,GAAcH,CAAd;EACA,WAAOD,CAAP;EACD,GAHD;;EAKA,SAAOD,eAAe,CAACC,CAAD,EAAIC,CAAJ,CAAtB;EACD;;ECNc,SAASI,cAAT,CAAwBC,QAAxB,EAAkCC,UAAlC,EAA8C;EAC3DD,EAAAA,QAAQ,CAACE,SAAT,GAAqBN,MAAM,CAACO,MAAP,CAAcF,UAAU,CAACC,SAAzB,CAArB;EACAF,EAAAA,QAAQ,CAACE,SAAT,CAAmBE,WAAnB,GAAiCJ,QAAjC;EACAH,EAAAA,eAAc,CAACG,QAAD,EAAWC,UAAX,CAAd;EACD;;ECHD,IAAMI,YAAY,GAAG,SAAfA,YAAe,CAACC,CAAD,EAAyBC,CAAzB;EAAA,MAACD,CAAD;EAACA,IAAAA,CAAD,GAAqB,EAArB;EAAA;;EAAA,MAAyBC,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,SAASG,eAAT,CAAyBC,UAAzB,EAAyE;EACvE,wBAA0BX,gBAAK,CAACY,QAAN,CAAwB,IAAxB,CAA1B;EAAA,MAAOlC,KAAP;EAAA,MAAcmC,QAAd;;EACA,MAAIF,UAAU,IAAI,IAAlB,EAAwB,MAAMA,UAAN;EACxB,MAAIjC,KAAK,IAAI,IAAb,EAAmB,MAAMA,KAAN;EACnB,SAAOmC,QAAP;EACD;EAWD;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "../dist/index";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(r
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).ReactErrorBoundary={},e.React)}(this,(function(e,r){"use strict";function t(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var n=t(r);function o(e,r){return o=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},o(e,r)}var a={error:null},u=function(e){var r,t;function u(){for(var r,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return(r=e.call.apply(e,[this].concat(n))||this).state=a,r.resetErrorBoundary=function(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];null==r.props.onReset||(e=r.props).onReset.apply(e,n),r.reset()},r}t=e,(r=u).prototype=Object.create(t.prototype),r.prototype.constructor=r,o(r,t),u.getDerivedStateFromError=function(e){return{error:e}};var i=u.prototype;return i.reset=function(){this.setState(a)},i.componentDidCatch=function(e,r){var t,n;null==(t=(n=this.props).onError)||t.call(n,e,r)},i.componentDidUpdate=function(e,r){var t,n,o,a,u=this.state.error,i=this.props.resetKeys;null!==u&&null!==r.error&&(void 0===(o=e.resetKeys)&&(o=[]),void 0===(a=i)&&(a=[]),o.length!==a.length||o.some((function(e,r){return!Object.is(e,a[r])})))&&(null==(t=(n=this.props).onResetKeysChange)||t.call(n,e.resetKeys,i),this.reset())},i.render=function(){var e=this.state.error,r=this.props,t=r.fallbackRender,o=r.FallbackComponent,a=r.fallback;if(null!==e){var u={error:e,resetErrorBoundary:this.resetErrorBoundary};if(n.isValidElement(a))return a;if("function"==typeof t)return t(u);if(o)return n.createElement(o,u);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},u}(n.Component);e.ErrorBoundary=u,e.useErrorHandler=function(e){var r=n.useState(null),t=r[0],o=r[1];if(null!=e)throw e;if(null!=t)throw t;return o},e.withErrorBoundary=function(e,r){var t=function(t){return n.createElement(u,r,n.createElement(e,t))},o=e.displayName||e.name||"Unknown";return t.displayName="withErrorBoundary("+o+")",t},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=react-error-boundary.umd.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-error-boundary.umd.min.js","sources":["../src/index.tsx","../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"],"sourcesContent":["import * as React from 'react'\n\nconst changedArray = (a: Array<unknown> = [], b: Array<unknown> = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\ninterface FallbackProps {\n error: Error\n resetErrorBoundary: (...args: Array<unknown>) => void\n}\n\ninterface ErrorBoundaryPropsWithComponent {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n FallbackComponent: React.ComponentType<FallbackProps>\n}\n\ndeclare function FallbackRender(\n props: FallbackProps,\n): React.ReactElement<\n unknown,\n string | React.FunctionComponent | typeof React.Component\n> | null\n\ninterface ErrorBoundaryPropsWithRender {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n fallbackRender: typeof FallbackRender\n}\n\ninterface ErrorBoundaryPropsWithFallback {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n fallback: React.ReactElement<\n unknown,\n string | React.FunctionComponent | typeof React.Component\n > | null\n}\n\ntype ErrorBoundaryProps =\n | ErrorBoundaryPropsWithFallback\n | ErrorBoundaryPropsWithComponent\n | ErrorBoundaryPropsWithRender\n\ntype ErrorBoundaryState = {error: Error | null}\n\nconst initialState: ErrorBoundaryState = {error: null}\n\nclass ErrorBoundary extends React.Component<\n React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>,\n ErrorBoundaryState\n> {\n static getDerivedStateFromError(error: Error) {\n return {error}\n }\n\n state = initialState\n
|
|
1
|
+
{"version":3,"file":"react-error-boundary.umd.min.js","sources":["../node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js","../src/index.tsx","../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"],"sourcesContent":["export default function _setPrototypeOf(o, p) {\n _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}","import * as React from 'react'\n\nconst changedArray = (a: Array<unknown> = [], b: Array<unknown> = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\ninterface FallbackProps {\n error: Error\n resetErrorBoundary: (...args: Array<unknown>) => void\n}\n\ninterface ErrorBoundaryPropsWithComponent {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n fallback?: never\n FallbackComponent: React.ComponentType<FallbackProps>\n fallbackRender?: never\n}\n\ndeclare function FallbackRender(\n props: FallbackProps,\n): React.ReactElement<\n unknown,\n string | React.FunctionComponent | typeof React.Component\n> | null\n\ninterface ErrorBoundaryPropsWithRender {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n fallback?: never\n FallbackComponent?: never\n fallbackRender: typeof FallbackRender\n}\n\ninterface ErrorBoundaryPropsWithFallback {\n onResetKeysChange?: (\n prevResetKeys: Array<unknown> | undefined,\n resetKeys: Array<unknown> | undefined,\n ) => void\n onReset?: (...args: Array<unknown>) => void\n onError?: (error: Error, info: {componentStack: string}) => void\n resetKeys?: Array<unknown>\n fallback: React.ReactElement<\n unknown,\n string | React.FunctionComponent | typeof React.Component\n > | null\n FallbackComponent?: never\n fallbackRender?: never\n}\n\ntype ErrorBoundaryProps =\n | ErrorBoundaryPropsWithFallback\n | ErrorBoundaryPropsWithComponent\n | ErrorBoundaryPropsWithRender\n\ntype ErrorBoundaryState = {error: Error | null}\n\nconst initialState: ErrorBoundaryState = {error: null}\n\nclass ErrorBoundary extends React.Component<\n React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>,\n ErrorBoundaryState\n> {\n static getDerivedStateFromError(error: Error) {\n return {error}\n }\n\n state = initialState\n resetErrorBoundary = (...args: Array<unknown>) => {\n this.props.onReset?.(...args)\n this.reset()\n }\n\n reset() {\n this.setState(initialState)\n }\n\n componentDidCatch(error: Error, info: React.ErrorInfo) {\n this.props.onError?.(error, info)\n }\n\n componentDidUpdate(\n prevProps: ErrorBoundaryProps,\n prevState: ErrorBoundaryState,\n ) {\n const {error} = this.state\n const {resetKeys} = this.props\n\n // There's an edge case where if the thing that triggered the error\n // happens to *also* be in the resetKeys array, we'd end up resetting\n // the error boundary immediately. This would likely trigger a second\n // error to be thrown.\n // So we make sure that we don't check the resetKeys on the first call\n // of cDU after the error is set\n\n if (\n error !== null &&\n prevState.error !== null &&\n changedArray(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onResetKeysChange?.(prevProps.resetKeys, resetKeys)\n this.reset()\n }\n }\n\n render() {\n const {error} = this.state\n\n const {fallbackRender, FallbackComponent, fallback} = this.props\n\n if (error !== null) {\n const props = {\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n }\n if (React.isValidElement(fallback)) {\n return fallback\n } else if (typeof fallbackRender === 'function') {\n return fallbackRender(props)\n } else if (FallbackComponent) {\n return <FallbackComponent {...props} />\n } else {\n throw new Error(\n 'react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop',\n )\n }\n }\n\n return this.props.children\n }\n}\n\nfunction withErrorBoundary<P>(\n Component: React.ComponentType<P>,\n errorBoundaryProps: ErrorBoundaryProps,\n): React.ComponentType<P> {\n const Wrapped: React.ComponentType<P> = props => {\n return (\n <ErrorBoundary {...errorBoundaryProps}>\n <Component {...props} />\n </ErrorBoundary>\n )\n }\n\n // Format for display in DevTools\n const name = Component.displayName || Component.name || 'Unknown'\n Wrapped.displayName = `withErrorBoundary(${name})`\n\n return Wrapped\n}\n\nfunction useErrorHandler(givenError?: unknown): (error: unknown) => void {\n const [error, setError] = React.useState<unknown>(null)\n if (givenError != null) throw givenError\n if (error != null) throw error\n return setError\n}\n\nexport {ErrorBoundary, withErrorBoundary, useErrorHandler}\nexport type {\n FallbackProps,\n ErrorBoundaryPropsWithComponent,\n ErrorBoundaryPropsWithRender,\n ErrorBoundaryPropsWithFallback,\n ErrorBoundaryProps,\n}\n\n/*\neslint\n @typescript-eslint/sort-type-union-intersection-members: \"off\",\n @typescript-eslint/no-throw-literal: \"off\",\n @typescript-eslint/prefer-nullish-coalescing: \"off\"\n*/\n","import setPrototypeOf from \"./setPrototypeOf.js\";\nexport default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n setPrototypeOf(subClass, superClass);\n}"],"names":["_setPrototypeOf","o","p","Object","setPrototypeOf","__proto__","initialState","error","ErrorBoundary","subClass","superClass","state","resetErrorBoundary","args","props","onReset","reset","prototype","create","constructor","getDerivedStateFromError","setState","componentDidCatch","info","onError","componentDidUpdate","prevProps","prevState","a","b","this","resetKeys","length","some","item","index","is","onResetKeysChange","render","fallbackRender","FallbackComponent","fallback","React","isValidElement","Error","children","Component","givenError","useState","setError","errorBoundaryProps","Wrapped","name","displayName"],"mappings":"ukBAAe,SAASA,EAAgBC,EAAGC,UACzCF,EAAkBG,OAAOC,gBAAkB,SAAyBH,EAAGC,UACrED,EAAEI,UAAYH,EACPD,GAGFD,EAAgBC,EAAGC,GCJ5B,IAgEMI,EAAmC,CAACC,MAAO,MAE3CC,cCnES,IAAwBC,EAAUC,0ID2E/CC,MAAQL,IACRM,mBAAqB,wCAAIC,2BAAAA,0BAClBC,MAAMC,cAAND,OAAMC,gBAAaF,KACnBG,WC9EwCN,KAAVD,KAC5BQ,UAAYd,OAAOe,OAAOR,EAAWO,WAC9CR,EAASQ,UAAUE,YAAcV,EACjCL,EAAeK,EAAUC,KDoElBU,yBAAP,SAAgCb,SACvB,CAACA,MAAAA,+BASVS,MAAA,gBACOK,SAASf,MAGhBgB,kBAAA,SAAkBf,EAAcgB,4BACzBT,OAAMU,mBAAUjB,EAAOgB,MAG9BE,mBAAA,SACEC,EACAC,WA1FkBC,EAAwBC,EA4FnCtB,EAASuB,KAAKnB,MAAdJ,MACAwB,EAAaD,KAAKhB,MAAlBiB,UAUK,OAAVxB,GACoB,OAApBoB,EAAUpB,kBAxGMqB,EAyGHF,EAAUK,aAzGPH,EAAoB,cAAIC,EAyGNE,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