react-error-boundary 3.1.4 → 4.0.1

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.
@@ -1,171 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
6
- var React = require('react');
7
-
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
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
-
28
- var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
29
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
30
-
31
- var changedArray = function changedArray(a, b) {
32
- if (a === void 0) {
33
- a = [];
34
- }
35
-
36
- if (b === void 0) {
37
- b = [];
38
- }
39
-
40
- return a.length !== b.length || a.some(function (item, index) {
41
- return !Object.is(item, b[index]);
42
- });
43
- };
44
-
45
- var initialState = {
46
- error: null
47
- };
48
-
49
- var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
50
- _inheritsLoose__default["default"](ErrorBoundary, _React$Component);
51
-
52
- function ErrorBoundary() {
53
- var _this;
54
-
55
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
56
- _args[_key] = arguments[_key];
57
- }
58
-
59
- _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
60
- _this.state = initialState;
61
-
62
- _this.resetErrorBoundary = function () {
63
- var _this$props;
64
-
65
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
66
- args[_key2] = arguments[_key2];
67
- }
68
-
69
- _this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
70
-
71
- _this.reset();
72
- };
73
-
74
- return _this;
75
- }
76
-
77
- ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
78
- return {
79
- error: error
80
- };
81
- };
82
-
83
- var _proto = ErrorBoundary.prototype;
84
-
85
- _proto.reset = function reset() {
86
- this.setState(initialState);
87
- };
88
-
89
- _proto.componentDidCatch = function componentDidCatch(error, info) {
90
- var _this$props$onError, _this$props2;
91
-
92
- (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
93
- };
94
-
95
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
96
- var error = this.state.error;
97
- var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
98
- // happens to *also* be in the resetKeys array, we'd end up resetting
99
- // the error boundary immediately. This would likely trigger a second
100
- // error to be thrown.
101
- // So we make sure that we don't check the resetKeys on the first call
102
- // of cDU after the error is set
103
-
104
- if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
105
- var _this$props$onResetKe, _this$props3;
106
-
107
- (_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
108
- this.reset();
109
- }
110
- };
111
-
112
- _proto.render = function render() {
113
- var error = this.state.error;
114
- var _this$props4 = this.props,
115
- fallbackRender = _this$props4.fallbackRender,
116
- FallbackComponent = _this$props4.FallbackComponent,
117
- fallback = _this$props4.fallback;
118
-
119
- if (error !== null) {
120
- var _props = {
121
- error: error,
122
- resetErrorBoundary: this.resetErrorBoundary
123
- };
124
-
125
- if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
126
- return fallback;
127
- } else if (typeof fallbackRender === 'function') {
128
- return fallbackRender(_props);
129
- } else if (FallbackComponent) {
130
- return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
131
- } else {
132
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
133
- }
134
- }
135
-
136
- return this.props.children;
137
- };
138
-
139
- return ErrorBoundary;
140
- }(React__namespace.Component);
141
-
142
- function withErrorBoundary(Component, errorBoundaryProps) {
143
- var Wrapped = function Wrapped(props) {
144
- return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props));
145
- }; // Format for display in DevTools
146
-
147
-
148
- var name = Component.displayName || Component.name || 'Unknown';
149
- Wrapped.displayName = "withErrorBoundary(" + name + ")";
150
- return Wrapped;
151
- }
152
-
153
- function useErrorHandler(givenError) {
154
- var _React$useState = React__namespace.useState(null),
155
- error = _React$useState[0],
156
- setError = _React$useState[1];
157
-
158
- if (givenError != null) throw givenError;
159
- if (error != null) throw error;
160
- return setError;
161
- }
162
- /*
163
- eslint
164
- @typescript-eslint/sort-type-union-intersection-members: "off",
165
- @typescript-eslint/no-throw-literal: "off",
166
- @typescript-eslint/prefer-nullish-coalescing: "off"
167
- */
168
-
169
- exports.ErrorBoundary = ErrorBoundary;
170
- exports.useErrorHandler = useErrorHandler;
171
- exports.withErrorBoundary = withErrorBoundary;
@@ -1 +0,0 @@
1
- export * from "../dist/index";
@@ -1,142 +0,0 @@
1
- import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
2
- import * as React from 'react';
3
-
4
- var changedArray = function changedArray(a, b) {
5
- if (a === void 0) {
6
- a = [];
7
- }
8
-
9
- if (b === void 0) {
10
- b = [];
11
- }
12
-
13
- return a.length !== b.length || a.some(function (item, index) {
14
- return !Object.is(item, b[index]);
15
- });
16
- };
17
-
18
- var initialState = {
19
- error: null
20
- };
21
-
22
- var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
23
- _inheritsLoose(ErrorBoundary, _React$Component);
24
-
25
- function ErrorBoundary() {
26
- var _this;
27
-
28
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
29
- _args[_key] = arguments[_key];
30
- }
31
-
32
- _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
33
- _this.state = initialState;
34
-
35
- _this.resetErrorBoundary = function () {
36
- var _this$props;
37
-
38
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
39
- args[_key2] = arguments[_key2];
40
- }
41
-
42
- _this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
43
-
44
- _this.reset();
45
- };
46
-
47
- return _this;
48
- }
49
-
50
- ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
51
- return {
52
- error: error
53
- };
54
- };
55
-
56
- var _proto = ErrorBoundary.prototype;
57
-
58
- _proto.reset = function reset() {
59
- this.setState(initialState);
60
- };
61
-
62
- _proto.componentDidCatch = function componentDidCatch(error, info) {
63
- var _this$props$onError, _this$props2;
64
-
65
- (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
66
- };
67
-
68
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
69
- var error = this.state.error;
70
- var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
71
- // happens to *also* be in the resetKeys array, we'd end up resetting
72
- // the error boundary immediately. This would likely trigger a second
73
- // error to be thrown.
74
- // So we make sure that we don't check the resetKeys on the first call
75
- // of cDU after the error is set
76
-
77
- if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
78
- var _this$props$onResetKe, _this$props3;
79
-
80
- (_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
81
- this.reset();
82
- }
83
- };
84
-
85
- _proto.render = function render() {
86
- var error = this.state.error;
87
- var _this$props4 = this.props,
88
- fallbackRender = _this$props4.fallbackRender,
89
- FallbackComponent = _this$props4.FallbackComponent,
90
- fallback = _this$props4.fallback;
91
-
92
- if (error !== null) {
93
- var _props = {
94
- error: error,
95
- resetErrorBoundary: this.resetErrorBoundary
96
- };
97
-
98
- if ( /*#__PURE__*/React.isValidElement(fallback)) {
99
- return fallback;
100
- } else if (typeof fallbackRender === 'function') {
101
- return fallbackRender(_props);
102
- } else if (FallbackComponent) {
103
- return /*#__PURE__*/React.createElement(FallbackComponent, _props);
104
- } else {
105
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
106
- }
107
- }
108
-
109
- return this.props.children;
110
- };
111
-
112
- return ErrorBoundary;
113
- }(React.Component);
114
-
115
- function withErrorBoundary(Component, errorBoundaryProps) {
116
- var Wrapped = function Wrapped(props) {
117
- return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props));
118
- }; // Format for display in DevTools
119
-
120
-
121
- var name = Component.displayName || Component.name || 'Unknown';
122
- Wrapped.displayName = "withErrorBoundary(" + name + ")";
123
- return Wrapped;
124
- }
125
-
126
- function useErrorHandler(givenError) {
127
- var _React$useState = React.useState(null),
128
- error = _React$useState[0],
129
- setError = _React$useState[1];
130
-
131
- if (givenError != null) throw givenError;
132
- if (error != null) throw error;
133
- return setError;
134
- }
135
- /*
136
- eslint
137
- @typescript-eslint/sort-type-union-intersection-members: "off",
138
- @typescript-eslint/no-throw-literal: "off",
139
- @typescript-eslint/prefer-nullish-coalescing: "off"
140
- */
141
-
142
- export { ErrorBoundary, useErrorHandler, withErrorBoundary };
@@ -1 +0,0 @@
1
- export * from "../dist/index";
@@ -1,187 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactErrorBoundary = {}, global.React));
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
- }
35
-
36
- function _inheritsLoose(subClass, superClass) {
37
- subClass.prototype = Object.create(superClass.prototype);
38
- subClass.prototype.constructor = subClass;
39
- _setPrototypeOf(subClass, superClass);
40
- }
41
-
42
- var changedArray = function changedArray(a, b) {
43
- if (a === void 0) {
44
- a = [];
45
- }
46
-
47
- if (b === void 0) {
48
- b = [];
49
- }
50
-
51
- return a.length !== b.length || a.some(function (item, index) {
52
- return !Object.is(item, b[index]);
53
- });
54
- };
55
-
56
- var initialState = {
57
- error: null
58
- };
59
-
60
- var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
61
- _inheritsLoose(ErrorBoundary, _React$Component);
62
-
63
- function ErrorBoundary() {
64
- var _this;
65
-
66
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
67
- _args[_key] = arguments[_key];
68
- }
69
-
70
- _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
71
- _this.state = initialState;
72
-
73
- _this.resetErrorBoundary = function () {
74
- var _this$props;
75
-
76
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
77
- args[_key2] = arguments[_key2];
78
- }
79
-
80
- _this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
81
-
82
- _this.reset();
83
- };
84
-
85
- return _this;
86
- }
87
-
88
- ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
89
- return {
90
- error: error
91
- };
92
- };
93
-
94
- var _proto = ErrorBoundary.prototype;
95
-
96
- _proto.reset = function reset() {
97
- this.setState(initialState);
98
- };
99
-
100
- _proto.componentDidCatch = function componentDidCatch(error, info) {
101
- var _this$props$onError, _this$props2;
102
-
103
- (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
104
- };
105
-
106
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
107
- var error = this.state.error;
108
- var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
109
- // happens to *also* be in the resetKeys array, we'd end up resetting
110
- // the error boundary immediately. This would likely trigger a second
111
- // error to be thrown.
112
- // So we make sure that we don't check the resetKeys on the first call
113
- // of cDU after the error is set
114
-
115
- if (error !== null && prevState.error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
116
- var _this$props$onResetKe, _this$props3;
117
-
118
- (_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
119
- this.reset();
120
- }
121
- };
122
-
123
- _proto.render = function render() {
124
- var error = this.state.error;
125
- var _this$props4 = this.props,
126
- fallbackRender = _this$props4.fallbackRender,
127
- FallbackComponent = _this$props4.FallbackComponent,
128
- fallback = _this$props4.fallback;
129
-
130
- if (error !== null) {
131
- var _props = {
132
- error: error,
133
- resetErrorBoundary: this.resetErrorBoundary
134
- };
135
-
136
- if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
137
- return fallback;
138
- } else if (typeof fallbackRender === 'function') {
139
- return fallbackRender(_props);
140
- } else if (FallbackComponent) {
141
- return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
142
- } else {
143
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
144
- }
145
- }
146
-
147
- return this.props.children;
148
- };
149
-
150
- return ErrorBoundary;
151
- }(React__namespace.Component);
152
-
153
- function withErrorBoundary(Component, errorBoundaryProps) {
154
- var Wrapped = function Wrapped(props) {
155
- return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props));
156
- }; // Format for display in DevTools
157
-
158
-
159
- var name = Component.displayName || Component.name || 'Unknown';
160
- Wrapped.displayName = "withErrorBoundary(" + name + ")";
161
- return Wrapped;
162
- }
163
-
164
- function useErrorHandler(givenError) {
165
- var _React$useState = React__namespace.useState(null),
166
- error = _React$useState[0],
167
- setError = _React$useState[1];
168
-
169
- if (givenError != null) throw givenError;
170
- if (error != null) throw error;
171
- return setError;
172
- }
173
- /*
174
- eslint
175
- @typescript-eslint/sort-type-union-intersection-members: "off",
176
- @typescript-eslint/no-throw-literal: "off",
177
- @typescript-eslint/prefer-nullish-coalescing: "off"
178
- */
179
-
180
- exports.ErrorBoundary = ErrorBoundary;
181
- exports.useErrorHandler = useErrorHandler;
182
- exports.withErrorBoundary = withErrorBoundary;
183
-
184
- Object.defineProperty(exports, '__esModule', { value: true });
185
-
186
- }));
187
- //# sourceMappingURL=react-error-boundary.umd.js.map
@@ -1 +0,0 @@
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,E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EA,SAAOD,OAAP;EACD;;EAED,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 +0,0 @@
1
- export * from "../dist/index";
@@ -1,2 +0,0 @@
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
- //# sourceMappingURL=react-error-boundary.umd.min.js.map
@@ -1 +0,0 @@
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,KAzGMF,EAAoB,IAChED,EAAEI,SAAWH,EAAEG,QAAUJ,EAAEK,MAAK,SAACC,EAAMC,UAAWhC,OAAOiC,GAAGF,EAAML,EAAEM,2B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