react-error-boundary 3.1.3 → 4.0.0

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,187 +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 () {
20
- return e[k];
21
- }
22
- });
23
- }
24
- });
25
- }
26
- n['default'] = e;
27
- return Object.freeze(n);
28
- }
29
-
30
- var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
31
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
-
33
- var changedArray = function changedArray(a, b) {
34
- if (a === void 0) {
35
- a = [];
36
- }
37
-
38
- if (b === void 0) {
39
- b = [];
40
- }
41
-
42
- return a.length !== b.length || a.some(function (item, index) {
43
- return !Object.is(item, b[index]);
44
- });
45
- };
46
-
47
- var initialState = {
48
- error: null
49
- };
50
-
51
- var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
52
- _inheritsLoose__default['default'](ErrorBoundary, _React$Component);
53
-
54
- function ErrorBoundary() {
55
- var _this;
56
-
57
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
58
- _args[_key] = arguments[_key];
59
- }
60
-
61
- _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
62
- _this.state = initialState;
63
- _this.updatedWithError = false;
64
-
65
- _this.resetErrorBoundary = function () {
66
- var _this$props;
67
-
68
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
69
- args[_key2] = arguments[_key2];
70
- }
71
-
72
- _this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
73
-
74
- _this.reset();
75
- };
76
-
77
- return _this;
78
- }
79
-
80
- ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
81
- return {
82
- error: error
83
- };
84
- };
85
-
86
- var _proto = ErrorBoundary.prototype;
87
-
88
- _proto.reset = function reset() {
89
- this.updatedWithError = false;
90
- this.setState(initialState);
91
- };
92
-
93
- _proto.componentDidCatch = function componentDidCatch(error, info) {
94
- var _this$props$onError, _this$props2;
95
-
96
- (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
97
- };
98
-
99
- _proto.componentDidMount = function componentDidMount() {
100
- var error = this.state.error;
101
-
102
- if (error !== null) {
103
- this.updatedWithError = true;
104
- }
105
- };
106
-
107
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
108
- var error = this.state.error;
109
- var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
110
- // happens to *also* be in the resetKeys array, we'd end up resetting
111
- // the error boundary immediately. This would likely trigger a second
112
- // error to be thrown.
113
- // So we make sure that we don't check the resetKeys on the first call
114
- // of cDU after the error is set
115
-
116
- if (error !== null && !this.updatedWithError) {
117
- this.updatedWithError = true;
118
- return;
119
- }
120
-
121
- if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
122
- var _this$props$onResetKe, _this$props3;
123
-
124
- (_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
125
- this.reset();
126
- }
127
- };
128
-
129
- _proto.render = function render() {
130
- var error = this.state.error;
131
- var _this$props4 = this.props,
132
- fallbackRender = _this$props4.fallbackRender,
133
- FallbackComponent = _this$props4.FallbackComponent,
134
- fallback = _this$props4.fallback;
135
-
136
- if (error !== null) {
137
- var _props = {
138
- error: error,
139
- resetErrorBoundary: this.resetErrorBoundary
140
- };
141
-
142
- if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
143
- return fallback;
144
- } else if (typeof fallbackRender === 'function') {
145
- return fallbackRender(_props);
146
- } else if (FallbackComponent) {
147
- return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
148
- } else {
149
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
150
- }
151
- }
152
-
153
- return this.props.children;
154
- };
155
-
156
- return ErrorBoundary;
157
- }(React__namespace.Component);
158
-
159
- function withErrorBoundary(Component, errorBoundaryProps) {
160
- var Wrapped = function Wrapped(props) {
161
- return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props));
162
- }; // Format for display in DevTools
163
-
164
-
165
- var name = Component.displayName || Component.name || 'Unknown';
166
- Wrapped.displayName = "withErrorBoundary(" + name + ")";
167
- return Wrapped;
168
- }
169
-
170
- function useErrorHandler(givenError) {
171
- var _React$useState = React__namespace.useState(null),
172
- error = _React$useState[0],
173
- setError = _React$useState[1];
174
-
175
- if (givenError != null) throw givenError;
176
- if (error != null) throw error;
177
- return setError;
178
- }
179
- /*
180
- eslint
181
- @typescript-eslint/no-throw-literal: "off",
182
- @typescript-eslint/prefer-nullish-coalescing: "off"
183
- */
184
-
185
- exports.ErrorBoundary = ErrorBoundary;
186
- exports.useErrorHandler = useErrorHandler;
187
- exports.withErrorBoundary = withErrorBoundary;
@@ -1 +0,0 @@
1
- export * from "../dist/index";
@@ -1,156 +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
- _this.updatedWithError = false;
35
-
36
- _this.resetErrorBoundary = function () {
37
- var _this$props;
38
-
39
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
40
- args[_key2] = arguments[_key2];
41
- }
42
-
43
- _this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
44
-
45
- _this.reset();
46
- };
47
-
48
- return _this;
49
- }
50
-
51
- ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
52
- return {
53
- error: error
54
- };
55
- };
56
-
57
- var _proto = ErrorBoundary.prototype;
58
-
59
- _proto.reset = function reset() {
60
- this.updatedWithError = false;
61
- this.setState(initialState);
62
- };
63
-
64
- _proto.componentDidCatch = function componentDidCatch(error, info) {
65
- var _this$props$onError, _this$props2;
66
-
67
- (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
68
- };
69
-
70
- _proto.componentDidMount = function componentDidMount() {
71
- var error = this.state.error;
72
-
73
- if (error !== null) {
74
- this.updatedWithError = true;
75
- }
76
- };
77
-
78
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
79
- var error = this.state.error;
80
- var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
81
- // happens to *also* be in the resetKeys array, we'd end up resetting
82
- // the error boundary immediately. This would likely trigger a second
83
- // error to be thrown.
84
- // So we make sure that we don't check the resetKeys on the first call
85
- // of cDU after the error is set
86
-
87
- if (error !== null && !this.updatedWithError) {
88
- this.updatedWithError = true;
89
- return;
90
- }
91
-
92
- if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
93
- var _this$props$onResetKe, _this$props3;
94
-
95
- (_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
96
- this.reset();
97
- }
98
- };
99
-
100
- _proto.render = function render() {
101
- var error = this.state.error;
102
- var _this$props4 = this.props,
103
- fallbackRender = _this$props4.fallbackRender,
104
- FallbackComponent = _this$props4.FallbackComponent,
105
- fallback = _this$props4.fallback;
106
-
107
- if (error !== null) {
108
- var _props = {
109
- error: error,
110
- resetErrorBoundary: this.resetErrorBoundary
111
- };
112
-
113
- if ( /*#__PURE__*/React.isValidElement(fallback)) {
114
- return fallback;
115
- } else if (typeof fallbackRender === 'function') {
116
- return fallbackRender(_props);
117
- } else if (FallbackComponent) {
118
- return /*#__PURE__*/React.createElement(FallbackComponent, _props);
119
- } else {
120
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
121
- }
122
- }
123
-
124
- return this.props.children;
125
- };
126
-
127
- return ErrorBoundary;
128
- }(React.Component);
129
-
130
- function withErrorBoundary(Component, errorBoundaryProps) {
131
- var Wrapped = function Wrapped(props) {
132
- return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props));
133
- }; // Format for display in DevTools
134
-
135
-
136
- var name = Component.displayName || Component.name || 'Unknown';
137
- Wrapped.displayName = "withErrorBoundary(" + name + ")";
138
- return Wrapped;
139
- }
140
-
141
- function useErrorHandler(givenError) {
142
- var _React$useState = React.useState(null),
143
- error = _React$useState[0],
144
- setError = _React$useState[1];
145
-
146
- if (givenError != null) throw givenError;
147
- if (error != null) throw error;
148
- return setError;
149
- }
150
- /*
151
- eslint
152
- @typescript-eslint/no-throw-literal: "off",
153
- @typescript-eslint/prefer-nullish-coalescing: "off"
154
- */
155
-
156
- export { ErrorBoundary, useErrorHandler, withErrorBoundary };
@@ -1 +0,0 @@
1
- export * from "../dist/index";
@@ -1,203 +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 () {
17
- return e[k];
18
- }
19
- });
20
- }
21
- });
22
- }
23
- n['default'] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
-
29
- function _setPrototypeOf(o, p) {
30
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
31
- o.__proto__ = p;
32
- return o;
33
- };
34
-
35
- return _setPrototypeOf(o, p);
36
- }
37
-
38
- function _inheritsLoose(subClass, superClass) {
39
- subClass.prototype = Object.create(superClass.prototype);
40
- subClass.prototype.constructor = subClass;
41
- _setPrototypeOf(subClass, superClass);
42
- }
43
-
44
- var changedArray = function changedArray(a, b) {
45
- if (a === void 0) {
46
- a = [];
47
- }
48
-
49
- if (b === void 0) {
50
- b = [];
51
- }
52
-
53
- return a.length !== b.length || a.some(function (item, index) {
54
- return !Object.is(item, b[index]);
55
- });
56
- };
57
-
58
- var initialState = {
59
- error: null
60
- };
61
-
62
- var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
63
- _inheritsLoose(ErrorBoundary, _React$Component);
64
-
65
- function ErrorBoundary() {
66
- var _this;
67
-
68
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
69
- _args[_key] = arguments[_key];
70
- }
71
-
72
- _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
73
- _this.state = initialState;
74
- _this.updatedWithError = false;
75
-
76
- _this.resetErrorBoundary = function () {
77
- var _this$props;
78
-
79
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
80
- args[_key2] = arguments[_key2];
81
- }
82
-
83
- _this.props.onReset == null ? void 0 : (_this$props = _this.props).onReset.apply(_this$props, args);
84
-
85
- _this.reset();
86
- };
87
-
88
- return _this;
89
- }
90
-
91
- ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
92
- return {
93
- error: error
94
- };
95
- };
96
-
97
- var _proto = ErrorBoundary.prototype;
98
-
99
- _proto.reset = function reset() {
100
- this.updatedWithError = false;
101
- this.setState(initialState);
102
- };
103
-
104
- _proto.componentDidCatch = function componentDidCatch(error, info) {
105
- var _this$props$onError, _this$props2;
106
-
107
- (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
108
- };
109
-
110
- _proto.componentDidMount = function componentDidMount() {
111
- var error = this.state.error;
112
-
113
- if (error !== null) {
114
- this.updatedWithError = true;
115
- }
116
- };
117
-
118
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
119
- var error = this.state.error;
120
- var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
121
- // happens to *also* be in the resetKeys array, we'd end up resetting
122
- // the error boundary immediately. This would likely trigger a second
123
- // error to be thrown.
124
- // So we make sure that we don't check the resetKeys on the first call
125
- // of cDU after the error is set
126
-
127
- if (error !== null && !this.updatedWithError) {
128
- this.updatedWithError = true;
129
- return;
130
- }
131
-
132
- if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
133
- var _this$props$onResetKe, _this$props3;
134
-
135
- (_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
136
- this.reset();
137
- }
138
- };
139
-
140
- _proto.render = function render() {
141
- var error = this.state.error;
142
- var _this$props4 = this.props,
143
- fallbackRender = _this$props4.fallbackRender,
144
- FallbackComponent = _this$props4.FallbackComponent,
145
- fallback = _this$props4.fallback;
146
-
147
- if (error !== null) {
148
- var _props = {
149
- error: error,
150
- resetErrorBoundary: this.resetErrorBoundary
151
- };
152
-
153
- if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
154
- return fallback;
155
- } else if (typeof fallbackRender === 'function') {
156
- return fallbackRender(_props);
157
- } else if (FallbackComponent) {
158
- return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
159
- } else {
160
- throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
161
- }
162
- }
163
-
164
- return this.props.children;
165
- };
166
-
167
- return ErrorBoundary;
168
- }(React__namespace.Component);
169
-
170
- function withErrorBoundary(Component, errorBoundaryProps) {
171
- var Wrapped = function Wrapped(props) {
172
- return /*#__PURE__*/React__namespace.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__namespace.createElement(Component, props));
173
- }; // Format for display in DevTools
174
-
175
-
176
- var name = Component.displayName || Component.name || 'Unknown';
177
- Wrapped.displayName = "withErrorBoundary(" + name + ")";
178
- return Wrapped;
179
- }
180
-
181
- function useErrorHandler(givenError) {
182
- var _React$useState = React__namespace.useState(null),
183
- error = _React$useState[0],
184
- setError = _React$useState[1];
185
-
186
- if (givenError != null) throw givenError;
187
- if (error != null) throw error;
188
- return setError;
189
- }
190
- /*
191
- eslint
192
- @typescript-eslint/no-throw-literal: "off",
193
- @typescript-eslint/prefer-nullish-coalescing: "off"
194
- */
195
-
196
- exports.ErrorBoundary = ErrorBoundary;
197
- exports.useErrorHandler = useErrorHandler;
198
- exports.withErrorBoundary = withErrorBoundary;
199
-
200
- Object.defineProperty(exports, '__esModule', { value: true });
201
-
202
- })));
203
- //# 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 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,E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eof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).ReactErrorBoundary={},r.React)}(this,(function(r,e){"use strict";function t(r){if(r&&r.__esModule)return r;var e=Object.create(null);return r&&Object.keys(r).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return r[t]}})}})),e.default=r,Object.freeze(e)}var n=t(e);function o(r,e){return(o=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}var a={error:null},i=function(r){var e,t;function i(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return(e=r.call.apply(r,[this].concat(n))||this).state=a,e.updatedWithError=!1,e.resetErrorBoundary=function(){for(var r,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];null==e.props.onReset||(r=e.props).onReset.apply(r,n),e.reset()},e}t=r,(e=i).prototype=Object.create(t.prototype),e.prototype.constructor=e,o(e,t),i.getDerivedStateFromError=function(r){return{error:r}};var u=i.prototype;return u.reset=function(){this.updatedWithError=!1,this.setState(a)},u.componentDidCatch=function(r,e){var t,n;null==(t=(n=this.props).onError)||t.call(n,r,e)},u.componentDidMount=function(){null!==this.state.error&&(this.updatedWithError=!0)},u.componentDidUpdate=function(r){var e,t,n,o,a=this.state.error,i=this.props.resetKeys;null===a||this.updatedWithError?null!==a&&(void 0===(n=r.resetKeys)&&(n=[]),void 0===(o=i)&&(o=[]),n.length!==o.length||n.some((function(r,e){return!Object.is(r,o[e])})))&&(null==(e=(t=this.props).onResetKeysChange)||e.call(t,r.resetKeys,i),this.reset()):this.updatedWithError=!0},u.render=function(){var r=this.state.error,e=this.props,t=e.fallbackRender,o=e.FallbackComponent,a=e.fallback;if(null!==r){var i={error:r,resetErrorBoundary:this.resetErrorBoundary};if(n.isValidElement(a))return a;if("function"==typeof t)return t(i);if(o)return n.createElement(o,i);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},i}(n.Component);r.ErrorBoundary=i,r.useErrorHandler=function(r){var e=n.useState(null),t=e[0],o=e[1];if(null!=r)throw r;if(null!=t)throw t;return o},r.withErrorBoundary=function(r,e){var t=function(t){return n.createElement(i,e,n.createElement(r,t))},o=r.displayName||r.name||"Unknown";return t.displayName="withErrorBoundary("+o+")",t},Object.defineProperty(r,"__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 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","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","updatedWithError","resetErrorBoundary","args","props","onReset","reset","prototype","create","constructor","getDerivedStateFromError","setState","componentDidCatch","info","onError","componentDidMount","this","componentDidUpdate","prevProps","a","b","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,IAGcA,EAAGC,GCJ5B,IAgEMI,EAAmC,CAACC,MAAO,MAE3CC,cCnES,IAAwBC,EAAUC,0ID2E/CC,MAAQL,IACRM,kBAAmB,IACnBC,mBAAqB,wCAAIC,2BAAAA,0BAClBC,MAAMC,cAAND,OAAMC,gBAAaF,KACnBG,WC/EwCP,KAAVD,KAC5BS,UAAYf,OAAOgB,OAAOT,EAAWQ,WAC9CT,EAASS,UAAUE,YAAcX,EACjCL,EAAeK,EAAUC,KDoElBW,yBAAP,SAAgCd,SACvB,CAACA,MAAAA,+BAUVU,MAAA,gBACOL,kBAAmB,OACnBU,SAAShB,MAGhBiB,kBAAA,SAAkBhB,EAAciB,4BACzBT,OAAMU,mBAAUlB,EAAOiB,MAG9BE,kBAAA,WAGgB,OAFEC,KAAKhB,MAAdJ,aAGAK,kBAAmB,MAI5BgB,mBAAA,SAAmBC,WAlGCC,EAAwBC,EAmGnCxB,EAASoB,KAAKhB,MAAdJ,MACAyB,EAAaL,KAAKZ,MAAlBiB,UAQO,OAAVzB,GAAmBoB,KAAKf,iBAKd,OAAVL,cAjHcuB,EAiHiBD,EAAUG,aAjH3BF,EAAoB,cAAIC,EAiHcC,KAjHdD,EAAoB,IAChED,EAAEG,SAAWF,EAAEE,QAAUH,EAAEI,MAAK,SAACC,EAAMC,UAAWjC,OAAOkC,GAAGF,EAAMJ,EAAEK,2BAiH3DrB,OAAMuB,6BAAoBT,EAAUG,UAAWA,QAC/Cf,cANAL,kBAAmB,KAU5B2B,OAAA,eACShC,EAASoB,KAAKhB,MAAdJ,QAE+CoB,KAAKZ,MAApDyB,IAAAA,eAAgBC,IAAAA,kBAAmBC,IAAAA,YA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