react-error-boundary 3.0.0 → 3.1.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.
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 -->
@@ -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,54 @@
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
+ FallbackComponent: React.ComponentType<FallbackProps>;
14
+ }
15
+ declare function FallbackRender(props: FallbackProps): React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
16
+ interface ErrorBoundaryPropsWithRender {
17
+ onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
18
+ onReset?: (...args: Array<unknown>) => void;
19
+ onError?: (error: Error, info: {
20
+ componentStack: string;
21
+ }) => void;
22
+ resetKeys?: Array<unknown>;
23
+ fallbackRender: typeof FallbackRender;
24
+ }
25
+ interface ErrorBoundaryPropsWithFallback {
26
+ onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
27
+ onReset?: (...args: Array<unknown>) => void;
28
+ onError?: (error: Error, info: {
29
+ componentStack: string;
30
+ }) => void;
31
+ resetKeys?: Array<unknown>;
32
+ fallback: React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
33
+ }
34
+ declare type ErrorBoundaryProps = ErrorBoundaryPropsWithFallback | ErrorBoundaryPropsWithComponent | ErrorBoundaryPropsWithRender;
35
+ declare type ErrorBoundaryState = {
36
+ error: Error | null;
37
+ };
38
+ declare class ErrorBoundary extends React.Component<React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>, ErrorBoundaryState> {
39
+ static getDerivedStateFromError(error: Error): {
40
+ error: Error;
41
+ };
42
+ state: ErrorBoundaryState;
43
+ updatedWithError: boolean;
44
+ resetErrorBoundary: (...args: Array<unknown>) => void;
45
+ reset(): void;
46
+ componentDidCatch(error: Error, info: React.ErrorInfo): void;
47
+ componentDidMount(): void;
48
+ componentDidUpdate(prevProps: ErrorBoundaryProps): void;
49
+ render(): {} | null | undefined;
50
+ }
51
+ declare function withErrorBoundary<P>(Component: React.ComponentType<P>, errorBoundaryProps: ErrorBoundaryProps): React.ComponentType<P>;
52
+ declare function useErrorHandler<P = Error>(givenError?: P | null | undefined): React.Dispatch<React.SetStateAction<P | null>>;
53
+ export { ErrorBoundary, withErrorBoundary, useErrorHandler };
54
+ export type { FallbackProps, ErrorBoundaryPropsWithComponent, ErrorBoundaryPropsWithRender, ErrorBoundaryPropsWithFallback, ErrorBoundaryProps, };
@@ -0,0 +1 @@
1
+ export * from "../dist/index";
@@ -8,9 +8,8 @@ var React = require('react');
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
9
 
10
10
  var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
11
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
11
 
13
- var changedArray = function (a, b) {
12
+ var changedArray = function changedArray(a, b) {
14
13
  if (a === void 0) {
15
14
  a = [];
16
15
  }
@@ -76,6 +75,14 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
76
75
  (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
77
76
  };
78
77
 
78
+ _proto.componentDidMount = function componentDidMount() {
79
+ var error = this.state.error;
80
+
81
+ if (error !== null) {
82
+ this.updatedWithError = true;
83
+ }
84
+ };
85
+
79
86
  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
80
87
  var error = this.state.error;
81
88
  var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
@@ -99,24 +106,25 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
99
106
  };
100
107
 
101
108
  _proto.render = function render() {
102
- var error = this.state.error;
109
+ var error = this.state.error; // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence)
110
+
103
111
  var _this$props4 = this.props,
104
112
  fallbackRender = _this$props4.fallbackRender,
105
113
  FallbackComponent = _this$props4.FallbackComponent,
106
114
  fallback = _this$props4.fallback;
107
115
 
108
116
  if (error !== null) {
109
- var props = {
117
+ var _props = {
110
118
  error: error,
111
119
  resetErrorBoundary: this.resetErrorBoundary
112
120
  };
113
121
 
114
- if ( /*#__PURE__*/React__default['default'].isValidElement(fallback)) {
122
+ if ( /*#__PURE__*/React.isValidElement(fallback)) {
115
123
  return fallback;
116
124
  } else if (typeof fallbackRender === 'function') {
117
- return fallbackRender(props);
125
+ return fallbackRender(_props);
118
126
  } else if (FallbackComponent) {
119
- return /*#__PURE__*/React__default['default'].createElement(FallbackComponent, props);
127
+ return /*#__PURE__*/React.createElement(FallbackComponent, _props);
120
128
  } else {
121
129
  throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
122
130
  }
@@ -126,12 +134,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
126
134
  };
127
135
 
128
136
  return ErrorBoundary;
129
- }(React__default['default'].Component);
137
+ }(React.Component);
130
138
 
131
139
  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
140
+ var Wrapped = function Wrapped(props) {
141
+ return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props));
142
+ }; // Format for display in DevTools
135
143
 
136
144
 
137
145
  var name = Component.displayName || Component.name || 'Unknown';
@@ -140,7 +148,7 @@ function withErrorBoundary(Component, errorBoundaryProps) {
140
148
  }
141
149
 
142
150
  function useErrorHandler(givenError) {
143
- var _React$useState = React__default['default'].useState(null),
151
+ var _React$useState = React.useState(null),
144
152
  error = _React$useState[0],
145
153
  setError = _React$useState[1];
146
154
 
@@ -148,6 +156,11 @@ function useErrorHandler(givenError) {
148
156
  if (error) throw error;
149
157
  return setError;
150
158
  }
159
+ /*
160
+ eslint
161
+ @typescript-eslint/no-throw-literal: "off",
162
+ @typescript-eslint/prefer-nullish-coalescing: "off"
163
+ */
151
164
 
152
165
  exports.ErrorBoundary = ErrorBoundary;
153
166
  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 { isValidElement, createElement, Component, useState } 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
@@ -90,24 +98,25 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
90
98
  };
91
99
 
92
100
  _proto.render = function render() {
93
- var error = this.state.error;
101
+ var error = this.state.error; // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence)
102
+
94
103
  var _this$props4 = this.props,
95
104
  fallbackRender = _this$props4.fallbackRender,
96
105
  FallbackComponent = _this$props4.FallbackComponent,
97
106
  fallback = _this$props4.fallback;
98
107
 
99
108
  if (error !== null) {
100
- var props = {
109
+ var _props = {
101
110
  error: error,
102
111
  resetErrorBoundary: this.resetErrorBoundary
103
112
  };
104
113
 
105
- if ( /*#__PURE__*/React.isValidElement(fallback)) {
114
+ if ( /*#__PURE__*/isValidElement(fallback)) {
106
115
  return fallback;
107
116
  } else if (typeof fallbackRender === 'function') {
108
- return fallbackRender(props);
117
+ return fallbackRender(_props);
109
118
  } else if (FallbackComponent) {
110
- return /*#__PURE__*/React.createElement(FallbackComponent, props);
119
+ return /*#__PURE__*/createElement(FallbackComponent, _props);
111
120
  } else {
112
121
  throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
113
122
  }
@@ -117,12 +126,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
117
126
  };
118
127
 
119
128
  return ErrorBoundary;
120
- }(React.Component);
129
+ }(Component);
121
130
 
122
131
  function withErrorBoundary(Component, errorBoundaryProps) {
123
- function Wrapped(props) {
124
- return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props));
125
- } // Format for display in DevTools
132
+ var Wrapped = function Wrapped(props) {
133
+ return /*#__PURE__*/createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/createElement(Component, props));
134
+ }; // Format for display in DevTools
126
135
 
127
136
 
128
137
  var name = Component.displayName || Component.name || 'Unknown';
@@ -131,7 +140,7 @@ function withErrorBoundary(Component, errorBoundaryProps) {
131
140
  }
132
141
 
133
142
  function useErrorHandler(givenError) {
134
- var _React$useState = React.useState(null),
143
+ var _React$useState = useState(null),
135
144
  error = _React$useState[0],
136
145
  setError = _React$useState[1];
137
146
 
@@ -139,5 +148,10 @@ function useErrorHandler(givenError) {
139
148
  if (error) throw error;
140
149
  return setError;
141
150
  }
151
+ /*
152
+ eslint
153
+ @typescript-eslint/no-throw-literal: "off",
154
+ @typescript-eslint/prefer-nullish-coalescing: "off"
155
+ */
142
156
 
143
157
  export { ErrorBoundary, useErrorHandler, withErrorBoundary };
@@ -0,0 +1 @@
1
+ export * from "../dist/index";
@@ -4,17 +4,22 @@
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 _setPrototypeOf(o, p) {
8
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
9
+ o.__proto__ = p;
10
+ return o;
11
+ };
8
12
 
9
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
+ return _setPrototypeOf(o, p);
14
+ }
10
15
 
11
16
  function _inheritsLoose(subClass, superClass) {
12
17
  subClass.prototype = Object.create(superClass.prototype);
13
18
  subClass.prototype.constructor = subClass;
14
- subClass.__proto__ = superClass;
19
+ _setPrototypeOf(subClass, superClass);
15
20
  }
16
21
 
17
- var changedArray = function (a, b) {
22
+ var changedArray = function changedArray(a, b) {
18
23
  if (a === void 0) {
19
24
  a = [];
20
25
  }
@@ -80,6 +85,14 @@
80
85
  (_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info);
81
86
  };
82
87
 
88
+ _proto.componentDidMount = function componentDidMount() {
89
+ var error = this.state.error;
90
+
91
+ if (error !== null) {
92
+ this.updatedWithError = true;
93
+ }
94
+ };
95
+
83
96
  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
84
97
  var error = this.state.error;
85
98
  var resetKeys = this.props.resetKeys; // There's an edge case where if the thing that triggered the error
@@ -103,24 +116,25 @@
103
116
  };
104
117
 
105
118
  _proto.render = function render() {
106
- var error = this.state.error;
119
+ var error = this.state.error; // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence)
120
+
107
121
  var _this$props4 = this.props,
108
122
  fallbackRender = _this$props4.fallbackRender,
109
123
  FallbackComponent = _this$props4.FallbackComponent,
110
124
  fallback = _this$props4.fallback;
111
125
 
112
126
  if (error !== null) {
113
- var props = {
127
+ var _props = {
114
128
  error: error,
115
129
  resetErrorBoundary: this.resetErrorBoundary
116
130
  };
117
131
 
118
- if ( /*#__PURE__*/React__default['default'].isValidElement(fallback)) {
132
+ if ( /*#__PURE__*/React.isValidElement(fallback)) {
119
133
  return fallback;
120
134
  } else if (typeof fallbackRender === 'function') {
121
- return fallbackRender(props);
135
+ return fallbackRender(_props);
122
136
  } else if (FallbackComponent) {
123
- return /*#__PURE__*/React__default['default'].createElement(FallbackComponent, props);
137
+ return /*#__PURE__*/React.createElement(FallbackComponent, _props);
124
138
  } else {
125
139
  throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
126
140
  }
@@ -130,12 +144,12 @@
130
144
  };
131
145
 
132
146
  return ErrorBoundary;
133
- }(React__default['default'].Component);
147
+ }(React.Component);
134
148
 
135
149
  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
150
+ var Wrapped = function Wrapped(props) {
151
+ return /*#__PURE__*/React.createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React.createElement(Component, props));
152
+ }; // Format for display in DevTools
139
153
 
140
154
 
141
155
  var name = Component.displayName || Component.name || 'Unknown';
@@ -144,7 +158,7 @@
144
158
  }
145
159
 
146
160
  function useErrorHandler(givenError) {
147
- var _React$useState = React__default['default'].useState(null),
161
+ var _React$useState = React.useState(null),
148
162
  error = _React$useState[0],
149
163
  setError = _React$useState[1];
150
164
 
@@ -152,6 +166,11 @@
152
166
  if (error) throw error;
153
167
  return setError;
154
168
  }
169
+ /*
170
+ eslint
171
+ @typescript-eslint/no-throw-literal: "off",
172
+ @typescript-eslint/prefer-nullish-coalescing: "off"
173
+ */
155
174
 
156
175
  exports.ErrorBoundary = ErrorBoundary;
157
176
  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,C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ACI;;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 FallbackComponent: React.ComponentType<FallbackProps>\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 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}\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 // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence)\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 as typeof 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<P = Error>(\n givenError?: P | null | undefined,\n): React.Dispatch<React.SetStateAction<P | null>> {\n const [error, setError] = React.useState<P | null>(null)\n if (givenError) throw givenError\n if (error) 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","React.createElement","Error","children","withErrorBoundary","Component","errorBoundaryProps","Wrapped","name","displayName","useErrorHandler","givenError","setError"],"mappings":";;;;;;EAAe,SAASA,eAAT,CAAyBC,CAAzB,EAA4BC,CAA5B,EAA+B;EAC5CF,EAAAA,eAAe,GAAGG,MAAM,CAACC,cAAP,IAAyB,SAASJ,eAAT,CAAyBC,CAAzB,EAA4BC,CAA5B,EAA+B;EACxED,IAAAA,CAAC,CAACI,SAAF,GAAcH,CAAd;EACA,WAAOD,CAAP;EACD,GAHD;;EAKA,SAAOD,eAAe,CAACC,CAAD,EAAIC,CAAJ,CAAtB;EACD;;ECNc,SAASI,cAAT,CAAwBC,QAAxB,EAAkCC,UAAlC,EAA8C;EAC3DD,EAAAA,QAAQ,CAACE,SAAT,GAAqBN,MAAM,CAACO,MAAP,CAAcF,UAAU,CAACC,SAAzB,CAArB;EACAF,EAAAA,QAAQ,CAACE,SAAT,CAAmBE,WAAnB,GAAiCJ,QAAjC;EACAH,EAAAA,eAAc,CAACG,QAAD,EAAWC,UAAX,CAAd;EACD;;ECHD,IAAMI,YAAY,GAAG,SAAfA,YAAe,CAACC,CAAD,EAAyBC,CAAzB;EAAA,MAACD,CAAD;EAACA,IAAAA,CAAD,GAAqB,EAArB;EAAA;;EAAA,MAAyBC,CAAzB;EAAyBA,IAAAA,CAAzB,GAA6C,EAA7C;EAAA;;EAAA,SACnBD,CAAC,CAACE,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CADwB;;;EAUxB,MAAMyB,IAAI,GAAGH,SAAS,CAACI,WAAV,IAAyBJ,SAAS,CAACG,IAAnC,IAA2C,SAAxD;EACAD,EAAAA,OAAO,CAACE,WAAR,0BAA2CD,IAA3C;EAEA,SAAOD,OAAP;EACD;;EAED,SAASG,eAAT,CACEC,UADF,EAEkD;EAAA,wBACtBX,cAAA,CAAyB,IAAzB,CADsB;EAAA,MACzCvB,KADyC;EAAA,MAClCmC,QADkC;;EAEhD,MAAID,UAAJ,EAAgB,MAAMA,UAAN;EAChB,MAAIlC,KAAJ,EAAW,MAAMA,KAAN;EACX,SAAOmC,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,e){return(t=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}var n={error:null},o=function(r){var o,a;function i(){for(var e,t=arguments.length,o=new Array(t),a=0;a<t;a++)o[a]=arguments[a];return(e=r.call.apply(r,[this].concat(o))||this).state=n,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}a=r,(o=i).prototype=Object.create(a.prototype),o.prototype.constructor=o,t(o,a),i.getDerivedStateFromError=function(r){return{error:r}};var u=i.prototype;return u.reset=function(){this.updatedWithError=!1,this.setState(n)},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,t=this.props,n=t.fallbackRender,o=t.FallbackComponent,a=t.fallback;if(null!==r){var i={error:r,resetErrorBoundary:this.resetErrorBoundary};if(e.isValidElement(a))return a;if("function"==typeof n)return n(i);if(o)return e.createElement(o,i);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},i}(e.Component);r.ErrorBoundary=o,r.useErrorHandler=function(r){var t=e.useState(null),n=t[0],o=t[1];if(r)throw r;if(n)throw n;return o},r.withErrorBoundary=function(r,t){var n=function(n){return e.createElement(o,t,e.createElement(r,n))},a=r.displayName||r.name||"Unknown";return n.displayName="withErrorBoundary("+a+")",n},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","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oFlC,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 FallbackComponent: React.ComponentType<FallbackProps>\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 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}\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 // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence)\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 as typeof 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<P = Error>(\n givenError?: P | null | undefined,\n): React.Dispatch<React.SetStateAction<P | null>> {\n const [error, setError] = React.useState<P | null>(null)\n if (givenError) throw givenError\n if (error) 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","React.createElement","Error","children","giv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,mBAAoBc,KAAKd,uBAEvB8B,iBAAqBD,UAChBA,EACF,GAA8B,mBAAnBF,SACRA,EAAyCzB,GAC5C,GAAI0B,SACFG,gBAACH,EAAsB1B,SAExB,IAAI8B,MACR,qGAKClB,KAAKZ,MAAM+B,aA5EMH,iDAmG5B,SACEI,SAE0BJ,WAAyB,MAA5CpC,OAAOyC,UACVD,EAAY,MAAMA,KAClBxC,EAAO,MAAMA,SACVyC,uBAzBT,SACEC,EACAC,OAEMC,EAAkC,SAAApC,UAEpC6B,gBAACpC,EAAkB0C,EACjBN,gBAACK,EAAclC,KAMfqC,EAAOH,EAAUI,aAAeJ,EAAUG,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.0",
3
+ "version": "3.1.1",
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,47 +0,0 @@
1
- import * as React from 'react'
2
-
3
- export interface FallbackProps {
4
- error?: Error
5
- componentStack?: string
6
- resetErrorBoundary: () => void
7
- }
8
-
9
- export interface ErrorBoundaryPropsWithComponent {
10
- onResetKeysChange?: (prevResetKeys: Array<any>, resetKeys: Array<any>) => void
11
- onReset?: () => void
12
- onError?: (error: Error, componentStack: string) => void
13
- resetKeys?: Array<any>
14
- FallbackComponent: React.ComponentType<FallbackProps>
15
- }
16
-
17
- export interface ErrorBoundaryPropsWithRender {
18
- onResetKeysChange?: (prevResetKeys: Array<any>, resetKeys: Array<any>) => void
19
- onReset?: () => void
20
- onError?: (error: Error, componentStack: string) => void
21
- resetKeys?: Array<any>
22
- fallbackRender: (props: FallbackProps) => React.ReactElement<any, any> | null
23
- }
24
-
25
- export interface ErrorBoundaryPropsWithFallback {
26
- onResetKeysChange?: (prevResetKeys: Array<any>, resetKeys: Array<any>) => void
27
- onReset?: () => void
28
- onError?: (error: Error, componentStack: string) => void
29
- resetKeys?: Array<any>
30
- fallback: React.ReactElement<any, any> | null
31
- }
32
-
33
- export type ErrorBoundaryProps =
34
- | ErrorBoundaryPropsWithFallback
35
- | ErrorBoundaryPropsWithComponent
36
- | ErrorBoundaryPropsWithRender
37
-
38
- export class ErrorBoundary extends React.Component<ErrorBoundaryProps> {}
39
-
40
- export function withErrorBoundary<P>(
41
- ComponentToDecorate: React.ComponentType<P>,
42
- errorBoundaryProps: ErrorBoundaryProps,
43
- ): React.ComponentType<P>
44
-
45
- export function useErrorHandler<P = Error>(
46
- error?: P,
47
- ): React.Dispatch<React.SetStateAction<P>>