react-error-boundary 3.1.3 → 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 +5 -1
- package/dist/index.d.ts +1 -3
- package/dist/react-error-boundary.cjs.js +6 -22
- package/dist/react-error-boundary.esm.js +3 -17
- package/dist/react-error-boundary.umd.js +7 -23
- 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 +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)
|
|
@@ -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
|
@@ -46,12 +46,10 @@ declare class ErrorBoundary extends React.Component<React.PropsWithRef<React.Pro
|
|
|
46
46
|
error: Error;
|
|
47
47
|
};
|
|
48
48
|
state: ErrorBoundaryState;
|
|
49
|
-
updatedWithError: boolean;
|
|
50
49
|
resetErrorBoundary: (...args: Array<unknown>) => void;
|
|
51
50
|
reset(): void;
|
|
52
51
|
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
53
|
-
|
|
54
|
-
componentDidUpdate(prevProps: ErrorBoundaryProps): void;
|
|
52
|
+
componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState): void;
|
|
55
53
|
render(): React.ReactNode;
|
|
56
54
|
}
|
|
57
55
|
declare function withErrorBoundary<P>(Component: React.ComponentType<P>, errorBoundaryProps: ErrorBoundaryProps): React.ComponentType<P>;
|
|
@@ -16,14 +16,12 @@ function _interopNamespace(e) {
|
|
|
16
16
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
17
|
Object.defineProperty(n, k, d.get ? d : {
|
|
18
18
|
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return e[k];
|
|
21
|
-
}
|
|
19
|
+
get: function () { return e[k]; }
|
|
22
20
|
});
|
|
23
21
|
}
|
|
24
22
|
});
|
|
25
23
|
}
|
|
26
|
-
n[
|
|
24
|
+
n["default"] = e;
|
|
27
25
|
return Object.freeze(n);
|
|
28
26
|
}
|
|
29
27
|
|
|
@@ -49,7 +47,7 @@ var initialState = {
|
|
|
49
47
|
};
|
|
50
48
|
|
|
51
49
|
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
52
|
-
_inheritsLoose__default[
|
|
50
|
+
_inheritsLoose__default["default"](ErrorBoundary, _React$Component);
|
|
53
51
|
|
|
54
52
|
function ErrorBoundary() {
|
|
55
53
|
var _this;
|
|
@@ -60,7 +58,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
60
58
|
|
|
61
59
|
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
|
62
60
|
_this.state = initialState;
|
|
63
|
-
_this.updatedWithError = false;
|
|
64
61
|
|
|
65
62
|
_this.resetErrorBoundary = function () {
|
|
66
63
|
var _this$props;
|
|
@@ -86,7 +83,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
86
83
|
var _proto = ErrorBoundary.prototype;
|
|
87
84
|
|
|
88
85
|
_proto.reset = function reset() {
|
|
89
|
-
this.updatedWithError = false;
|
|
90
86
|
this.setState(initialState);
|
|
91
87
|
};
|
|
92
88
|
|
|
@@ -96,15 +92,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
96
92
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
97
93
|
};
|
|
98
94
|
|
|
99
|
-
_proto.
|
|
100
|
-
var error = this.state.error;
|
|
101
|
-
|
|
102
|
-
if (error !== null) {
|
|
103
|
-
this.updatedWithError = true;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
95
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
108
96
|
var error = this.state.error;
|
|
109
97
|
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
|
|
110
98
|
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
@@ -113,12 +101,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
113
101
|
// So we make sure that we don't check the resetKeys on the first call
|
|
114
102
|
// of cDU after the error is set
|
|
115
103
|
|
|
116
|
-
if (error !== null &&
|
|
117
|
-
this.updatedWithError = true;
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
104
|
+
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
122
105
|
var _this$props$onResetKe, _this$props3;
|
|
123
106
|
|
|
124
107
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -178,6 +161,7 @@ function useErrorHandler(givenError) {
|
|
|
178
161
|
}
|
|
179
162
|
/*
|
|
180
163
|
eslint
|
|
164
|
+
@typescript-eslint/sort-type-union-intersection-members: "off",
|
|
181
165
|
@typescript-eslint/no-throw-literal: "off",
|
|
182
166
|
@typescript-eslint/prefer-nullish-coalescing: "off"
|
|
183
167
|
*/
|
|
@@ -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,15 +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.
|
|
71
|
-
var error = this.state.error;
|
|
72
|
-
|
|
73
|
-
if (error !== null) {
|
|
74
|
-
this.updatedWithError = true;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
68
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
79
69
|
var error = this.state.error;
|
|
80
70
|
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
|
|
81
71
|
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
@@ -84,12 +74,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
84
74
|
// So we make sure that we don't check the resetKeys on the first call
|
|
85
75
|
// of cDU after the error is set
|
|
86
76
|
|
|
87
|
-
if (error !== null &&
|
|
88
|
-
this.updatedWithError = true;
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
77
|
+
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
93
78
|
var _this$props$onResetKe, _this$props3;
|
|
94
79
|
|
|
95
80
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -149,6 +134,7 @@ function useErrorHandler(givenError) {
|
|
|
149
134
|
}
|
|
150
135
|
/*
|
|
151
136
|
eslint
|
|
137
|
+
@typescript-eslint/sort-type-union-intersection-members: "off",
|
|
152
138
|
@typescript-eslint/no-throw-literal: "off",
|
|
153
139
|
@typescript-eslint/prefer-nullish-coalescing: "off"
|
|
154
140
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
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
6
|
|
|
7
7
|
function _interopNamespace(e) {
|
|
8
8
|
if (e && e.__esModule) return e;
|
|
@@ -13,14 +13,12 @@
|
|
|
13
13
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
14
|
Object.defineProperty(n, k, d.get ? d : {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return e[k];
|
|
18
|
-
}
|
|
16
|
+
get: function () { return e[k]; }
|
|
19
17
|
});
|
|
20
18
|
}
|
|
21
19
|
});
|
|
22
20
|
}
|
|
23
|
-
n[
|
|
21
|
+
n["default"] = e;
|
|
24
22
|
return Object.freeze(n);
|
|
25
23
|
}
|
|
26
24
|
|
|
@@ -71,7 +69,6 @@
|
|
|
71
69
|
|
|
72
70
|
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
|
73
71
|
_this.state = initialState;
|
|
74
|
-
_this.updatedWithError = false;
|
|
75
72
|
|
|
76
73
|
_this.resetErrorBoundary = function () {
|
|
77
74
|
var _this$props;
|
|
@@ -97,7 +94,6 @@
|
|
|
97
94
|
var _proto = ErrorBoundary.prototype;
|
|
98
95
|
|
|
99
96
|
_proto.reset = function reset() {
|
|
100
|
-
this.updatedWithError = false;
|
|
101
97
|
this.setState(initialState);
|
|
102
98
|
};
|
|
103
99
|
|
|
@@ -107,15 +103,7 @@
|
|
|
107
103
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
108
104
|
};
|
|
109
105
|
|
|
110
|
-
_proto.
|
|
111
|
-
var error = this.state.error;
|
|
112
|
-
|
|
113
|
-
if (error !== null) {
|
|
114
|
-
this.updatedWithError = true;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
106
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
119
107
|
var error = this.state.error;
|
|
120
108
|
var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
|
|
121
109
|
// happens to *also* be in the resetKeys array, we'd end up resetting
|
|
@@ -124,12 +112,7 @@
|
|
|
124
112
|
// So we make sure that we don't check the resetKeys on the first call
|
|
125
113
|
// of cDU after the error is set
|
|
126
114
|
|
|
127
|
-
if (error !== null &&
|
|
128
|
-
this.updatedWithError = true;
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
115
|
+
if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
133
116
|
var _this$props$onResetKe, _this$props3;
|
|
134
117
|
|
|
135
118
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -189,6 +172,7 @@
|
|
|
189
172
|
}
|
|
190
173
|
/*
|
|
191
174
|
eslint
|
|
175
|
+
@typescript-eslint/sort-type-union-intersection-members: "off",
|
|
192
176
|
@typescript-eslint/no-throw-literal: "off",
|
|
193
177
|
@typescript-eslint/prefer-nullish-coalescing: "off"
|
|
194
178
|
*/
|
|
@@ -199,5 +183,5 @@
|
|
|
199
183
|
|
|
200
184
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
201
185
|
|
|
202
|
-
}))
|
|
186
|
+
}));
|
|
203
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/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 updatedWithError = false\n resetErrorBoundary = (...args: Array<unknown>) => {\n this.props.onReset?.(...args)\n this.reset()\n }\n\n reset() {\n this.updatedWithError = false\n this.setState(initialState)\n }\n\n componentDidCatch(error: Error, info: React.ErrorInfo) {\n this.props.onError?.(error, info)\n }\n\n componentDidMount() {\n const {error} = this.state\n\n if (error !== null) {\n this.updatedWithError = true\n }\n }\n\n componentDidUpdate(prevProps: ErrorBoundaryProps) {\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 if (error !== null && !this.updatedWithError) {\n this.updatedWithError = true\n return\n }\n\n if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {\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/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","updatedWithError","resetErrorBoundary","args","props","onReset","reset","getDerivedStateFromError","setState","componentDidCatch","info","onError","componentDidMount","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,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,Y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7EyBH,gBAAK,CAACI;;EAgFlC,SAASC,iBAAT,CACED,SADF,EAEEE,kBAFF,EAG0B;EACxB,MAAMC,OAA+B,GAAG,SAAlCA,OAAkC,CAAAxB,KAAK,EAAI;EAC/C,wBACEiB,+BAAC,aAAD,EAAmBM,kBAAnB,eACEN,+BAAC,SAAD,EAAejB,KAAf,CADF,CADF;EAKD,GAND,CADwB;;;EAUxB,MAAMyB,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,EAAyE;EACvE,wBAA0BX,gBAAK,CAACY,QAAN,CAAwB,IAAxB,CAA1B;EAAA,MAAOnC,KAAP;EAAA,MAAcoC,QAAd;;EACA,MAAIF,UAAU,IAAI,IAAlB,EAAwB,MAAMA,UAAN;EACxB,MAAIlC,KAAK,IAAI,IAAb,EAAmB,MAAMA,KAAN;EACnB,SAAOoC,QAAP;EACD;EAWD;EACA;EACA;EACA;EACA;;;;;;;;;;;;"}
|
|
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,CAAzB;EAAyBA,IAAAA,CAAz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,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,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":["../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
|
|
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,KA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