react-error-boundary 2.3.1 → 2.3.2
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 +3 -5
- package/dist/react-error-boundary.cjs.js +33 -15
- package/dist/react-error-boundary.esm.js +21 -6
- package/dist/react-error-boundary.umd.js +30 -13
- package/dist/react-error-boundary.umd.js.map +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 +9 -8
package/README.md
CHANGED
|
@@ -339,7 +339,7 @@ function Greeting() {
|
|
|
339
339
|
<form onSubmit={handleSubmit}>
|
|
340
340
|
<label>Name</label>
|
|
341
341
|
<input id="name" />
|
|
342
|
-
<button type="submit"
|
|
342
|
+
<button type="submit"}>
|
|
343
343
|
get a greeting
|
|
344
344
|
</button>
|
|
345
345
|
</form>
|
|
@@ -348,7 +348,7 @@ function Greeting() {
|
|
|
348
348
|
```
|
|
349
349
|
|
|
350
350
|
> Note, in case it's not clear what's happening here, you could also write
|
|
351
|
-
> `
|
|
351
|
+
> `handleSubmit` like this:
|
|
352
352
|
|
|
353
353
|
```javascript
|
|
354
354
|
function handleSubmit(event) {
|
|
@@ -381,9 +381,7 @@ function Greeting() {
|
|
|
381
381
|
<form onSubmit={handleSubmit}>
|
|
382
382
|
<label>Name</label>
|
|
383
383
|
<input id="name" />
|
|
384
|
-
<button type="submit"
|
|
385
|
-
get a greeting
|
|
386
|
-
</button>
|
|
384
|
+
<button type="submit">get a greeting</button>
|
|
387
385
|
</form>
|
|
388
386
|
)
|
|
389
387
|
}
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
|
|
6
|
+
var React = require('react');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
9
12
|
|
|
10
13
|
var changedArray = function (a, b) {
|
|
11
14
|
if (a === void 0) {
|
|
@@ -27,7 +30,7 @@ var initialState = {
|
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
30
|
-
|
|
33
|
+
_inheritsLoose__default['default'](ErrorBoundary, _React$Component);
|
|
31
34
|
|
|
32
35
|
function ErrorBoundary() {
|
|
33
36
|
var _this;
|
|
@@ -54,6 +57,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
54
57
|
return _this;
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
|
|
61
|
+
return {
|
|
62
|
+
error: error
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
57
66
|
var _proto = ErrorBoundary.prototype;
|
|
58
67
|
|
|
59
68
|
_proto.componentDidCatch = function componentDidCatch(error, info) {
|
|
@@ -61,16 +70,17 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
61
70
|
|
|
62
71
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info == null ? void 0 : info.componentStack);
|
|
63
72
|
this.setState({
|
|
64
|
-
error: error,
|
|
65
73
|
info: info
|
|
66
74
|
});
|
|
67
75
|
};
|
|
68
76
|
|
|
69
77
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
70
|
-
var
|
|
78
|
+
var _this$state = this.state,
|
|
79
|
+
error = _this$state.error,
|
|
80
|
+
info = _this$state.info;
|
|
71
81
|
var resetKeys = this.props.resetKeys;
|
|
72
82
|
|
|
73
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
83
|
+
if (error !== null && info !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
74
84
|
var _this$props$onResetKe, _this$props3;
|
|
75
85
|
|
|
76
86
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -79,27 +89,35 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
79
89
|
};
|
|
80
90
|
|
|
81
91
|
_proto.render = function render() {
|
|
82
|
-
var _this$
|
|
83
|
-
error = _this$
|
|
84
|
-
info = _this$
|
|
92
|
+
var _this$state2 = this.state,
|
|
93
|
+
error = _this$state2.error,
|
|
94
|
+
info = _this$state2.info;
|
|
85
95
|
var _this$props4 = this.props,
|
|
86
96
|
fallbackRender = _this$props4.fallbackRender,
|
|
87
97
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
88
98
|
fallback = _this$props4.fallback;
|
|
89
99
|
|
|
90
100
|
if (error !== null) {
|
|
101
|
+
// we'll get a re-render with the error state in getDerivedStateFromError
|
|
102
|
+
// but we don't have the info yet, so just render null
|
|
103
|
+
// note that this won't be committed to the DOM thanks to our componentDidCatch
|
|
104
|
+
// so the user won't see a flash of nothing, so this works fine.
|
|
105
|
+
// the benefit of doing things this way rather than just putting both the
|
|
106
|
+
// error and info setState within componentDidCatch is we avoid re-rendering
|
|
107
|
+
// busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66
|
|
108
|
+
if (!info) return null;
|
|
91
109
|
var props = {
|
|
92
110
|
componentStack: info == null ? void 0 : info.componentStack,
|
|
93
111
|
error: error,
|
|
94
112
|
resetErrorBoundary: this.resetErrorBoundary
|
|
95
113
|
};
|
|
96
114
|
|
|
97
|
-
if ( /*#__PURE__*/
|
|
115
|
+
if ( /*#__PURE__*/React__default['default'].isValidElement(fallback)) {
|
|
98
116
|
return fallback;
|
|
99
117
|
} else if (typeof fallbackRender === 'function') {
|
|
100
118
|
return fallbackRender(props);
|
|
101
119
|
} else if (FallbackComponent) {
|
|
102
|
-
return /*#__PURE__*/
|
|
120
|
+
return /*#__PURE__*/React__default['default'].createElement(FallbackComponent, props);
|
|
103
121
|
} else {
|
|
104
122
|
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
105
123
|
}
|
|
@@ -109,11 +127,11 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
109
127
|
};
|
|
110
128
|
|
|
111
129
|
return ErrorBoundary;
|
|
112
|
-
}(
|
|
130
|
+
}(React__default['default'].Component);
|
|
113
131
|
|
|
114
132
|
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
115
133
|
function Wrapped(props) {
|
|
116
|
-
return /*#__PURE__*/
|
|
134
|
+
return /*#__PURE__*/React__default['default'].createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__default['default'].createElement(Component, props));
|
|
117
135
|
} // Format for display in DevTools
|
|
118
136
|
|
|
119
137
|
|
|
@@ -123,7 +141,7 @@ function withErrorBoundary(Component, errorBoundaryProps) {
|
|
|
123
141
|
}
|
|
124
142
|
|
|
125
143
|
function useErrorHandler(givenError) {
|
|
126
|
-
var _React$useState =
|
|
144
|
+
var _React$useState = React__default['default'].useState(null),
|
|
127
145
|
error = _React$useState[0],
|
|
128
146
|
setError = _React$useState[1];
|
|
129
147
|
|
|
@@ -48,6 +48,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
48
48
|
return _this;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
|
|
52
|
+
return {
|
|
53
|
+
error: error
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
51
57
|
var _proto = ErrorBoundary.prototype;
|
|
52
58
|
|
|
53
59
|
_proto.componentDidCatch = function componentDidCatch(error, info) {
|
|
@@ -55,16 +61,17 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
55
61
|
|
|
56
62
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info == null ? void 0 : info.componentStack);
|
|
57
63
|
this.setState({
|
|
58
|
-
error: error,
|
|
59
64
|
info: info
|
|
60
65
|
});
|
|
61
66
|
};
|
|
62
67
|
|
|
63
68
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
64
|
-
var
|
|
69
|
+
var _this$state = this.state,
|
|
70
|
+
error = _this$state.error,
|
|
71
|
+
info = _this$state.info;
|
|
65
72
|
var resetKeys = this.props.resetKeys;
|
|
66
73
|
|
|
67
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
74
|
+
if (error !== null && info !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
68
75
|
var _this$props$onResetKe, _this$props3;
|
|
69
76
|
|
|
70
77
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -73,15 +80,23 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
73
80
|
};
|
|
74
81
|
|
|
75
82
|
_proto.render = function render() {
|
|
76
|
-
var _this$
|
|
77
|
-
error = _this$
|
|
78
|
-
info = _this$
|
|
83
|
+
var _this$state2 = this.state,
|
|
84
|
+
error = _this$state2.error,
|
|
85
|
+
info = _this$state2.info;
|
|
79
86
|
var _this$props4 = this.props,
|
|
80
87
|
fallbackRender = _this$props4.fallbackRender,
|
|
81
88
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
82
89
|
fallback = _this$props4.fallback;
|
|
83
90
|
|
|
84
91
|
if (error !== null) {
|
|
92
|
+
// we'll get a re-render with the error state in getDerivedStateFromError
|
|
93
|
+
// but we don't have the info yet, so just render null
|
|
94
|
+
// note that this won't be committed to the DOM thanks to our componentDidCatch
|
|
95
|
+
// so the user won't see a flash of nothing, so this works fine.
|
|
96
|
+
// the benefit of doing things this way rather than just putting both the
|
|
97
|
+
// error and info setState within componentDidCatch is we avoid re-rendering
|
|
98
|
+
// busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66
|
|
99
|
+
if (!info) return null;
|
|
85
100
|
var props = {
|
|
86
101
|
componentStack: info == null ? void 0 : info.componentStack,
|
|
87
102
|
error: error,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
|
|
4
|
-
(global = global || self, factory(global.ReactErrorBoundary = {}, global.React));
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactErrorBoundary = {}, global.React));
|
|
5
5
|
}(this, (function (exports, React) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
8
10
|
|
|
9
11
|
function _inheritsLoose(subClass, superClass) {
|
|
10
12
|
subClass.prototype = Object.create(superClass.prototype);
|
|
@@ -59,6 +61,12 @@
|
|
|
59
61
|
return _this;
|
|
60
62
|
}
|
|
61
63
|
|
|
64
|
+
ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
|
|
65
|
+
return {
|
|
66
|
+
error: error
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
62
70
|
var _proto = ErrorBoundary.prototype;
|
|
63
71
|
|
|
64
72
|
_proto.componentDidCatch = function componentDidCatch(error, info) {
|
|
@@ -66,16 +74,17 @@
|
|
|
66
74
|
|
|
67
75
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info == null ? void 0 : info.componentStack);
|
|
68
76
|
this.setState({
|
|
69
|
-
error: error,
|
|
70
77
|
info: info
|
|
71
78
|
});
|
|
72
79
|
};
|
|
73
80
|
|
|
74
81
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
75
|
-
var
|
|
82
|
+
var _this$state = this.state,
|
|
83
|
+
error = _this$state.error,
|
|
84
|
+
info = _this$state.info;
|
|
76
85
|
var resetKeys = this.props.resetKeys;
|
|
77
86
|
|
|
78
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
87
|
+
if (error !== null && info !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
79
88
|
var _this$props$onResetKe, _this$props3;
|
|
80
89
|
|
|
81
90
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -84,27 +93,35 @@
|
|
|
84
93
|
};
|
|
85
94
|
|
|
86
95
|
_proto.render = function render() {
|
|
87
|
-
var _this$
|
|
88
|
-
error = _this$
|
|
89
|
-
info = _this$
|
|
96
|
+
var _this$state2 = this.state,
|
|
97
|
+
error = _this$state2.error,
|
|
98
|
+
info = _this$state2.info;
|
|
90
99
|
var _this$props4 = this.props,
|
|
91
100
|
fallbackRender = _this$props4.fallbackRender,
|
|
92
101
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
93
102
|
fallback = _this$props4.fallback;
|
|
94
103
|
|
|
95
104
|
if (error !== null) {
|
|
105
|
+
// we'll get a re-render with the error state in getDerivedStateFromError
|
|
106
|
+
// but we don't have the info yet, so just render null
|
|
107
|
+
// note that this won't be committed to the DOM thanks to our componentDidCatch
|
|
108
|
+
// so the user won't see a flash of nothing, so this works fine.
|
|
109
|
+
// the benefit of doing things this way rather than just putting both the
|
|
110
|
+
// error and info setState within componentDidCatch is we avoid re-rendering
|
|
111
|
+
// busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66
|
|
112
|
+
if (!info) return null;
|
|
96
113
|
var props = {
|
|
97
114
|
componentStack: info == null ? void 0 : info.componentStack,
|
|
98
115
|
error: error,
|
|
99
116
|
resetErrorBoundary: this.resetErrorBoundary
|
|
100
117
|
};
|
|
101
118
|
|
|
102
|
-
if ( /*#__PURE__*/
|
|
119
|
+
if ( /*#__PURE__*/React__default['default'].isValidElement(fallback)) {
|
|
103
120
|
return fallback;
|
|
104
121
|
} else if (typeof fallbackRender === 'function') {
|
|
105
122
|
return fallbackRender(props);
|
|
106
123
|
} else if (FallbackComponent) {
|
|
107
|
-
return /*#__PURE__*/
|
|
124
|
+
return /*#__PURE__*/React__default['default'].createElement(FallbackComponent, props);
|
|
108
125
|
} else {
|
|
109
126
|
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
110
127
|
}
|
|
@@ -114,11 +131,11 @@
|
|
|
114
131
|
};
|
|
115
132
|
|
|
116
133
|
return ErrorBoundary;
|
|
117
|
-
}(
|
|
134
|
+
}(React__default['default'].Component);
|
|
118
135
|
|
|
119
136
|
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
120
137
|
function Wrapped(props) {
|
|
121
|
-
return /*#__PURE__*/
|
|
138
|
+
return /*#__PURE__*/React__default['default'].createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__default['default'].createElement(Component, props));
|
|
122
139
|
} // Format for display in DevTools
|
|
123
140
|
|
|
124
141
|
|
|
@@ -128,7 +145,7 @@
|
|
|
128
145
|
}
|
|
129
146
|
|
|
130
147
|
function useErrorHandler(givenError) {
|
|
131
|
-
var _React$useState =
|
|
148
|
+
var _React$useState = React__default['default'].useState(null),
|
|
132
149
|
error = _React$useState[0],
|
|
133
150
|
setError = _React$useState[1];
|
|
134
151
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-error-boundary.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","../src/index.js"],"sourcesContent":["export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null, info: null}\nclass ErrorBoundary extends React.Component {\n state = initialState\n resetErrorBoundary = (...args) => {\n this.props.onReset?.(...args)\n this.setState(initialState)\n }\n\n componentDidCatch(error, info) {\n this.props.onError?.(error, info?.componentStack)\n this.setState({
|
|
1
|
+
{"version":3,"file":"react-error-boundary.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","../src/index.js"],"sourcesContent":["export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null, info: null}\nclass ErrorBoundary extends React.Component {\n static getDerivedStateFromError(error) {\n return {error}\n }\n\n state = initialState\n resetErrorBoundary = (...args) => {\n this.props.onReset?.(...args)\n this.setState(initialState)\n }\n\n componentDidCatch(error, info) {\n this.props.onError?.(error, info?.componentStack)\n this.setState({info})\n }\n\n componentDidUpdate(prevProps) {\n const {error, info} = this.state\n const {resetKeys} = this.props\n if (\n error !== null &&\n info !== null &&\n changedArray(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onResetKeysChange?.(prevProps.resetKeys, resetKeys)\n this.setState(initialState)\n }\n }\n\n render() {\n const {error, info} = this.state\n const {fallbackRender, FallbackComponent, fallback} = this.props\n\n if (error !== null) {\n // we'll get a re-render with the error state in getDerivedStateFromError\n // but we don't have the info yet, so just render null\n // note that this won't be committed to the DOM thanks to our componentDidCatch\n // so the user won't see a flash of nothing, so this works fine.\n // the benefit of doing things this way rather than just putting both the\n // error and info setState within componentDidCatch is we avoid re-rendering\n // busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66\n if (!info) return null\n\n const props = {\n componentStack: info?.componentStack,\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(Component, errorBoundaryProps) {\n function Wrapped(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) {\n const [error, setError] = React.useState(null)\n if (givenError) throw givenError\n if (error) throw error\n return setError\n}\n\nexport {ErrorBoundary, withErrorBoundary, useErrorHandler}\n"],"names":["_inheritsLoose","subClass","superClass","prototype","Object","create","constructor","__proto__","changedArray","a","b","length","some","item","index","is","initialState","error","info","ErrorBoundary","state","resetErrorBoundary","args","props","onReset","setState","getDerivedStateFromError","componentDidCatch","onError","componentStack","componentDidUpdate","prevProps","resetKeys","onResetKeysChange","render","fallbackRender","FallbackComponent","fallback","React","isValidElement","Error","children","Component","withErrorBoundary","errorBoundaryProps","Wrapped","name","displayName","useErrorHandler","givenError","useState","setError"],"mappings":";;;;;;;;;;EAAe,SAASA,cAAT,CAAwBC,QAAxB,EAAkCC,UAAlC,EAA8C;EAC3DD,EAAAA,QAAQ,CAACE,SAAT,GAAqBC,MAAM,CAACC,MAAP,CAAcH,UAAU,CAACC,SAAzB,CAArB;EACAF,EAAAA,QAAQ,CAACE,SAAT,CAAmBG,WAAnB,GAAiCL,QAAjC;EACAA,EAAAA,QAAQ,CAACM,SAAT,GAAqBL,UAArB;EACD;;ECFD,IAAMM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EACxD,WAASC,OAAT,CAAiBtB,KAAjB,EAAwB;EACtB,wBACEe,wCAAC,aAAD,EAAmBM,kBAAnB,eACEN,wCAAC,SAAD,EAAef,KAAf,CADF,CADF;EAKD,GAPuD;;;EAUxD,MAAMuB,IAAI,GAAGJ,SAAS,CAACK,WAAV,IAAyBL,SAAS,CAACI,IAAnC,IAA2C,SAAxD;EACAD,EAAAA,OAAO,CAACE,WAAR,0BAA2CD,IAA3C;EAEA,SAAOD,OAAP;EACD;;EAED,SAASG,eAAT,CAAyBC,UAAzB,EAAqC;EAAA,wBACTX,yBAAK,CAACY,QAAN,CAAe,IAAf,CADS;EAAA,MAC5BjC,KAD4B;EAAA,MACrBkC,QADqB;;EAEnC,MAAIF,UAAJ,EAAgB,MAAMA,UAAN;EAChB,MAAIhC,KAAJ,EAAW,MAAMA,KAAN;EACX,SAAOkC,QAAP;EACD;;;;;;;;;;;;;;"}
|
|
@@ -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){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(r);var o={error:null,info:null},a=function(e){var r,t;function a(){for(var r,t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];return(r=e.call.apply(e,[this].concat(n))||this).state=o,r.resetErrorBoundary=function(){for(var e,t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];null==r.props.onReset||(e=r.props).onReset.apply(e,n),r.setState(o)},r}t=e,(r=a).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,a.getDerivedStateFromError=function(e){return{error:e}};var l=a.prototype;return l.componentDidCatch=function(e,r){var t,n;null==(t=(n=this.props).onError)||t.call(n,e,null==r?void 0:r.componentStack),this.setState({info:r})},l.componentDidUpdate=function(e){var r,t,n,a,l=this.state,i=l.error,u=l.info,s=this.props.resetKeys;null!==i&&null!==u&&(void 0===(n=e.resetKeys)&&(n=[]),void 0===(a=s)&&(a=[]),n.length!==a.length||n.some((function(e,r){return!Object.is(e,a[r])})))&&(null==(r=(t=this.props).onResetKeysChange)||r.call(t,e.resetKeys,s),this.setState(o))},l.render=function(){var e=this.state,r=e.error,t=e.info,o=this.props,a=o.fallbackRender,l=o.FallbackComponent,i=o.fallback;if(null!==r){if(!t)return null;var u={componentStack:null==t?void 0:t.componentStack,error:r,resetErrorBoundary:this.resetErrorBoundary};if(n.default.isValidElement(i))return i;if("function"==typeof a)return a(u);if(l)return n.default.createElement(l,u);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},a}(n.default.Component);e.ErrorBoundary=a,e.useErrorHandler=function(e){var r=n.default.useState(null),t=r[0],o=r[1];if(e)throw e;if(t)throw t;return o},e.withErrorBoundary=function(e,r){function t(t){return n.default.createElement(a,r,n.default.createElement(e,t))}var 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.js","../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"],"sourcesContent":["import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null, info: null}\nclass ErrorBoundary extends React.Component {\n state = initialState\n resetErrorBoundary = (...args) => {\n this.props.onReset?.(...args)\n this.setState(initialState)\n }\n\n componentDidCatch(error, info) {\n this.props.onError?.(error, info?.componentStack)\n this.setState({
|
|
1
|
+
{"version":3,"file":"react-error-boundary.umd.min.js","sources":["../src/index.js","../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"],"sourcesContent":["import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null, info: null}\nclass ErrorBoundary extends React.Component {\n static getDerivedStateFromError(error) {\n return {error}\n }\n\n state = initialState\n resetErrorBoundary = (...args) => {\n this.props.onReset?.(...args)\n this.setState(initialState)\n }\n\n componentDidCatch(error, info) {\n this.props.onError?.(error, info?.componentStack)\n this.setState({info})\n }\n\n componentDidUpdate(prevProps) {\n const {error, info} = this.state\n const {resetKeys} = this.props\n if (\n error !== null &&\n info !== null &&\n changedArray(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onResetKeysChange?.(prevProps.resetKeys, resetKeys)\n this.setState(initialState)\n }\n }\n\n render() {\n const {error, info} = this.state\n const {fallbackRender, FallbackComponent, fallback} = this.props\n\n if (error !== null) {\n // we'll get a re-render with the error state in getDerivedStateFromError\n // but we don't have the info yet, so just render null\n // note that this won't be committed to the DOM thanks to our componentDidCatch\n // so the user won't see a flash of nothing, so this works fine.\n // the benefit of doing things this way rather than just putting both the\n // error and info setState within componentDidCatch is we avoid re-rendering\n // busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66\n if (!info) return null\n\n const props = {\n componentStack: info?.componentStack,\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(Component, errorBoundaryProps) {\n function Wrapped(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) {\n const [error, setError] = React.useState(null)\n if (givenError) throw givenError\n if (error) throw error\n return setError\n}\n\nexport {ErrorBoundary, withErrorBoundary, useErrorHandler}\n","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}"],"names":["initialState","error","info","ErrorBoundary","subClass","superClass","state","resetErrorBoundary","args","props","onReset","setState","prototype","Object","create","constructor","__proto__","getDerivedStateFromError","componentDidCatch","onError","componentStack","componentDidUpdate","prevProps","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":"gXAEA,IAGMA,EAAe,CAACC,MAAO,KAAMC,KAAM,MACnCC,cCNS,IAAwBC,EAAUC,0IDW/CC,MAAQN,IACRO,mBAAqB,wCAAIC,2BAAAA,0BAClBC,MAAMC,cAAND,OAAMC,gBAAaF,KACnBG,SAASX,MCd+BK,KAAVD,KAC5BQ,UAAYC,OAAOC,OAAOT,EAAWO,WAC9CR,EAASQ,UAAUG,YAAcX,EACjCA,EAASY,UAAYX,IDIdY,yBAAP,SAAgChB,SACvB,CAACA,MAAAA,+BASViB,kBAAA,SAAkBjB,EAAOC,4BAClBO,OAAMU,mBAAUlB,QAAOC,SAAAA,EAAMkB,qBAC7BT,SAAS,CAACT,KAAAA,OAGjBmB,mBAAA,SAAmBC,WApBCC,EAAQC,IAqBJC,KAAKnB,MAApBL,IAAAA,MAAOC,IAAAA,KACPwB,EAAaD,KAAKhB,MAAlBiB,UAEK,OAAVzB,GACS,OAATC,cAzBgBqB,EA0BHD,EAAUI,aA1BPH,EAAI,cAAIC,EA0BUE,KA1BVF,EAAI,IAChCD,EAAEI,SAAWH,EAAEG,QAAUJ,EAAEK,MAAK,SAACC,EAAMC,UAAWjB,OAAOkB,GAAGF,EAAML,EAAEM,2BA2B3DrB,OAAMuB,6BAAoBV,EAAUI,UAAWA,QAC/Cf,SAASX,OAIlBiC,OAAA,iBACwBR,KAAKnB,MAApBL,IAAAA,MAAOC,IAAAA,OACwCuB,KAAKhB,MAApDyB,IAAAA,eAAgBC,IAAAA,kBAAmBC,IAAAA,YAE5B,OAAVnC,EAAgB,KAQbC,EAAM,OAAO,SAEZO,EAAQ,CACZW,qBAAgBlB,SAAAA,EAAMkB,eACtBnB,MAAAA,EACAM,mBAAoBkB,KAAKlB,uBAEvB8B,UAAMC,eAAeF,UAChBA,EACF,GAA8B,mBAAnBF,SACTA,EAAezB,GACjB,GAAI0B,SACFE,wBAACF,EAAsB1B,SAExB,IAAI8B,MACR,qGAKCd,KAAKhB,MAAM+B,aA7DMH,UAAMI,+CAiFlC,SAAyBC,SACGL,UAAMM,SAAS,MAAlC1C,OAAO2C,UACVF,EAAY,MAAMA,KAClBzC,EAAO,MAAMA,SACV2C,uBApBT,SAA2BH,EAAWI,YAC3BC,EAAQrC,UAEb4B,wBAAClC,EAAkB0C,EACjBR,wBAACI,EAAchC,QAMfsC,EAAON,EAAUO,aAAeP,EAAUM,MAAQ,iBACxDD,EAAQE,iCAAmCD,MAEpCD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-error-boundary",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "Simple reusable React error boundary component",
|
|
5
5
|
"main": "dist/react-error-boundary.cjs.js",
|
|
6
6
|
"module": "dist/react-error-boundary.esm.js",
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"validate": "kcd-scripts validate"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@babel/runtime": "^7.
|
|
42
|
+
"@babel/runtime": "^7.11.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@testing-library/jest-dom": "^5.11.
|
|
46
|
-
"@testing-library/react": "^
|
|
47
|
-
"@testing-library/user-event": "^12.
|
|
48
|
-
"kcd-scripts": "^6.
|
|
45
|
+
"@testing-library/jest-dom": "^5.11.4",
|
|
46
|
+
"@testing-library/react": "^11.0.2",
|
|
47
|
+
"@testing-library/user-event": "^12.1.4",
|
|
48
|
+
"kcd-scripts": "^6.3.0",
|
|
49
49
|
"react": "^16.13.1",
|
|
50
50
|
"react-dom": "^16.13.1",
|
|
51
|
-
"typescript": "^
|
|
51
|
+
"typescript": "^4.0.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"react": ">=16.13.1"
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"extends": "./node_modules/kcd-scripts/eslint.js",
|
|
58
58
|
"rules": {
|
|
59
59
|
"react/prop-types": "off",
|
|
60
|
-
"react/no-did-update-set-state": "off"
|
|
60
|
+
"react/no-did-update-set-state": "off",
|
|
61
|
+
"babel/no-unused-expressions": "off"
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
}
|