react-error-boundary 4.0.9 → 4.0.10
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.
|
@@ -23,12 +23,16 @@ class ErrorBoundary extends react.Component {
|
|
|
23
23
|
error
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
resetErrorBoundary(
|
|
26
|
+
resetErrorBoundary() {
|
|
27
27
|
const {
|
|
28
28
|
error
|
|
29
29
|
} = this.state;
|
|
30
30
|
if (error !== null) {
|
|
31
|
-
|
|
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, {
|
|
32
36
|
args,
|
|
33
37
|
reason: "imperative-api"
|
|
34
38
|
});
|
|
@@ -36,7 +40,8 @@ class ErrorBoundary extends react.Component {
|
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
componentDidCatch(error, info) {
|
|
39
|
-
|
|
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);
|
|
40
45
|
}
|
|
41
46
|
componentDidUpdate(prevProps, prevState) {
|
|
42
47
|
const {
|
|
@@ -52,7 +57,8 @@ class ErrorBoundary extends react.Component {
|
|
|
52
57
|
// So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.
|
|
53
58
|
|
|
54
59
|
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
55
|
-
|
|
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, {
|
|
56
62
|
next: resetKeys,
|
|
57
63
|
prev: prevProps.resetKeys,
|
|
58
64
|
reason: "keys"
|
|
@@ -96,7 +102,9 @@ class ErrorBoundary extends react.Component {
|
|
|
96
102
|
}, childToRender);
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
|
-
function hasArrayChanged(
|
|
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] : [];
|
|
100
108
|
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
101
109
|
}
|
|
102
110
|
|
|
@@ -116,7 +124,7 @@ function useErrorBoundary() {
|
|
|
116
124
|
});
|
|
117
125
|
const memoized = react.useMemo(() => ({
|
|
118
126
|
resetBoundary: () => {
|
|
119
|
-
context
|
|
127
|
+
context === null || context === void 0 ? void 0 : context.resetErrorBoundary();
|
|
120
128
|
setState({
|
|
121
129
|
error: null,
|
|
122
130
|
hasError: false
|
|
@@ -126,7 +134,7 @@ function useErrorBoundary() {
|
|
|
126
134
|
error,
|
|
127
135
|
hasError: true
|
|
128
136
|
})
|
|
129
|
-
}), [context
|
|
137
|
+
}), [context === null || context === void 0 ? void 0 : context.resetErrorBoundary]);
|
|
130
138
|
if (state.hasError) {
|
|
131
139
|
throw state.error;
|
|
132
140
|
}
|
|
@@ -141,7 +149,7 @@ function withErrorBoundary(component, errorBoundaryProps) {
|
|
|
141
149
|
|
|
142
150
|
// Format for display in DevTools
|
|
143
151
|
const name = component.displayName || component.name || "Unknown";
|
|
144
|
-
Wrapped.displayName =
|
|
152
|
+
Wrapped.displayName = "withErrorBoundary(".concat(name, ")");
|
|
145
153
|
return Wrapped;
|
|
146
154
|
}
|
|
147
155
|
|
|
@@ -19,12 +19,16 @@ class ErrorBoundary extends Component {
|
|
|
19
19
|
error
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
resetErrorBoundary(
|
|
22
|
+
resetErrorBoundary() {
|
|
23
23
|
const {
|
|
24
24
|
error
|
|
25
25
|
} = this.state;
|
|
26
26
|
if (error !== null) {
|
|
27
|
-
|
|
27
|
+
var _this$props$onReset, _this$props;
|
|
28
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
29
|
+
args[_key] = arguments[_key];
|
|
30
|
+
}
|
|
31
|
+
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
28
32
|
args,
|
|
29
33
|
reason: "imperative-api"
|
|
30
34
|
});
|
|
@@ -32,7 +36,8 @@ class ErrorBoundary extends Component {
|
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
componentDidCatch(error, info) {
|
|
35
|
-
|
|
39
|
+
var _this$props$onError, _this$props2;
|
|
40
|
+
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
36
41
|
}
|
|
37
42
|
componentDidUpdate(prevProps, prevState) {
|
|
38
43
|
const {
|
|
@@ -48,7 +53,8 @@ class ErrorBoundary extends Component {
|
|
|
48
53
|
// So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.
|
|
49
54
|
|
|
50
55
|
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
51
|
-
|
|
56
|
+
var _this$props$onReset2, _this$props3;
|
|
57
|
+
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
52
58
|
next: resetKeys,
|
|
53
59
|
prev: prevProps.resetKeys,
|
|
54
60
|
reason: "keys"
|
|
@@ -92,7 +98,9 @@ class ErrorBoundary extends Component {
|
|
|
92
98
|
}, childToRender);
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
|
-
function hasArrayChanged(
|
|
101
|
+
function hasArrayChanged() {
|
|
102
|
+
let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
103
|
+
let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
96
104
|
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
97
105
|
}
|
|
98
106
|
|
|
@@ -112,7 +120,7 @@ function useErrorBoundary() {
|
|
|
112
120
|
});
|
|
113
121
|
const memoized = useMemo(() => ({
|
|
114
122
|
resetBoundary: () => {
|
|
115
|
-
context
|
|
123
|
+
context === null || context === void 0 ? void 0 : context.resetErrorBoundary();
|
|
116
124
|
setState({
|
|
117
125
|
error: null,
|
|
118
126
|
hasError: false
|
|
@@ -122,7 +130,7 @@ function useErrorBoundary() {
|
|
|
122
130
|
error,
|
|
123
131
|
hasError: true
|
|
124
132
|
})
|
|
125
|
-
}), [context
|
|
133
|
+
}), [context === null || context === void 0 ? void 0 : context.resetErrorBoundary]);
|
|
126
134
|
if (state.hasError) {
|
|
127
135
|
throw state.error;
|
|
128
136
|
}
|
|
@@ -137,7 +145,7 @@ function withErrorBoundary(component, errorBoundaryProps) {
|
|
|
137
145
|
|
|
138
146
|
// Format for display in DevTools
|
|
139
147
|
const name = component.displayName || component.name || "Unknown";
|
|
140
|
-
Wrapped.displayName =
|
|
148
|
+
Wrapped.displayName = "withErrorBoundary(".concat(name, ")");
|
|
141
149
|
return Wrapped;
|
|
142
150
|
}
|
|
143
151
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-error-boundary",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.10",
|
|
4
4
|
"description": "Simple reusable React error boundary component",
|
|
5
5
|
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"@babel/runtime": "^7.12.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
+
"@babel/preset-env": "^7.22.5",
|
|
46
47
|
"@babel/preset-typescript": "^7.21.5",
|
|
47
48
|
"@preconstruct/cli": "^2.7.0",
|
|
48
49
|
"@types/jest": "^26.0.15",
|