react-error-boundary 4.0.1 → 4.0.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 +22 -2
- package/dist/react-error-boundary.d.ts +3 -3
- package/dist/react-error-boundary.d.ts.map +1 -1
- package/dist/react-error-boundary.js +7 -5
- package/dist/react-error-boundary.js.map +1 -1
- package/dist/react-error-boundary.module.js +8 -6
- package/dist/react-error-boundary.module.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# react-error-boundary
|
|
2
2
|
|
|
3
|
-
Reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component. Supports all React renderers (including React DOM and React Native).
|
|
3
|
+
Reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component. Supports all React renderers (including React DOM and React Native).
|
|
4
4
|
|
|
5
5
|
### If you like this project, [buy me a coffee](http://givebrian.coffee/).
|
|
6
6
|
|
|
@@ -19,9 +19,13 @@ yarn add react-error-boundary
|
|
|
19
19
|
### `ErrorBoundary` component
|
|
20
20
|
Wrap an `ErrorBoundary` around other React components to "catch" errors and render a fallback UI. The component supports several ways to render a fallback (shown below).
|
|
21
21
|
|
|
22
|
+
> **Note** `ErrorBoundary` is a _client_ component. You can only pass props to it that are serializeable or use it in files that have a `"use client";` directive.
|
|
23
|
+
|
|
22
24
|
#### `ErrorBoundary` with `fallback` prop
|
|
23
25
|
The simplest way to render a default "something went wrong" type error message.
|
|
24
26
|
```js
|
|
27
|
+
"use client";
|
|
28
|
+
|
|
25
29
|
import { ErrorBoundary } from "react-error-boundary";
|
|
26
30
|
|
|
27
31
|
<ErrorBoundary fallback={<div>Something went wrong</div>}>
|
|
@@ -31,6 +35,8 @@ import { ErrorBoundary } from "react-error-boundary";
|
|
|
31
35
|
#### `ErrorBoundary` with `fallbackRender` prop
|
|
32
36
|
["Render prop"](https://react.dev/reference/react/Children#calling-a-render-prop-to-customize-rendering) function responsible for returning a fallback UI based on a thrown value.
|
|
33
37
|
```js
|
|
38
|
+
"use client";
|
|
39
|
+
|
|
34
40
|
import { ErrorBoundary } from "react-error-boundary";
|
|
35
41
|
|
|
36
42
|
function fallbackRender({ error, resetErrorBoundary }) {
|
|
@@ -56,6 +62,8 @@ function fallbackRender({ error, resetErrorBoundary }) {
|
|
|
56
62
|
#### `ErrorBoundary` with `FallbackComponent` prop
|
|
57
63
|
React component responsible for returning a fallback UI based on a thrown value.
|
|
58
64
|
```js
|
|
65
|
+
"use client";
|
|
66
|
+
|
|
59
67
|
import { ErrorBoundary } from "react-error-boundary";
|
|
60
68
|
|
|
61
69
|
function Fallback({ error, resetErrorBoundary }) {
|
|
@@ -82,6 +90,8 @@ function Fallback({ error, resetErrorBoundary }) {
|
|
|
82
90
|
#### Logging errors with `onError`
|
|
83
91
|
|
|
84
92
|
```js
|
|
93
|
+
"use client";
|
|
94
|
+
|
|
85
95
|
import { ErrorBoundary } from "react-error-boundary";
|
|
86
96
|
|
|
87
97
|
const logError = (error: Error, info: { componentStack: string }) => {
|
|
@@ -105,6 +115,8 @@ React only handles errors thrown during render or during component lifecycle met
|
|
|
105
115
|
This hook can be used to pass those errors to the nearest error boundary:
|
|
106
116
|
|
|
107
117
|
```js
|
|
118
|
+
"use client";
|
|
119
|
+
|
|
108
120
|
import { useErrorBoundary } from "react-error-boundary";
|
|
109
121
|
|
|
110
122
|
function Example() {
|
|
@@ -130,6 +142,8 @@ function Example() {
|
|
|
130
142
|
A fallback component can use this hook to request the nearest error boundary retry the render that original failed.
|
|
131
143
|
|
|
132
144
|
```js
|
|
145
|
+
"use client";
|
|
146
|
+
|
|
133
147
|
import { useErrorBoundary } from "react-error-boundary";
|
|
134
148
|
|
|
135
149
|
function ErrorFallback({ error }) {
|
|
@@ -149,6 +163,8 @@ function ErrorFallback({ error }) {
|
|
|
149
163
|
This package can also be used as a [higher-order component](https://legacy.reactjs.org/docs/higher-order-components.html) that accepts all of the same props as above:
|
|
150
164
|
|
|
151
165
|
```js
|
|
166
|
+
"use client";
|
|
167
|
+
|
|
152
168
|
import {withErrorBoundary} from 'react-error-boundary'
|
|
153
169
|
|
|
154
170
|
const ComponentWithErrorBoundary = withErrorBoundary(ExampleComponent, {
|
|
@@ -160,4 +176,8 @@ const ComponentWithErrorBoundary = withErrorBoundary(ExampleComponent, {
|
|
|
160
176
|
})
|
|
161
177
|
|
|
162
178
|
// Can be rendered as <ComponentWithErrorBoundary {...props} />
|
|
163
|
-
```
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
[This blog post](https://kentcdodds.com/blog/use-react-error-boundary-to-handle-errors-in-react) shows more examples of how this package can be used, although it was written for the [version 3 API](https://github.com/bvaughn/react-error-boundary/releases/tag/v3.1.4).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, ComponentType, FunctionComponent, ReactElement, ReactNode, ErrorInfo, PropsWithChildren, PropsWithRef } from "react";
|
|
1
|
+
import { Component, ComponentType, FunctionComponent, ReactElement, ReactNode, ErrorInfo, PropsWithChildren, PropsWithRef, RefAttributes, ForwardRefExoticComponent, PropsWithoutRef } from "react";
|
|
2
2
|
export type ErrorBoundaryContextType = {
|
|
3
3
|
didCatch: boolean;
|
|
4
4
|
error: any;
|
|
@@ -53,13 +53,13 @@ export class ErrorBoundary extends Component<PropsWithRef<PropsWithChildren<Erro
|
|
|
53
53
|
resetErrorBoundary: (...args: any[]) => void;
|
|
54
54
|
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
55
55
|
componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState): void;
|
|
56
|
-
render():
|
|
56
|
+
render(): ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
57
57
|
}
|
|
58
58
|
export type UseErrorBoundaryApi<Error> = {
|
|
59
59
|
resetBoundary: () => void;
|
|
60
60
|
showBoundary: (error: Error) => void;
|
|
61
61
|
};
|
|
62
62
|
export function useErrorBoundary<Error = any>(): UseErrorBoundaryApi<Error>;
|
|
63
|
-
export function withErrorBoundary<Props extends Object>(
|
|
63
|
+
export function withErrorBoundary<Props extends Object>(component: ComponentType<Props>, errorBoundaryProps: ErrorBoundaryProps): ForwardRefExoticComponent<PropsWithoutRef<Props> & RefAttributes<any>>;
|
|
64
64
|
|
|
65
65
|
//# sourceMappingURL=react-error-boundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAEA,uCAAuC;IACrC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,GAAG,CAAC;IACX,kBAAkB,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEF,OAAO,MAAM,8EACyC,CAAC;ACDvD,gCAAgC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAC;AAEjE,4BAA4B;IAC1B,KAAK,EAAE,GAAG,CAAC;IACX,kBAAkB,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEF,gCAAgC;IAC9B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACnE,OAAO,CAAC,EAAE,CACR,OAAO,EACH;QAAE,MAAM,EAAE,gBAAgB,CAAC;QAAC,IAAI,EAAE,GAAG,EAAE,CAAA;KAAE,GACzC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;QAAC,IAAI,EAAE,GAAG,EAAE,GAAG,SAAS,CAAA;KAAE,KACrE,IAAI,CAAC;IACV,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;CACnB,CAAC;AAEF,8CAA8C,wBAAwB,GAAG;IACvE,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,i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AE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACtC,CAAC;AAEF,iCAAiC,KAAK,GAAG,GAAG,KAAK,oBAAoB,KAAK,CAAC,CAiC1E;AC9BD,kCAAkC,KAAK,SAAS,MAAM,EACpD,SAAS,EAAE,cAAc,KAAK,CAAC,EAC/B,kBAAkB,EAAE,kBAAkB,GACrC,0BAA0B,gBAAgB,KAAK,CAAC,GAAG,cAAc,GAAG,CAAC,CAAC,CAexE","sources":["src/src/ErrorBoundaryContext.ts","src/src/types.ts","src/src/ErrorBoundary.ts","src/src/assertErrorBoundaryContext.ts","src/src/useErrorBoundary.ts","src/src/withErrorBoundary.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,"\"use client\";\n\nexport * from \"./ErrorBoundary\";\nexport * from \"./ErrorBoundaryContext\";\nexport * from \"./useErrorBoundary\";\nexport * from \"./withErrorBoundary\";\n\n// TypeScript types\nexport * from \"./types\";\n"],"names":[],"version":3,"file":"react-error-boundary.d.ts.map"}
|
|
@@ -143,12 +143,13 @@ var $9e88dd86e0bb2944$exports = {};
|
|
|
143
143
|
$parcel$export($9e88dd86e0bb2944$exports, "withErrorBoundary", () => $9e88dd86e0bb2944$export$f0c7a449e0cfaec7);
|
|
144
144
|
|
|
145
145
|
|
|
146
|
-
function $9e88dd86e0bb2944$export$f0c7a449e0cfaec7(
|
|
147
|
-
const Wrapped = (props)=>{
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
function $9e88dd86e0bb2944$export$f0c7a449e0cfaec7(component, errorBoundaryProps) {
|
|
147
|
+
const Wrapped = (0, $8zHUo$react.forwardRef)((props, ref)=>(0, $8zHUo$react.createElement)((0, $6d6d4999e62b3ee0$export$e926676385687eaf), errorBoundaryProps, (0, $8zHUo$react.createElement)(component, {
|
|
148
|
+
...props,
|
|
149
|
+
ref: ref
|
|
150
|
+
})));
|
|
150
151
|
// Format for display in DevTools
|
|
151
|
-
const name =
|
|
152
|
+
const name = component.displayName || component.name || "Unknown";
|
|
152
153
|
Wrapped.displayName = `withErrorBoundary(${name})`;
|
|
153
154
|
return Wrapped;
|
|
154
155
|
}
|
|
@@ -157,6 +158,7 @@ function $9e88dd86e0bb2944$export$f0c7a449e0cfaec7(Component, errorBoundaryProps
|
|
|
157
158
|
var $faefaad95e5fcca0$exports = {};
|
|
158
159
|
|
|
159
160
|
|
|
161
|
+
"use client";
|
|
160
162
|
$parcel$exportWildcard(module.exports, $6d6d4999e62b3ee0$exports);
|
|
161
163
|
$parcel$exportWildcard(module.exports, $4a61716688322eb0$exports);
|
|
162
164
|
$parcel$exportWildcard(module.exports, $3c4937b727a6fcfb$exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;ACAA;;;;ACAA;AAQO,MAAM,4CACX,CAAA,GAAA,0BAAY,EAAmC,IAAI;;;ADIrD,MAAM,qCAAmC;IACvC,UAAU,KAAK;IACf,OAAO,IAAI;AACb;AAEO,MAAM,kDAAsB,CAAA,GAAA,sBAAS,AAAD;IAIzC,QAAQ,mCAAa;IAErB,OAAO,yBAAyB,KAAY,EAAE;QAC5C,OAAO;YAAE,UAAU,IAAI;mBAAE;QAAM;IACjC;IAEA,qBAAqB,CAAC,GAAG,OAAgB;QACvC,MAAM,SAAE,MAAK,EAAE,GAAG,IAAI,CAAC,KAAK;QAE5B,IAAI,UAAU,IAAI,EAAE;YAClB,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG;sBACnB;gBACA,QAAQ;YACV;YAEA,IAAI,CAAC,QAAQ,CAAC;QAChB,CAAC;IACH,EAAE;IAEF,kBAAkB,KAAY,EAAE,IAAe,EAAE;QAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO;IAC9B;IAEA,mBACE,SAA6B,EAC7B,SAA6B,EAC7B;QACA,MAAM,YAAE,SAAQ,EAAE,GAAG,IAAI,CAAC,KAAK;QAC/B,MAAM,aAAE,UAAS,EAAE,GAAG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AAI,IACb,OAAO,MAAM,QAAQ,KAAK,aAC1B,OAAO,MAAM,kBAAkB,KAAK,YAEpC,MAAM,IAAI,MAAM,kCAAkC;IAGpD,OAAO,IAAI;AACb;;;;ADLO,SAAS,4CAA4D;IAC1E,MAAM,UAAU,CAAA,GAAA,uBAAS,EAAE,CAAA,GAAA,yCAAmB;IAE9C,CAAA,GAAA,yCAA0B,AAAD,EAAE;IAE3B,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,qBAAQ,AAAD,EAG9B;QACD,OAAO,IAAI;QACX,UAAU,KAAK;IACjB;IAEA,MAAM,WAAW,CAAA,GAAA,oBAAO,AAAD,EACrB,IAAO,CAAA;YACL,eAAe,IAAM;gBACnB,SAAS;gBACT,SAAS;oBAAE,OAAO,IAAI;oBAAE,UAAU,KAAK;gBAAC;YAC1C;YACA,cAAc,CAAC,QACb,SAAS;2BACP;oBACA,UAAU,IAAI;gBAChB;QACJ,CAAA,GACA;QAAC,SAAS;KAAmB;IAG/B,IAAI,MAAM,QAAQ,EAChB,MAAM,MAAM,KAAK,CAAC;IAGpB,OAAO;AACT;;;;;;AE1CA;;AAIO,SAAS,0CACd,SAA+B,EAC/B,kBAAsC,EAChB;IACtB,MAAM,UAAgC,CAAC,QAAiB;QACtD,OAAO,CAAA,GAAA,0BAAa,AAAD,EACjB,CAAA,GAAA,yCAAa,AAAD,GACZ,oBACA,CAAA,GAAA,0BAAY,EAAE,WAAW;IAE7B;IAEA,iCAAiC;IACjC,MAAM,OAAO,UAAU,WAAW,IAAI,UAAU,IAAI,IAAI;IACxD,QAAQ,WAAW,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IAElD,OAAO;AACT;;;;;","sources":["src/index.ts","src/ErrorBoundary.ts","src/ErrorBoundaryContext.ts","src/useErrorBoundary.ts","src/assertErrorBoundaryContext.ts","src/withErrorBoundary.ts","src/types.ts"],"sourcesContent":["export * from \"./ErrorBoundary\";\nexport * from \"./ErrorBoundaryContext\";\nexport * from \"./useErrorBoundary\";\nexport * from \"./withErrorBoundary\";\n\n// TypeScript types\nexport * from \"./types\";\n","import {\n Component,\n createElement,\n ErrorInfo,\n isValidElement,\n PropsWithChildren,\n PropsWithRef,\n} from \"react\";\nimport { ErrorBoundaryContext } from \"./ErrorBoundaryContext\";\nimport { ErrorBoundaryProps, FallbackProps } from \"./types\";\n\ntype ErrorBoundaryState = { didCatch: boolean; error: any };\n\nconst initialState: ErrorBoundaryState = {\n didCatch: false,\n error: null,\n};\n\nexport class ErrorBoundary extends Component<\n PropsWithRef<PropsWithChildren<ErrorBoundaryProps>>,\n ErrorBoundaryState\n> {\n state = initialState;\n\n static getDerivedStateFromError(error: Error) {\n return { didCatch: true, error };\n }\n\n resetErrorBoundary = (...args: any[]) => {\n const { error } = this.state;\n\n if (error !== null) {\n this.props.onReset?.({\n args,\n reason: \"imperative-api\",\n });\n\n this.setState(initialState);\n }\n };\n\n componentDidCatch(error: Error, info: ErrorInfo) {\n this.props.onError?.(error, info);\n }\n\n componentDidUpdate(\n prevProps: ErrorBoundaryProps,\n prevState: ErrorBoundaryState\n ) {\n const { didCatch } = this.state;\n const { resetKeys } = this.props;\n\n // There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,\n // we'd end up resetting the error boundary immediately.\n // This would likely trigger a second error to be thrown.\n // So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.\n\n if (\n didCatch &&\n prevState.error !== null &&\n hasArrayChanged(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onReset?.({\n next: resetKeys,\n prev: prevProps.resetKeys,\n reason: \"keys\",\n });\n\n this.setState(initialState);\n }\n }\n\n render() {\n const { children, fallbackRender, FallbackComponent, fallback } =\n this.props;\n const { didCatch, error } = this.state;\n\n let childToRender = children;\n\n if (didCatch) {\n const props: FallbackProps = {\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n };\n\n if (isValidElement(fallback)) {\n childToRender = fallback;\n } else if (typeof fallbackRender === \"function\") {\n childToRender = fallbackRender(props);\n } else if (FallbackComponent) {\n childToRender = createElement(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 createElement(\n ErrorBoundaryContext.Provider,\n {\n value: {\n didCatch,\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n },\n },\n childToRender\n );\n }\n}\n\nfunction hasArrayChanged(a: any[] = [], b: any[] = []) {\n return (\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n );\n}\n","import { createContext } from \"react\";\n\nexport type ErrorBoundaryContextType = {\n didCatch: boolean;\n error: any;\n resetErrorBoundary: (...args: any[]) => void;\n};\n\nexport const ErrorBoundaryContext =\n createContext<ErrorBoundaryContextType | null>(null);\n","import { useContext, useMemo, useState } from \"react\";\nimport { assertErrorBoundaryContext } from \"./assertErrorBoundaryContext\";\nimport { ErrorBoundaryContext } from \"./ErrorBoundaryContext\";\n\nexport type UseErrorBoundaryApi<Error> = {\n resetBoundary: () => void;\n showBoundary: (error: Error) => void;\n};\n\nexport function useErrorBoundary<Error = any>(): UseErrorBoundaryApi<Error> {\n const context = useContext(ErrorBoundaryContext);\n\n assertErrorBoundaryContext(context);\n\n const [state, setState] = useState<{\n error: Error | null;\n hasError: boolean;\n }>({\n error: null,\n hasError: false,\n });\n\n const memoized = useMemo(\n () => ({\n resetBoundary: () => {\n context?.resetErrorBoundary();\n setState({ error: null, hasError: false });\n },\n showBoundary: (error: Error) =>\n setState({\n error,\n hasError: true,\n }),\n }),\n [context?.resetErrorBoundary]\n );\n\n if (state.hasError) {\n throw state.error;\n }\n\n return memoized;\n}\n","import { ErrorBoundaryContextType } from \"./ErrorBoundaryContext\";\n\nexport function assertErrorBoundaryContext(\n value: any\n): value is ErrorBoundaryContextType {\n if (\n value == null ||\n typeof value.didCatch !== \"boolean\" ||\n typeof value.resetErrorBoundary !== \"function\"\n ) {\n throw new Error(\"ErrorBoundaryContext not found\");\n }\n\n return true;\n}\n","import { ComponentType, createElement } from \"react\";\nimport { ErrorBoundary } from \"./ErrorBoundary\";\nimport { ErrorBoundaryProps } from \"./types\";\n\nexport function withErrorBoundary<Props extends Object>(\n Component: ComponentType<Props>,\n errorBoundaryProps: ErrorBoundaryProps\n): ComponentType<Props> {\n const Wrapped: ComponentType<Props> = (props: Props) => {\n return createElement(\n ErrorBoundary,\n errorBoundaryProps,\n createElement(Component, props)\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","import {\n Component,\n ComponentType,\n FunctionComponent,\n ReactElement,\n ReactNode,\n} from \"react\";\n\ndeclare function FallbackRender(props: FallbackProps): ReactNode;\n\nexport type FallbackProps = {\n error: any;\n resetErrorBoundary: (...args: any[]) => void;\n};\n\ntype ErrorBoundarySharedProps = {\n onError?: (error: Error, info: { componentStack: string }) => void;\n onReset?: (\n details:\n | { reason: \"imperative-api\"; args: any[] }\n | { reason: \"keys\"; prev: any[] | undefined; next: any[] | undefined }\n ) => void;\n resetKeys?: any[];\n};\n\nexport type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {\n fallback?: never;\n FallbackComponent: ComponentType<FallbackProps>;\n fallbackRender?: never;\n};\n\nexport type ErrorBoundaryPropsWithRender = ErrorBoundarySharedProps & {\n fallback?: never;\n FallbackComponent?: never;\n fallbackRender: typeof FallbackRender;\n};\n\nexport type ErrorBoundaryPropsWithFallback = ErrorBoundarySharedProps & {\n fallback: ReactElement<\n unknown,\n string | FunctionComponent | typeof Component\n > | null;\n FallbackComponent?: never;\n fallbackRender?: never;\n};\n\nexport type ErrorBoundaryProps =\n | ErrorBoundaryPropsWithFallback\n | ErrorBoundaryPropsWithComponent\n | ErrorBoundaryPropsWithRender;\n"],"names":[],"version":3,"file":"react-error-boundary.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;ACAA;;;;ACAA;AAQO,MAAM,4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;YAC1C;YACA,cAAc,CAAC,QACb,SAAS;2BACP;oBACA,UAAU,IAAI;gBAChB;QACJ,CAAA,GACA;QAAC,SAAS;KAAmB;IAG/B,IAAI,MAAM,QAAQ,EAChB,MAAM,MAAM,KAAK,CAAC;IAGpB,OAAO;AACT;;;;;;AE1CA;;AAYO,SAAS,0CACd,SAA+B,EAC/B,kBAAsC,EACkC;IACxE,MAAM,UAAU,CAAA,GAAA,uBAAU,AAAD,EACvB,CAAC,OAAc,MACb,CAAA,GAAA,0BAAY,EACV,CAAA,GAAA,yCAAa,AAAD,GACZ,oBACA,CAAA,GAAA,0BAAY,EAAE,WAAW;YAAE,GAAG,KAAK;iBAAE;QAAI;IAI/C,iCAAiC;IACjC,MAAM,OAAO,UAAU,WAAW,IAAI,UAAU,IAAI,IAAI;IACxD,QAAQ,WAAW,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IAElD,OAAO;AACT;;;;;;AL9BA","sources":["src/index.ts","src/ErrorBoundary.ts","src/ErrorBoundaryContext.ts","src/useErrorBoundary.ts","src/assertErrorBoundaryContext.ts","src/withErrorBoundary.ts","src/types.ts"],"sourcesContent":["\"use client\";\n\nexport * from \"./ErrorBoundary\";\nexport * from \"./ErrorBoundaryContext\";\nexport * from \"./useErrorBoundary\";\nexport * from \"./withErrorBoundary\";\n\n// TypeScript types\nexport * from \"./types\";\n","import {\n Component,\n createElement,\n ErrorInfo,\n isValidElement,\n PropsWithChildren,\n PropsWithRef,\n ReactElement,\n} from \"react\";\nimport { ErrorBoundaryContext } from \"./ErrorBoundaryContext\";\nimport { ErrorBoundaryProps, FallbackProps } from \"./types\";\n\ntype ErrorBoundaryState = { didCatch: boolean; error: any };\n\nconst initialState: ErrorBoundaryState = {\n didCatch: false,\n error: null,\n};\n\nexport class ErrorBoundary extends Component<\n PropsWithRef<PropsWithChildren<ErrorBoundaryProps>>,\n ErrorBoundaryState\n> {\n state = initialState;\n\n static getDerivedStateFromError(error: Error) {\n return { didCatch: true, error };\n }\n\n resetErrorBoundary = (...args: any[]) => {\n const { error } = this.state;\n\n if (error !== null) {\n this.props.onReset?.({\n args,\n reason: \"imperative-api\",\n });\n\n this.setState(initialState);\n }\n };\n\n componentDidCatch(error: Error, info: ErrorInfo) {\n this.props.onError?.(error, info);\n }\n\n componentDidUpdate(\n prevProps: ErrorBoundaryProps,\n prevState: ErrorBoundaryState\n ) {\n const { didCatch } = this.state;\n const { resetKeys } = this.props;\n\n // There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,\n // we'd end up resetting the error boundary immediately.\n // This would likely trigger a second error to be thrown.\n // So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.\n\n if (\n didCatch &&\n prevState.error !== null &&\n hasArrayChanged(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onReset?.({\n next: resetKeys,\n prev: prevProps.resetKeys,\n reason: \"keys\",\n });\n\n this.setState(initialState);\n }\n }\n\n render() {\n const { children, fallbackRender, FallbackComponent, fallback } =\n this.props;\n const { didCatch, error } = this.state;\n\n let childToRender = children;\n\n if (didCatch) {\n const props: FallbackProps = {\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n };\n\n if (isValidElement(fallback)) {\n childToRender = fallback;\n } else if (typeof fallbackRender === \"function\") {\n childToRender = fallbackRender(props);\n } else if (FallbackComponent) {\n childToRender = createElement(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 createElement(\n ErrorBoundaryContext.Provider,\n {\n value: {\n didCatch,\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n },\n },\n childToRender\n ) as ReactElement;\n }\n}\n\nfunction hasArrayChanged(a: any[] = [], b: any[] = []) {\n return (\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n );\n}\n","import { createContext } from \"react\";\n\nexport type ErrorBoundaryContextType = {\n didCatch: boolean;\n error: any;\n resetErrorBoundary: (...args: any[]) => void;\n};\n\nexport const ErrorBoundaryContext =\n createContext<ErrorBoundaryContextType | null>(null);\n","import { useContext, useMemo, useState } from \"react\";\nimport { assertErrorBoundaryContext } from \"./assertErrorBoundaryContext\";\nimport { ErrorBoundaryContext } from \"./ErrorBoundaryContext\";\n\nexport type UseErrorBoundaryApi<Error> = {\n resetBoundary: () => void;\n showBoundary: (error: Error) => void;\n};\n\nexport function useErrorBoundary<Error = any>(): UseErrorBoundaryApi<Error> {\n const context = useContext(ErrorBoundaryContext);\n\n assertErrorBoundaryContext(context);\n\n const [state, setState] = useState<{\n error: Error | null;\n hasError: boolean;\n }>({\n error: null,\n hasError: false,\n });\n\n const memoized = useMemo(\n () => ({\n resetBoundary: () => {\n context?.resetErrorBoundary();\n setState({ error: null, hasError: false });\n },\n showBoundary: (error: Error) =>\n setState({\n error,\n hasError: true,\n }),\n }),\n [context?.resetErrorBoundary]\n );\n\n if (state.hasError) {\n throw state.error;\n }\n\n return memoized;\n}\n","import { ErrorBoundaryContextType } from \"./ErrorBoundaryContext\";\n\nexport function assertErrorBoundaryContext(\n value: any\n): value is ErrorBoundaryContextType {\n if (\n value == null ||\n typeof value.didCatch !== \"boolean\" ||\n typeof value.resetErrorBoundary !== \"function\"\n ) {\n throw new Error(\"ErrorBoundaryContext not found\");\n }\n\n return true;\n}\n","import {\n createElement,\n forwardRef,\n ForwardedRef,\n RefAttributes,\n ForwardRefExoticComponent,\n PropsWithoutRef,\n ComponentType,\n} from \"react\";\nimport { ErrorBoundary } from \"./ErrorBoundary\";\nimport { ErrorBoundaryProps } from \"./types\";\n\nexport function withErrorBoundary<Props extends Object>(\n component: ComponentType<Props>,\n errorBoundaryProps: ErrorBoundaryProps\n): ForwardRefExoticComponent<PropsWithoutRef<Props> & RefAttributes<any>> {\n const Wrapped = forwardRef<ComponentType<Props>, Props>(\n (props: Props, ref: ForwardedRef<ComponentType<Props>>) =>\n createElement(\n ErrorBoundary,\n errorBoundaryProps,\n createElement(component, { ...props, ref })\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","import {\n Component,\n ComponentType,\n FunctionComponent,\n ReactElement,\n ReactNode,\n} from \"react\";\n\ndeclare function FallbackRender(props: FallbackProps): ReactNode;\n\nexport type FallbackProps = {\n error: any;\n resetErrorBoundary: (...args: any[]) => void;\n};\n\ntype ErrorBoundarySharedProps = {\n onError?: (error: Error, info: { componentStack: string }) => void;\n onReset?: (\n details:\n | { reason: \"imperative-api\"; args: any[] }\n | { reason: \"keys\"; prev: any[] | undefined; next: any[] | undefined }\n ) => void;\n resetKeys?: any[];\n};\n\nexport type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {\n fallback?: never;\n FallbackComponent: ComponentType<FallbackProps>;\n fallbackRender?: never;\n};\n\nexport type ErrorBoundaryPropsWithRender = ErrorBoundarySharedProps & {\n fallback?: never;\n FallbackComponent?: never;\n fallbackRender: typeof FallbackRender;\n};\n\nexport type ErrorBoundaryPropsWithFallback = ErrorBoundarySharedProps & {\n fallback: ReactElement<\n unknown,\n string | FunctionComponent | typeof Component\n > | null;\n FallbackComponent?: never;\n fallbackRender?: never;\n};\n\nexport type ErrorBoundaryProps =\n | ErrorBoundaryPropsWithFallback\n | ErrorBoundaryPropsWithComponent\n | ErrorBoundaryPropsWithRender;\n"],"names":[],"version":3,"file":"react-error-boundary.js.map"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {isValidElement as $hgUW1$isValidElement, createElement as $hgUW1$createElement, Component as $hgUW1$Component, createContext as $hgUW1$createContext, useContext as $hgUW1$useContext, useState as $hgUW1$useState, useMemo as $hgUW1$useMemo} from "react";
|
|
1
|
+
import {isValidElement as $hgUW1$isValidElement, createElement as $hgUW1$createElement, Component as $hgUW1$Component, createContext as $hgUW1$createContext, useContext as $hgUW1$useContext, useState as $hgUW1$useState, useMemo as $hgUW1$useMemo, forwardRef as $hgUW1$forwardRef} from "react";
|
|
2
2
|
|
|
3
3
|
function $parcel$export(e, n, v, s) {
|
|
4
4
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
@@ -127,12 +127,13 @@ var $62ff477d53f02a5b$exports = {};
|
|
|
127
127
|
$parcel$export($62ff477d53f02a5b$exports, "withErrorBoundary", () => $62ff477d53f02a5b$export$f0c7a449e0cfaec7);
|
|
128
128
|
|
|
129
129
|
|
|
130
|
-
function $62ff477d53f02a5b$export$f0c7a449e0cfaec7(
|
|
131
|
-
const Wrapped = (props)=>{
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
function $62ff477d53f02a5b$export$f0c7a449e0cfaec7(component, errorBoundaryProps) {
|
|
131
|
+
const Wrapped = (0, $hgUW1$forwardRef)((props, ref)=>(0, $hgUW1$createElement)((0, $44d7e150ebc754d2$export$e926676385687eaf), errorBoundaryProps, (0, $hgUW1$createElement)(component, {
|
|
132
|
+
...props,
|
|
133
|
+
ref: ref
|
|
134
|
+
})));
|
|
134
135
|
// Format for display in DevTools
|
|
135
|
-
const name =
|
|
136
|
+
const name = component.displayName || component.name || "Unknown";
|
|
136
137
|
Wrapped.displayName = `withErrorBoundary(${name})`;
|
|
137
138
|
return Wrapped;
|
|
138
139
|
}
|
|
@@ -141,6 +142,7 @@ function $62ff477d53f02a5b$export$f0c7a449e0cfaec7(Component, errorBoundaryProps
|
|
|
141
142
|
var $81c1b644006d48ec$exports = {};
|
|
142
143
|
|
|
143
144
|
|
|
145
|
+
"use client";
|
|
144
146
|
|
|
145
147
|
|
|
146
148
|
export {$44d7e150ebc754d2$export$e926676385687eaf as ErrorBoundary, $ebb31c7feaa4405e$export$b16d9fb1a22de840 as ErrorBoundaryContext, $7c3c25b3f398a9d6$export$c052f6604b7d51fe as useErrorBoundary, $62ff477d53f02a5b$export$f0c7a449e0cfaec7 as withErrorBoundary};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;ACAA;;;;ACAA;AAQO,MAAM,4CACX,CAAA,GAAA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,CAAC,QACb,SAAS;2BACP;oBACA,UAAU,IAAI;gBAChB;QACJ,CAAA,GACA;QAAC,SAAS;KAAmB;IAG/B,IAAI,MAAM,QAAQ,EAChB,MAAM,MAAM,KAAK,CAAC;IAGpB,OAAO;AACT;;;;;;AE1CA;;AAIO,SAAS,0CACd,SAA+B,EAC/B,kBAAsC,EAChB;IACtB,MAAM,UAAgC,CAAC,QAAiB;QACtD,OAAO,CAAA,GAAA,oBAAa,AAAD,EACjB,CAAA,GAAA,yCAAa,AAAD,GACZ,oBACA,CAAA,GAAA,oBAAY,EAAE,WAAW;IAE7B;IAEA,iCAAiC;IACjC,MAAM,OAAO,UAAU,WAAW,IAAI,UAAU,IAAI,IAAI;IACxD,QAAQ,WAAW,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IAElD,OAAO;AACT;;;;;","sources":["src/index.ts","src/ErrorBoundary.ts","src/ErrorBoundaryContext.ts","src/useErrorBoundary.ts","src/assertErrorBoundaryContext.ts","src/withErrorBoundary.ts","src/types.ts"],"sourcesContent":["export * from \"./ErrorBoundary\";\nexport * from \"./ErrorBoundaryContext\";\nexport * from \"./useErrorBoundary\";\nexport * from \"./withErrorBoundary\";\n\n// TypeScript types\nexport * from \"./types\";\n","import {\n Component,\n createElement,\n ErrorInfo,\n isValidElement,\n PropsWithChildren,\n PropsWithRef,\n} from \"react\";\nimport { ErrorBoundaryContext } from \"./ErrorBoundaryContext\";\nimport { ErrorBoundaryProps, FallbackProps } from \"./types\";\n\ntype ErrorBoundaryState = { didCatch: boolean; error: any };\n\nconst initialState: ErrorBoundaryState = {\n didCatch: false,\n error: null,\n};\n\nexport class ErrorBoundary extends Component<\n PropsWithRef<PropsWithChildren<ErrorBoundaryProps>>,\n ErrorBoundaryState\n> {\n state = initialState;\n\n static getDerivedStateFromError(error: Error) {\n return { didCatch: true, error };\n }\n\n resetErrorBoundary = (...args: any[]) => {\n const { error } = this.state;\n\n if (error !== null) {\n this.props.onReset?.({\n args,\n reason: \"imperative-api\",\n });\n\n this.setState(initialState);\n }\n };\n\n componentDidCatch(error: Error, info: ErrorInfo) {\n this.props.onError?.(error, info);\n }\n\n componentDidUpdate(\n prevProps: ErrorBoundaryProps,\n prevState: ErrorBoundaryState\n ) {\n const { didCatch } = this.state;\n const { resetKeys } = this.props;\n\n // There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,\n // we'd end up resetting the error boundary immediately.\n // This would likely trigger a second error to be thrown.\n // So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.\n\n if (\n didCatch &&\n prevState.error !== null &&\n hasArrayChanged(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onReset?.({\n next: resetKeys,\n prev: prevProps.resetKeys,\n reason: \"keys\",\n });\n\n this.setState(initialState);\n }\n }\n\n render() {\n const { children, fallbackRender, FallbackComponent, fallback } =\n this.props;\n const { didCatch, error } = this.state;\n\n let childToRender = children;\n\n if (didCatch) {\n const props: FallbackProps = {\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n };\n\n if (isValidElement(fallback)) {\n childToRender = fallback;\n } else if (typeof fallbackRender === \"function\") {\n childToRender = fallbackRender(props);\n } else if (FallbackComponent) {\n childToRender = createElement(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 createElement(\n ErrorBoundaryContext.Provider,\n {\n value: {\n didCatch,\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n },\n },\n childToRender\n );\n }\n}\n\nfunction hasArrayChanged(a: any[] = [], b: any[] = []) {\n return (\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n );\n}\n","import { createContext } from \"react\";\n\nexport type ErrorBoundaryContextType = {\n didCatch: boolean;\n error: any;\n resetErrorBoundary: (...args: any[]) => void;\n};\n\nexport const ErrorBoundaryContext =\n createContext<ErrorBoundaryContextType | null>(null);\n","import { useContext, useMemo, useState } from \"react\";\nimport { assertErrorBoundaryContext } from \"./assertErrorBoundaryContext\";\nimport { ErrorBoundaryContext } from \"./ErrorBoundaryContext\";\n\nexport type UseErrorBoundaryApi<Error> = {\n resetBoundary: () => void;\n showBoundary: (error: Error) => void;\n};\n\nexport function useErrorBoundary<Error = any>(): UseErrorBoundaryApi<Error> {\n const context = useContext(ErrorBoundaryContext);\n\n assertErrorBoundaryContext(context);\n\n const [state, setState] = useState<{\n error: Error | null;\n hasError: boolean;\n }>({\n error: null,\n hasError: false,\n });\n\n const memoized = useMemo(\n () => ({\n resetBoundary: () => {\n context?.resetErrorBoundary();\n setState({ error: null, hasError: false });\n },\n showBoundary: (error: Error) =>\n setState({\n error,\n hasError: true,\n }),\n }),\n [context?.resetErrorBoundary]\n );\n\n if (state.hasError) {\n throw state.error;\n }\n\n return memoized;\n}\n","import { ErrorBoundaryContextType } from \"./ErrorBoundaryContext\";\n\nexport function assertErrorBoundaryContext(\n value: any\n): value is ErrorBoundaryContextType {\n if (\n value == null ||\n typeof value.didCatch !== \"boolean\" ||\n typeof value.resetErrorBoundary !== \"function\"\n ) {\n throw new Error(\"ErrorBoundaryContext not found\");\n }\n\n return true;\n}\n","import { ComponentType, createElement } from \"react\";\nimport { ErrorBoundary } from \"./ErrorBoundary\";\nimport { ErrorBoundaryProps } from \"./types\";\n\nexport function withErrorBoundary<Props extends Object>(\n Component: ComponentType<Props>,\n errorBoundaryProps: ErrorBoundaryProps\n): ComponentType<Props> {\n const Wrapped: ComponentType<Props> = (props: Props) => {\n return createElement(\n ErrorBoundary,\n errorBoundaryProps,\n createElement(Component, props)\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","import {\n Component,\n ComponentType,\n FunctionComponent,\n ReactElement,\n ReactNode,\n} from \"react\";\n\ndeclare function FallbackRender(props: FallbackProps): ReactNode;\n\nexport type FallbackProps = {\n error: any;\n resetErrorBoundary: (...args: any[]) => void;\n};\n\ntype ErrorBoundarySharedProps = {\n onError?: (error: Error, info: { componentStack: string }) => void;\n onReset?: (\n details:\n | { reason: \"imperative-api\"; args: any[] }\n | { reason: \"keys\"; prev: any[] | undefined; next: any[] | undefined }\n ) => void;\n resetKeys?: any[];\n};\n\nexport type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {\n fallback?: never;\n FallbackComponent: ComponentType<FallbackProps>;\n fallbackRender?: never;\n};\n\nexport type ErrorBoundaryPropsWithRender = ErrorBoundarySharedProps & {\n fallback?: never;\n FallbackComponent?: never;\n fallbackRender: typeof FallbackRender;\n};\n\nexport type ErrorBoundaryPropsWithFallback = ErrorBoundarySharedProps & {\n fallback: ReactElement<\n unknown,\n string | FunctionComponent | typeof Component\n > | null;\n FallbackComponent?: never;\n fallbackRender?: never;\n};\n\nexport type ErrorBoundaryProps =\n | ErrorBoundaryPropsWithFallback\n | ErrorBoundaryPropsWithComponent\n | ErrorBoundaryPropsWithRender;\n"],"names":[],"version":3,"file":"react-error-boundary.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;ACAA;;;;ACAA;AAQO,MAAM,4CACX,CAAA,GAAA,oBAAY,EAAmC,IAAI;;;ADKrD,MAAM,qCAAmC;IACvC,UAAU,KAAK;IACf,OAAO,IAAI;AACb;AAEO,MAAM,kDAAsB,CAAA,GAAA,gBAAS,AAAD;IAIzC,QAAQ,mCAAa;IAErB,OAAO,yBAAyB,KAAY,EAAE;QAC5C,OAAO;YAAE,UAAU,IAAI;mBAAE;QAAM;IACjC;IAEA,qBAAqB,CAAC,GAAG,OAAgB;QACvC,MAAM,SAAE,MAAK,EAAE,GAAG,IAAI,CAAC,KAAK;QAE5B,IAAI,UAAU,IAAI,EAAE;YAClB,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG;sBACnB;gBACA,QAAQ;YACV;YAEA,IAAI,CAAC,QAAQ,CAAC;QAChB,CAAC;IACH,EAAE;IAEF,kBAAkB,KAAY,EAAE,IAAe,EAAE;QAC/C,IAAI,CAAC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CAAC,CAAC;IAElD,OAAO;AACT;;;;;;AL9BA","sources":["src/index.ts","src/ErrorBoundary.ts","src/ErrorBoundaryContext.ts","src/useErrorBoundary.ts","src/assertErrorBoundaryContext.ts","src/withErrorBoundary.ts","src/types.ts"],"sourcesContent":["\"use client\";\n\nexport * from \"./ErrorBoundary\";\nexport * from \"./ErrorBoundaryContext\";\nexport * from \"./useErrorBoundary\";\nexport * from \"./withErrorBoundary\";\n\n// TypeScript types\nexport * from \"./types\";\n","import {\n Component,\n createElement,\n ErrorInfo,\n isValidElement,\n PropsWithChildren,\n PropsWithRef,\n ReactElement,\n} from \"react\";\nimport { ErrorBoundaryContext } from \"./ErrorBoundaryContext\";\nimport { ErrorBoundaryProps, FallbackProps } from \"./types\";\n\ntype ErrorBoundaryState = { didCatch: boolean; error: any };\n\nconst initialState: ErrorBoundaryState = {\n didCatch: false,\n error: null,\n};\n\nexport class ErrorBoundary extends Component<\n PropsWithRef<PropsWithChildren<ErrorBoundaryProps>>,\n ErrorBoundaryState\n> {\n state = initialState;\n\n static getDerivedStateFromError(error: Error) {\n return { didCatch: true, error };\n }\n\n resetErrorBoundary = (...args: any[]) => {\n const { error } = this.state;\n\n if (error !== null) {\n this.props.onReset?.({\n args,\n reason: \"imperative-api\",\n });\n\n this.setState(initialState);\n }\n };\n\n componentDidCatch(error: Error, info: ErrorInfo) {\n this.props.onError?.(error, info);\n }\n\n componentDidUpdate(\n prevProps: ErrorBoundaryProps,\n prevState: ErrorBoundaryState\n ) {\n const { didCatch } = this.state;\n const { resetKeys } = this.props;\n\n // There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,\n // we'd end up resetting the error boundary immediately.\n // This would likely trigger a second error to be thrown.\n // So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.\n\n if (\n didCatch &&\n prevState.error !== null &&\n hasArrayChanged(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onReset?.({\n next: resetKeys,\n prev: prevProps.resetKeys,\n reason: \"keys\",\n });\n\n this.setState(initialState);\n }\n }\n\n render() {\n const { children, fallbackRender, FallbackComponent, fallback } =\n this.props;\n const { didCatch, error } = this.state;\n\n let childToRender = children;\n\n if (didCatch) {\n const props: FallbackProps = {\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n };\n\n if (isValidElement(fallback)) {\n childToRender = fallback;\n } else if (typeof fallbackRender === \"function\") {\n childToRender = fallbackRender(props);\n } else if (FallbackComponent) {\n childToRender = createElement(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 createElement(\n ErrorBoundaryContext.Provider,\n {\n value: {\n didCatch,\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n },\n },\n childToRender\n ) as ReactElement;\n }\n}\n\nfunction hasArrayChanged(a: any[] = [], b: any[] = []) {\n return (\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n );\n}\n","import { createContext } from \"react\";\n\nexport type ErrorBoundaryContextType = {\n didCatch: boolean;\n error: any;\n resetErrorBoundary: (...args: any[]) => void;\n};\n\nexport const ErrorBoundaryContext =\n createContext<ErrorBoundaryContextType | null>(null);\n","import { useContext, useMemo, useState } from \"react\";\nimport { assertErrorBoundaryContext } from \"./assertErrorBoundaryContext\";\nimport { ErrorBoundaryContext } from \"./ErrorBoundaryContext\";\n\nexport type UseErrorBoundaryApi<Error> = {\n resetBoundary: () => void;\n showBoundary: (error: Error) => void;\n};\n\nexport function useErrorBoundary<Error = any>(): UseErrorBoundaryApi<Error> {\n const context = useContext(ErrorBoundaryContext);\n\n assertErrorBoundaryContext(context);\n\n const [state, setState] = useState<{\n error: Error | null;\n hasError: boolean;\n }>({\n error: null,\n hasError: false,\n });\n\n const memoized = useMemo(\n () => ({\n resetBoundary: () => {\n context?.resetErrorBoundary();\n setState({ error: null, hasError: false });\n },\n showBoundary: (error: Error) =>\n setState({\n error,\n hasError: true,\n }),\n }),\n [context?.resetErrorBoundary]\n );\n\n if (state.hasError) {\n throw state.error;\n }\n\n return memoized;\n}\n","import { ErrorBoundaryContextType } from \"./ErrorBoundaryContext\";\n\nexport function assertErrorBoundaryContext(\n value: any\n): value is ErrorBoundaryContextType {\n if (\n value == null ||\n typeof value.didCatch !== \"boolean\" ||\n typeof value.resetErrorBoundary !== \"function\"\n ) {\n throw new Error(\"ErrorBoundaryContext not found\");\n }\n\n return true;\n}\n","import {\n createElement,\n forwardRef,\n ForwardedRef,\n RefAttributes,\n ForwardRefExoticComponent,\n PropsWithoutRef,\n ComponentType,\n} from \"react\";\nimport { ErrorBoundary } from \"./ErrorBoundary\";\nimport { ErrorBoundaryProps } from \"./types\";\n\nexport function withErrorBoundary<Props extends Object>(\n component: ComponentType<Props>,\n errorBoundaryProps: ErrorBoundaryProps\n): ForwardRefExoticComponent<PropsWithoutRef<Props> & RefAttributes<any>> {\n const Wrapped = forwardRef<ComponentType<Props>, Props>(\n (props: Props, ref: ForwardedRef<ComponentType<Props>>) =>\n createElement(\n ErrorBoundary,\n errorBoundaryProps,\n createElement(component, { ...props, ref })\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","import {\n Component,\n ComponentType,\n FunctionComponent,\n ReactElement,\n ReactNode,\n} from \"react\";\n\ndeclare function FallbackRender(props: FallbackProps): ReactNode;\n\nexport type FallbackProps = {\n error: any;\n resetErrorBoundary: (...args: any[]) => void;\n};\n\ntype ErrorBoundarySharedProps = {\n onError?: (error: Error, info: { componentStack: string }) => void;\n onReset?: (\n details:\n | { reason: \"imperative-api\"; args: any[] }\n | { reason: \"keys\"; prev: any[] | undefined; next: any[] | undefined }\n ) => void;\n resetKeys?: any[];\n};\n\nexport type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {\n fallback?: never;\n FallbackComponent: ComponentType<FallbackProps>;\n fallbackRender?: never;\n};\n\nexport type ErrorBoundaryPropsWithRender = ErrorBoundarySharedProps & {\n fallback?: never;\n FallbackComponent?: never;\n fallbackRender: typeof FallbackRender;\n};\n\nexport type ErrorBoundaryPropsWithFallback = ErrorBoundarySharedProps & {\n fallback: ReactElement<\n unknown,\n string | FunctionComponent | typeof Component\n > | null;\n FallbackComponent?: never;\n fallbackRender?: never;\n};\n\nexport type ErrorBoundaryProps =\n | ErrorBoundaryPropsWithFallback\n | ErrorBoundaryPropsWithComponent\n | ErrorBoundaryPropsWithRender;\n"],"names":[],"version":3,"file":"react-error-boundary.module.js.map"}
|