react-error-boundary 3.0.2 → 3.1.3

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 CHANGED
@@ -12,7 +12,6 @@
12
12
  [![version][version-badge]][package]
13
13
  [![downloads][downloads-badge]][npmtrends]
14
14
  [![MIT License][license-badge]][license]
15
-
16
15
  [![PRs Welcome][prs-badge]][prs]
17
16
  [![Code of Conduct][coc-badge]][coc]
18
17
  <!-- prettier-ignore-end -->
@@ -290,7 +289,7 @@ See the recovery examples above.
290
289
  This is called when the `resetKeys` are changed (triggering a reset of the
291
290
  `ErrorBoundary`). It's called with the `prevResetKeys` and the `resetKeys`.
292
291
 
293
- ### `useErrorHandler(error?: Error)`
292
+ ### `useErrorHandler(error?: unknown)`
294
293
 
295
294
  React's error boundaries feature is limited in that the boundaries can only
296
295
  handle errors thrown during React's lifecycles. To quote
@@ -336,9 +335,7 @@ function Greeting() {
336
335
  <form onSubmit={handleSubmit}>
337
336
  <label>Name</label>
338
337
  <input id="name" />
339
- <button type="submit"}>
340
- get a greeting
341
- </button>
338
+ <button type="submit">get a greeting</button>
342
339
  </form>
343
340
  )
344
341
  }
@@ -425,20 +422,20 @@ MIT
425
422
  <!-- prettier-ignore-start -->
426
423
  [npm]: https://www.npmjs.com
427
424
  [node]: https://nodejs.org
428
- [build-badge]: https://img.shields.io/travis/bvaughn/react-error-boundary.svg?style=flat-square
429
- [build]: https://travis-ci.org/bvaughn/react-error-boundary
425
+ [build-badge]: https://img.shields.io/github/workflow/status/bvaughn/react-error-boundary/validate?logo=github&style=flat-square
426
+ [build]: https://github.com/bvaughn/react-error-boundary/actions?query=workflow%3Avalidate
430
427
  [coverage-badge]: https://img.shields.io/codecov/c/github/bvaughn/react-error-boundary.svg?style=flat-square
431
428
  [coverage]: https://codecov.io/github/bvaughn/react-error-boundary
432
429
  [version-badge]: https://img.shields.io/npm/v/react-error-boundary.svg?style=flat-square
433
430
  [package]: https://www.npmjs.com/package/react-error-boundary
434
431
  [downloads-badge]: https://img.shields.io/npm/dm/react-error-boundary.svg?style=flat-square
435
- [npmtrends]: http://www.npmtrends.com/react-error-boundary
432
+ [npmtrends]: https://www.npmtrends.com/react-error-boundary
436
433
  [license-badge]: https://img.shields.io/npm/l/react-error-boundary.svg?style=flat-square
437
434
  [license]: https://github.com/bvaughn/react-error-boundary/blob/master/LICENSE
438
435
  [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
439
- [prs]: http://makeapullrequest.com
436
+ [prs]: https://makeapullrequest.com
440
437
  [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
441
- [coc]: https://github.com/bvaughn/react-error-boundary/blob/master/other/CODE_OF_CONDUCT.md
438
+ [coc]: https://github.com/bvaughn/react-error-boundary/blob/master/CODE_OF_CONDUCT.md
442
439
  [bugs]: https://github.com/bvaughn/react-error-boundary/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Acreated-desc+label%3Abug
443
440
  [requests]: https://github.com/bvaughn/react-error-boundary/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement
444
441
  [good-first-issue]: https://github.com/bvaughn/react-error-boundary/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement+label%3A%22good+first+issue%22
@@ -0,0 +1,60 @@
1
+ import * as React from 'react';
2
+ interface FallbackProps {
3
+ error: Error;
4
+ resetErrorBoundary: (...args: Array<unknown>) => void;
5
+ }
6
+ interface ErrorBoundaryPropsWithComponent {
7
+ onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
8
+ onReset?: (...args: Array<unknown>) => void;
9
+ onError?: (error: Error, info: {
10
+ componentStack: string;
11
+ }) => void;
12
+ resetKeys?: Array<unknown>;
13
+ fallback?: never;
14
+ FallbackComponent: React.ComponentType<FallbackProps>;
15
+ fallbackRender?: never;
16
+ }
17
+ declare function FallbackRender(props: FallbackProps): React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
18
+ interface ErrorBoundaryPropsWithRender {
19
+ onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
20
+ onReset?: (...args: Array<unknown>) => void;
21
+ onError?: (error: Error, info: {
22
+ componentStack: string;
23
+ }) => void;
24
+ resetKeys?: Array<unknown>;
25
+ fallback?: never;
26
+ FallbackComponent?: never;
27
+ fallbackRender: typeof FallbackRender;
28
+ }
29
+ interface ErrorBoundaryPropsWithFallback {
30
+ onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
31
+ onReset?: (...args: Array<unknown>) => void;
32
+ onError?: (error: Error, info: {
33
+ componentStack: string;
34
+ }) => void;
35
+ resetKeys?: Array<unknown>;
36
+ fallback: React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
37
+ FallbackComponent?: never;
38
+ fallbackRender?: never;
39
+ }
40
+ declare type ErrorBoundaryProps = ErrorBoundaryPropsWithFallback | ErrorBoundaryPropsWithComponent | ErrorBoundaryPropsWithRender;
41
+ declare type ErrorBoundaryState = {
42
+ error: Error | null;
43
+ };
44
+ declare class ErrorBoundary extends React.Component<React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>, ErrorBoundaryState> {
45
+ static getDerivedStateFromError(error: Error): {
46
+ error: Error;
47
+ };
48
+ state: ErrorBoundaryState;
49
+ updatedWithError: boolean;
50
+ resetErrorBoundary: (...args: Array<unknown>) => void;
51
+ reset(): void;
52
+ componentDidCatch(error: Error, info: React.ErrorInfo): void;
53
+ componentDidMount(): void;
54
+ componentDidUpdate(prevProps: ErrorBoundaryProps): void;
55
+ render(): React.ReactNode;
56
+ }
57
+ declare function withErrorBoundary<P>(Component: React.ComponentType<P>, errorBoundaryProps: ErrorBoundaryProps): React.ComponentType<P>;
58
+ declare function useErrorHandler(givenError?: unknown): (error: unknown) => void;
59
+ export { ErrorBoundary, withErrorBoundary, useErrorHandler };
60
+ export type { FallbackProps, ErrorBoundaryPropsWithComponent, ErrorBoundaryPropsWithRender, ErrorBoundaryPropsWithFallback, ErrorBoundaryProps, };
@@ -0,0 +1 @@
1
+ export * from "../dist/index";
@@ -7,10 +7,30 @@ var React = require('react');
7
7
 
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
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
+
10
30
  var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
11
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
31
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
12
32
 
13
- var changedArray = function (a, b) {
33
+ var changedArray = function changedArray(a, b) {
14
34
  if (a === void 0) {
15
35
  a = [];
16
36
  }
@@ -76,6 +96,14 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
76
96
  (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
77
97
  };
78
98
 
99
+ _proto.componentDidMount = function componentDidMount() {
100
+ var error = this.state.error;
101
+
102
+ if (error !== null) {
103
+ this.updatedWithError = true;
104
+ }
105
+ };
106
+
79
107
  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
80
108
  var error = this.state.error;
81
109
  var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
@@ -106,17 +134,17 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
106
134
  fallback = _this$props4.fallback;
107
135
 
108
136
  if (error !== null) {
109
- var props = {
137
+ var _props = {
110
138
  error: error,
111
139
  resetErrorBoundary: this.resetErrorBoundary
112
140
  };
113
141
 
114
- if ( /*#__PURE__*/React__default['default'].isValidElement(fallback)) {
142
+ if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
115
143
  return fallback;
116
144
  } else if (typeof fallbackRender === 'function') {
117
- return fallbackRender(props);
145
+ return fallbackRender(_props);
118
146
  } else if (FallbackComponent) {
119
- return /*#__PURE__*/React__default['default'].createElement(FallbackComponent, props);
147
+ return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
120
148
  } else {
121
149
  throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
122
150
  }
@@ -126,12 +154,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
126
154
  };
127
155
 
128
156
  return ErrorBoundary;
129
- }(React__default['default'].Component);
157
+ }(React__namespace.Component);
130
158
 
131
159
  function withErrorBoundary(Component, errorBoundaryProps) {
132
- function Wrapped(props) {
133
- return /*#__PURE__*/React__default['default'].createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__default['default'].createElement(Component, props));
134
- } // Format for display in DevTools
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
135
163
 
136
164
 
137
165
  var name = Component.displayName || Component.name || 'Unknown';
@@ -140,14 +168,19 @@ function withErrorBoundary(Component, errorBoundaryProps) {
140
168
  }
141
169
 
142
170
  function useErrorHandler(givenError) {
143
- var _React$useState = React__default['default'].useState(null),
171
+ var _React$useState = React__namespace.useState(null),
144
172
  error = _React$useState[0],
145
173
  setError = _React$useState[1];
146
174
 
147
- if (givenError) throw givenError;
148
- if (error) throw error;
175
+ if (givenError != null) throw givenError;
176
+ if (error != null) throw error;
149
177
  return setError;
150
178
  }
179
+ /*
180
+ eslint
181
+ @typescript-eslint/no-throw-literal: "off",
182
+ @typescript-eslint/prefer-nullish-coalescing: "off"
183
+ */
151
184
 
152
185
  exports.ErrorBoundary = ErrorBoundary;
153
186
  exports.useErrorHandler = useErrorHandler;
@@ -0,0 +1 @@
1
+ export * from "../dist/index";
@@ -1,7 +1,7 @@
1
1
  import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
2
- import React from 'react';
2
+ import * as React from 'react';
3
3
 
4
- var changedArray = function (a, b) {
4
+ var changedArray = function changedArray(a, b) {
5
5
  if (a === void 0) {
6
6
  a = [];
7
7
  }
@@ -67,6 +67,14 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
67
67
  (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
68
68
  };
69
69
 
70
+ _proto.componentDidMount = function componentDidMount() {
71
+ var error = this.state.error;
72
+
73
+ if (error !== null) {
74
+ this.updatedWithError = true;
75
+ }
76
+ };
77
+
70
78
  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
71
79
  var error = this.state.error;
72
80
  var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
@@ -97,7 +105,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
97
105
  fallback = _this$props4.fallback;
98
106
 
99
107
  if (error !== null) {
100
- var props = {
108
+ var _props = {
101
109
  error: error,
102
110
  resetErrorBoundary: this.resetErrorBoundary
103
111
  };
@@ -105,9 +113,9 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
105
113
  if ( /*#__PURE__*/React.isValidElement(fallback)) {
106
114
  return fallback;
107
115
  } else if (typeof fallbackRender === 'function') {
108
- return fallbackRender(props);
116
+ return fallbackRender(_props);
109
117
  } else if (FallbackComponent) {
110
- return /*#__PURE__*/React.createElement(FallbackComponent, props);
118
+ return /*#__PURE__*/React.createElement(FallbackComponent, _props);
111
119
  } else {
112
120
  throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
113
121
  }
@@ -120,9 +128,9 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
120
128
  }(React.Component);
121
129
 
122
130
  function withErrorBoundary(Component, errorBoundaryProps) {
123
- function Wrapped(props) {
131
+ var Wrapped = function Wrapped(props) {
124
132
  return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props));
125
- } // Format for display in DevTools
133
+ }; // Format for display in DevTools
126
134
 
127
135
 
128
136
  var name = Component.displayName || Component.name || 'Unknown';
@@ -135,9 +143,14 @@ function useErrorHandler(givenError) {
135
143
  error = _React$useState[0],
136
144
  setError = _React$useState[1];
137
145
 
138
- if (givenError) throw givenError;
139
- if (error) throw error;
146
+ if (givenError != null) throw givenError;
147
+ if (error != null) throw error;
140
148
  return setError;
141
149
  }
150
+ /*
151
+ eslint
152
+ @typescript-eslint/no-throw-literal: "off",
153
+ @typescript-eslint/prefer-nullish-coalescing: "off"
154
+ */
142
155
 
143
156
  export { ErrorBoundary, useErrorHandler, withErrorBoundary };
@@ -0,0 +1 @@
1
+ export * from "../dist/index";
@@ -4,17 +4,44 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactErrorBoundary = {}, global.React));
5
5
  }(this, (function (exports, React) { 'use strict';
6
6
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
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);
8
28
 
9
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
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
+ }
10
37
 
11
38
  function _inheritsLoose(subClass, superClass) {
12
39
  subClass.prototype = Object.create(superClass.prototype);
13
40
  subClass.prototype.constructor = subClass;
14
- subClass.__proto__ = superClass;
41
+ _setPrototypeOf(subClass, superClass);
15
42
  }
16
43
 
17
- var changedArray = function (a, b) {
44
+ var changedArray = function changedArray(a, b) {
18
45
  if (a === void 0) {
19
46
  a = [];
20
47
  }
@@ -80,6 +107,14 @@
80
107
  (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
81
108
  };
82
109
 
110
+ _proto.componentDidMount = function componentDidMount() {
111
+ var error = this.state.error;
112
+
113
+ if (error !== null) {
114
+ this.updatedWithError = true;
115
+ }
116
+ };
117
+
83
118
  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
84
119
  var error = this.state.error;
85
120
  var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
@@ -110,17 +145,17 @@
110
145
  fallback = _this$props4.fallback;
111
146
 
112
147
  if (error !== null) {
113
- var props = {
148
+ var _props = {
114
149
  error: error,
115
150
  resetErrorBoundary: this.resetErrorBoundary
116
151
  };
117
152
 
118
- if ( /*#__PURE__*/React__default['default'].isValidElement(fallback)) {
153
+ if ( /*#__PURE__*/React__namespace.isValidElement(fallback)) {
119
154
  return fallback;
120
155
  } else if (typeof fallbackRender === 'function') {
121
- return fallbackRender(props);
156
+ return fallbackRender(_props);
122
157
  } else if (FallbackComponent) {
123
- return /*#__PURE__*/React__default['default'].createElement(FallbackComponent, props);
158
+ return /*#__PURE__*/React__namespace.createElement(FallbackComponent, _props);
124
159
  } else {
125
160
  throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
126
161
  }
@@ -130,12 +165,12 @@
130
165
  };
131
166
 
132
167
  return ErrorBoundary;
133
- }(React__default['default'].Component);
168
+ }(React__namespace.Component);
134
169
 
135
170
  function withErrorBoundary(Component, errorBoundaryProps) {
136
- function Wrapped(props) {
137
- return /*#__PURE__*/React__default['default'].createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__default['default'].createElement(Component, props));
138
- } // Format for display in DevTools
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
139
174
 
140
175
 
141
176
  var name = Component.displayName || Component.name || 'Unknown';
@@ -144,14 +179,19 @@
144
179
  }
145
180
 
146
181
  function useErrorHandler(givenError) {
147
- var _React$useState = React__default['default'].useState(null),
182
+ var _React$useState = React__namespace.useState(null),
148
183
  error = _React$useState[0],
149
184
  setError = _React$useState[1];
150
185
 
151
- if (givenError) throw givenError;
152
- if (error) throw error;
186
+ if (givenError != null) throw givenError;
187
+ if (error != null) throw error;
153
188
  return setError;
154
189
  }
190
+ /*
191
+ eslint
192
+ @typescript-eslint/no-throw-literal: "off",
193
+ @typescript-eslint/prefer-nullish-coalescing: "off"
194
+ */
155
195
 
156
196
  exports.ErrorBoundary = ErrorBoundary;
157
197
  exports.useErrorHandler = useErrorHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"react-error-boundary.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","../src/index.js"],"sourcesContent":["export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null}\nclass ErrorBoundary extends React.Component {\n static getDerivedStateFromError(error) {\n return {error}\n }\n\n state = initialState\n updatedWithError = false\n resetErrorBoundary = (...args) => {\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, info) {\n this.props.onError?.(error, info)\n }\n\n componentDidUpdate(prevProps) {\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 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(Component, errorBoundaryProps) {\n function Wrapped(props) {\n return (\n <ErrorBoundary {...errorBoundaryProps}>\n <Component {...props} />\n </ErrorBoundary>\n )\n }\n\n // Format for display in DevTools\n const name = Component.displayName || Component.name || 'Unknown'\n Wrapped.displayName = `withErrorBoundary(${name})`\n\n return Wrapped\n}\n\nfunction useErrorHandler(givenError) {\n const [error, setError] = React.useState(null)\n if (givenError) throw givenError\n if (error) throw error\n return setError\n}\n\nexport {ErrorBoundary, withErrorBoundary, useErrorHandler}\n"],"names":["_inheritsLoose","subClass","superClass","prototype","Object","create","constructor","__proto__","changedArray","a","b","length","some","item","index","is","initialState","error","ErrorBoundary","state","updatedWithError","resetErrorBoundary","args","props","onReset","reset","getDerivedStateFromError","setState","componentDidCatch","info","onError","componentDidUpdate","prevProps","resetKeys","onResetKeysChange","render","fallbackRender","FallbackComponent","fallback","React","isValidElement","Error","children","Component","withErrorBoundary","errorBoundaryProps","Wrapped","name","displayName","useErrorHandler","givenError","useState","setError"],"mappings":";;;;;;;;;;EAAe,SAASA,cAAT,CAAwBC,QAAxB,EAAkCC,UAAlC,EAA8C;EAC3DD,EAAAA,QAAQ,CAACE,SAAT,GAAqBC,MAAM,CAACC,MAAP,CAAcH,UAAU,CAACC,SAAzB,CAArB;EACAF,EAAAA,QAAQ,CAACE,SAAT,CAAmBG,WAAnB,GAAiCL,QAAjC;EACAA,EAAAA,QAAQ,CAACM,SAAT,GAAqBL,UAArB;EACD;;ECFD,IAAMM,YAAY,GAAG,UAACC,CAAD,EAASC,CAAT;EAAA,MAACD,CAAD;EAACA,IAAAA,CAAD,GAAK,EAAL;EAAA;;EAAA,MAASC,CAAT;EAASA,IAAAA,CAAT,GAAa,EAAb;EAAA;;EAAA,SACnBD,CAAC,CAACE,MAAF,KAAaD,CAAC,CAACC,MAAf,IAAyBF,CAAC,CAACG,IAAF,CAAO,UAACC,IAAD,EAAOC,KAAP;EAAA,WAAiB,CAACV,MAAM,CAACW,EAAP,CAAUF,IAAV,EAAgBH,CAAC,CAACI,KAAD,CAAjB,CAAlB;EAAA,GAAP,CADN;EAAA,CAArB;;EAGA,IAAME,YAAY,GAAG;EAACC,EAAAA,KAAK,EAAE;EAAR,CAArB;;MACMC;;;;;;;;;;;YAKJC,QAAQH;YACRI,mBAAmB;;YACnBC,qBAAqB,YAAa;EAAA;;EAAA,yCAATC,IAAS;EAATA,QAAAA,IAAS;EAAA;;EAChC,YAAKC,KAAL,CAAWC,OAAX,yCAAKD,KAAL,EAAWC,OAAX,oBAAwBF,IAAxB;;EACA,YAAKG,KAAL;EACD;;;;;kBATMC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;EAClC,eAAOA,QAAP;EACD,OAFD,MAEO,IAAI,OAAOF,cAAP,KAA0B,UAA9B,EAA0C;EAC/C,eAAOA,cAAc,CAACb,KAAD,CAArB;EACD,OAFM,MAEA,IAAIc,iBAAJ,EAAuB;EAC5B,4BAAOE,wCAAC,iBAAD,EAAuBhB,KAAvB,CAAP;EACD,OAFM,MAEA;EACL,cAAM,IAAIkB,KAAJ,CACJ,4FADI,CAAN;EAGD;EACF;;EAED,WAAO,KAAKlB,KAAL,CAAWmB,QAAlB;EACD;;;IAjEyBH,yBAAK,CAACI;;EAoElC,SAASC,iBAAT,CAA2BD,SAA3B,EAAsCE,kBAAtC,EAA0D;EACxD,WAASC,OAAT,CAAiBvB,KAAjB,EAAwB;EACtB,wBACEgB,wCAAC,aAAD,EAAmBM,kBAAnB,eACEN,wCAAC,SAAD,EAAehB,KAAf,CADF,CADF;EAKD,GAPuD;;;EAUxD,MAAMwB,IAAI,GAAGJ,SAAS,CAACK,WAAV,IAAyBL,SAAS,CAACI,IAAnC,IAA2C,SAAxD;EACAD,EAAAA,OAAO,CAACE,WAAR,0BAA2CD,IAA3C;EAEA,SAAOD,OAAP;EACD;;EAED,SAASG,eAAT,CAAyBC,UAAzB,EAAqC;EAAA,wBACTX,yBAAK,CAACY,QAAN,CAAe,IAAf,CADS;EAAA,MAC5BlC,KAD4B;EAAA,MACrBmC,QADqB;;EAEnC,MAAIF,UAAJ,EAAgB,MAAMA,UAAN;EAChB,MAAIjC,KAAJ,EAAW,MAAMA,KAAN;EACX,SAAOmC,QAAP;EACD;;;;;;;;;;;;;;"}
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,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4BAAOE,+BAAC,iBAAD,EAAuBjB,MAAvB,CAAP;EACD,OAFM,MAEA;EACL,cAAM,IAAImB,KAAJ,CACJ,4FADI,CAAN;EAGD;EACF;;EAED,WAAO,KAAKnB,KAAL,CAAWoB,QAAlB;EACD;;;IA7EyBH,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;;;;;;;;;;;;"}
@@ -0,0 +1 @@
1
+ export * from "../dist/index";
@@ -1,2 +1,2 @@
1
- !function(r,e){"object"==typeof exports&&"undefined"!=typeof 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){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=t(e);var o={error:null},a=function(r){var e,t;function a(){for(var e,t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];return(e=r.call.apply(r,[this].concat(n))||this).state=o,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=a).prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t,a.getDerivedStateFromError=function(r){return{error:r}};var i=a.prototype;return i.reset=function(){this.updatedWithError=!1,this.setState(o)},i.componentDidCatch=function(r,e){var t,n;null==(t=(n=this.props).onError)||t.call(n,r,e)},i.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},i.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.default.isValidElement(a))return a;if("function"==typeof t)return t(i);if(o)return n.default.createElement(o,i);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},a}(n.default.Component);r.ErrorBoundary=a,r.useErrorHandler=function(r){var e=n.default.useState(null),t=e[0],o=e[1];if(r)throw r;if(t)throw t;return o},r.withErrorBoundary=function(r,e){function t(t){return n.default.createElement(a,e,n.default.createElement(r,t))}var o=r.displayName||r.name||"Unknown";return t.displayName="withErrorBoundary("+o+")",t},Object.defineProperty(r,"__esModule",{value:!0})}));
1
+ !function(r,e){"object"==typeof exports&&"undefined"!=typeof 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
2
  //# sourceMappingURL=react-error-boundary.umd.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-error-boundary.umd.min.js","sources":["../src/index.js","../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"],"sourcesContent":["import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null}\nclass ErrorBoundary extends React.Component {\n static getDerivedStateFromError(error) {\n return {error}\n }\n\n state = initialState\n updatedWithError = false\n resetErrorBoundary = (...args) => {\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, info) {\n this.props.onError?.(error, info)\n }\n\n componentDidUpdate(prevProps) {\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 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(Component, errorBoundaryProps) {\n function Wrapped(props) {\n return (\n <ErrorBoundary {...errorBoundaryProps}>\n <Component {...props} />\n </ErrorBoundary>\n )\n }\n\n // Format for display in DevTools\n const name = Component.displayName || Component.name || 'Unknown'\n Wrapped.displayName = `withErrorBoundary(${name})`\n\n return Wrapped\n}\n\nfunction useErrorHandler(givenError) {\n const [error, setError] = React.useState(null)\n if (givenError) throw givenError\n if (error) throw error\n return setError\n}\n\nexport {ErrorBoundary, withErrorBoundary, useErrorHandler}\n","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}"],"names":["initialState","error","ErrorBoundary","subClass","superClass","state","updatedWithError","resetErrorBoundary","args","props","onReset","reset","prototype","Object","create","constructor","__proto__","getDerivedStateFromError","setState","componentDidCatch","info","onError","componentDidUpdate","prevProps","a","b","this","resetKeys","length","some","item","index","is","onResetKeysChange","render","fallbackRender","FallbackComponent","fallback","React","isValidElement","Error","children","Component","givenError","useState","setError","errorBoundaryProps","Wrapped","name","displayName"],"mappings":"gXAEA,IAGMA,EAAe,CAACC,MAAO,MACvBC,cCNS,IAAwBC,EAAUC,0IDW/CC,MAAQL,IACRM,kBAAmB,IACnBC,mBAAqB,wCAAIC,2BAAAA,0BAClBC,MAAMC,cAAND,OAAMC,gBAAaF,KACnBG,WCfwCP,KAAVD,KAC5BS,UAAYC,OAAOC,OAAOV,EAAWQ,WAC9CT,EAASS,UAAUG,YAAcZ,EACjCA,EAASa,UAAYZ,IDIda,yBAAP,SAAgChB,SACvB,CAACA,MAAAA,+BAUVU,MAAA,gBACOL,kBAAmB,OACnBY,SAASlB,MAGhBmB,kBAAA,SAAkBlB,EAAOmB,4BAClBX,OAAMY,mBAAUpB,EAAOmB,MAG9BE,mBAAA,SAAmBC,WAzBCC,EAAQC,EA0BnBxB,EAASyB,KAAKrB,MAAdJ,MACA0B,EAAaD,KAAKjB,MAAlBkB,UAQO,OAAV1B,GAAmByB,KAAKpB,iBAKd,OAAVL,cAxCcuB,EAwCiBD,EAAUI,aAxC3BH,EAAI,cAAIC,EAwC8BE,KAxC9BF,EAAI,IAChCD,EAAEI,SAAWH,EAAEG,QAAUJ,EAAEK,MAAK,SAACC,EAAMC,UAAWlB,OAAOmB,GAAGF,EAAML,EAAEM,2BAwC3DtB,OAAMwB,6BAAoBV,EAAUI,UAAWA,QAC/ChB,cANAL,kBAAmB,KAU5B4B,OAAA,eACSjC,EAASyB,KAAKrB,MAAdJ,QAC+CyB,KAAKjB,MAApD0B,IAAAA,eAAgBC,IAAAA,kBAAmBC,IAAAA,YAE5B,OAAVpC,EAAgB,KACZQ,EAAQ,CACZR,MAAAA,EACAM,mBAAoBmB,KAAKnB,uBAEvB+B,UAAMC,eAAeF,UAChBA,EACF,GAA8B,mBAAnBF,SACTA,EAAe1B,GACjB,GAAI2B,SACFE,wBAACF,EAAsB3B,SAExB,IAAI+B,MACR,qGAKCd,KAAKjB,MAAMgC,aAhEMH,UAAMI,+CAoFlC,SAAyBC,SACGL,UAAMM,SAAS,MAAlC3C,OAAO4C,UACVF,EAAY,MAAMA,KAClB1C,EAAO,MAAMA,SACV4C,uBApBT,SAA2BH,EAAWI,YAC3BC,EAAQtC,UAEb6B,wBAACpC,EAAkB4C,EACjBR,wBAACI,EAAcjC,QAMfuC,EAAON,EAAUO,aAAeP,EAAUM,MAAQ,iBACxDD,EAAQE,iCAAmCD,MAEpCD"}
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,YAE5B,OAAVnC,EAAgB,KACZQ,EAAQ,CACZR,MAAAA,EACAM,mBAAoBc,KAAKd,uBAEvB8B,EAAMC,eAAeF,UAChBA,EACF,GAA8B,mBAAnBF,SACTA,EAAezB,GACjB,GAAI0B,SACFE,gBAACF,EAAsB1B,SAExB,IAAI8B,MACR,qGAKClB,KAAKZ,MAAM+B,aA5EMH,EAAMI,+CAmGlC,SAAyBC,SACGL,EAAMM,SAAkB,MAA3C1C,OAAO2C,UACI,MAAdF,EAAoB,MAAMA,KACjB,MAATzC,EAAe,MAAMA,SAClB2C,uBAvBT,SACEH,EACAI,OAEMC,EAAkC,SAAArC,UAEpC4B,gBAACnC,EAAkB2C,EACjBR,gBAACI,EAAchC,KAMfsC,EAAON,EAAUO,aAAeP,EAAUM,MAAQ,iBACxDD,EAAQE,iCAAmCD,MAEpCD"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "react-error-boundary",
3
- "version": "3.0.2",
3
+ "version": "3.1.3",
4
4
  "description": "Simple reusable React error boundary component",
5
5
  "main": "dist/react-error-boundary.cjs.js",
6
6
  "module": "dist/react-error-boundary.esm.js",
7
7
  "browser": "dist/react-error-boundary.umd.js",
8
- "types": "index.d.ts",
8
+ "types": "dist/index.d.ts",
9
9
  "sideEffects": false,
10
10
  "keywords": [
11
11
  "react",
@@ -27,8 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/bvaughn/react-error-boundary#readme",
29
29
  "files": [
30
- "dist",
31
- "index.d.ts"
30
+ "dist"
32
31
  ],
33
32
  "scripts": {
34
33
  "build": "kcd-scripts build --bundle",
@@ -36,19 +35,22 @@
36
35
  "setup": "npm install && npm run validate -s",
37
36
  "test": "kcd-scripts test",
38
37
  "test:update": "npm test -- --updateSnapshot --coverage",
38
+ "typecheck": "kcd-scripts typecheck",
39
39
  "validate": "kcd-scripts validate"
40
40
  },
41
41
  "dependencies": {
42
- "@babel/runtime": "^7.11.2"
42
+ "@babel/runtime": "^7.12.5"
43
43
  },
44
44
  "devDependencies": {
45
- "@testing-library/jest-dom": "^5.11.4",
46
- "@testing-library/react": "^11.0.2",
47
- "@testing-library/user-event": "^12.1.4",
48
- "kcd-scripts": "^6.3.0",
49
- "react": "^16.13.1",
50
- "react-dom": "^16.13.1",
51
- "typescript": "^4.0.2"
45
+ "@testing-library/jest-dom": "^5.11.6",
46
+ "@testing-library/react": "^11.2.2",
47
+ "@testing-library/user-event": "^12.2.2",
48
+ "@types/jest": "^26.0.15",
49
+ "@types/react": "^17.0.0",
50
+ "kcd-scripts": "^7.3.0",
51
+ "react": "^17.0.1",
52
+ "react-dom": "^17.0.1",
53
+ "typescript": "^4.1.2"
52
54
  },
53
55
  "peerDependencies": {
54
56
  "react": ">=16.13.1"
package/index.d.ts DELETED
@@ -1,46 +0,0 @@
1
- import * as React from 'react'
2
-
3
- export interface FallbackProps {
4
- error?: Error
5
- resetErrorBoundary: () => void
6
- }
7
-
8
- export interface ErrorBoundaryPropsWithComponent {
9
- onResetKeysChange?: (prevResetKeys: Array<any>, resetKeys: Array<any>) => void
10
- onReset?: () => void
11
- onError?: (error: Error, info: { componentStack: string }) => void
12
- resetKeys?: Array<any>
13
- FallbackComponent: React.ComponentType<FallbackProps>
14
- }
15
-
16
- export interface ErrorBoundaryPropsWithRender {
17
- onResetKeysChange?: (prevResetKeys: Array<any>, resetKeys: Array<any>) => void
18
- onReset?: () => void
19
- onError?: (error: Error, info: { componentStack: string }) => void
20
- resetKeys?: Array<any>
21
- fallbackRender: (props: FallbackProps) => React.ReactElement<any, any> | null
22
- }
23
-
24
- export interface ErrorBoundaryPropsWithFallback {
25
- onResetKeysChange?: (prevResetKeys: Array<any>, resetKeys: Array<any>) => void
26
- onReset?: () => void
27
- onError?: (error: Error, info: { componentStack: string }) => void
28
- resetKeys?: Array<any>
29
- fallback: React.ReactElement<any, any> | null
30
- }
31
-
32
- export type ErrorBoundaryProps =
33
- | ErrorBoundaryPropsWithFallback
34
- | ErrorBoundaryPropsWithComponent
35
- | ErrorBoundaryPropsWithRender
36
-
37
- export class ErrorBoundary extends React.Component<ErrorBoundaryProps> {}
38
-
39
- export function withErrorBoundary<P>(
40
- ComponentToDecorate: React.ComponentType<P>,
41
- errorBoundaryProps: ErrorBoundaryProps,
42
- ): React.ComponentType<P>
43
-
44
- export function useErrorHandler<P = Error>(
45
- error?: P,
46
- ): React.Dispatch<React.SetStateAction<P>>