react-error-boundary 6.0.1 → 6.0.2

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
@@ -1,6 +1,6 @@
1
- # react-error-boundary
1
+ <img src="https://react-error-boundary-lib.vercel.app/og.svg" alt="react-error-boundary logo" width="400" height="210" />
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
+ `react-error-boundary`: 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, 🎉 [become a sponsor](https://github.com/sponsors/bvaughn/) or ☕ [buy me a coffee](http://givebrian.coffee/)
6
6
 
@@ -17,6 +17,10 @@ pnpm add react-error-boundary
17
17
  yarn add react-error-boundary
18
18
  ```
19
19
 
20
+ ## FAQs
21
+
22
+ Frequently asked questions can be found [here](https://react-error-boundary-lib.vercel.app/common-questions).
23
+
20
24
  ## API
21
25
 
22
26
  ### ErrorBoundary
@@ -25,6 +29,12 @@ yarn add react-error-boundary
25
29
  A reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component.
26
30
  Wrap this component around other React components to "catch" errors and render a fallback UI.
27
31
 
32
+ This package is built on top of React [error boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary),
33
+ so it has all of the advantages and constraints of that API.
34
+ This means that it can't catch errors during:
35
+ - Server side rendering</li>
36
+ - Event handlers
37
+ - Asynchronous code (including effects)
28
38
 
29
39
  ℹ️ The component provides several ways to render a fallback: `fallback`, `fallbackRender`, and `FallbackComponent`.
30
40
  Refer to the documentation to determine which is best for your application.
@@ -1 +1 @@
1
- {"version":3,"file":"react-error-boundary.cjs","sources":["../lib/context/ErrorBoundaryContext.ts","../lib/components/ErrorBoundary.tsx","../lib/utils/isErrorBoundaryContext.ts","../lib/utils/assertErrorBoundaryContext.ts","../lib/hooks/useErrorBoundary.ts","../lib/utils/withErrorBoundary.ts"],"sourcesContent":["import { createContext } from \"react\";\n\nexport type ErrorBoundaryContextType = {\n didCatch: boolean;\n error: Error | null;\n resetErrorBoundary: (...args: unknown[]) => void;\n};\n\nexport const ErrorBoundaryContext =\n createContext<ErrorBoundaryContextType | null>(null);\n","import { Component, createElement, type ErrorInfo } from \"react\";\nimport { ErrorBoundaryContext } from \"../context/ErrorBoundaryContext\";\nimport type { ErrorBoundaryProps, FallbackProps } from \"../types\";\n\nconst isDevelopment = import.meta.env.DEV;\n\ntype ErrorBoundaryState =\n | {\n didCatch: true;\n error: Error;\n }\n | {\n didCatch: false;\n error: null;\n };\n\nconst initialState: ErrorBoundaryState = {\n didCatch: false,\n error: null,\n};\n\n/**\n * A reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component.\n * Wrap this component around other React components to \"catch\" errors and render a fallback UI.\n *\n *\n * ℹ️ The component provides several ways to render a fallback: `fallback`, `fallbackRender`, and `FallbackComponent`.\n * Refer to the documentation to determine which is best for your application.\n *\n * ℹ️ This 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.\n */\nexport class ErrorBoundary extends Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n\n this.resetErrorBoundary = this.resetErrorBoundary.bind(this);\n this.state = initialState;\n }\n\n static getDerivedStateFromError(error: Error) {\n return { didCatch: true, error };\n }\n\n resetErrorBoundary(...args: unknown[]) {\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 (typeof fallbackRender === \"function\") {\n childToRender = fallbackRender(props);\n } else if (FallbackComponent) {\n childToRender = createElement(FallbackComponent, props);\n } else if (fallback !== undefined) {\n childToRender = fallback;\n } else {\n if (isDevelopment) {\n console.error(\n \"react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop\",\n );\n }\n\n throw error;\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: unknown[] = [], b: unknown[] = []) {\n return (\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n );\n}\n","import type { ErrorBoundaryContextType } from \"../context/ErrorBoundaryContext\";\n\nexport function isErrorBoundaryContext(\n value: unknown,\n): value is ErrorBoundaryContextType {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"didCatch\" in value &&\n typeof value.didCatch === \"boolean\" &&\n \"error\" in value &&\n \"resetErrorBoundary\" in value &&\n typeof value.resetErrorBoundary === \"function\"\n );\n}\n","import type { ErrorBoundaryContextType } from \"../context/ErrorBoundaryContext\";\nimport { isErrorBoundaryContext } from \"./isErrorBoundaryContext\";\n\nexport function assertErrorBoundaryContext(\n value: unknown,\n): asserts value is ErrorBoundaryContextType {\n if (!isErrorBoundaryContext(value)) {\n throw new Error(\"ErrorBoundaryContext not found\");\n }\n}\n","import { useContext, useMemo, useState } from \"react\";\nimport { ErrorBoundaryContext } from \"../context/ErrorBoundaryContext\";\nimport { assertErrorBoundaryContext } from \"../utils/assertErrorBoundaryContext\";\n\ntype UseErrorBoundaryState =\n | { error: Error; hasError: true }\n | { error: null; hasError: false };\n\nexport type UseErrorBoundaryApi = {\n error: Error | null;\n resetBoundary: () => void;\n showBoundary: (error: Error) => void;\n};\n\n/**\n * Convenience hook for imperatively showing or dismissing error boundaries.\n *\n * ⚠️ This hook must only be used within an `ErrorBoundary` subtree.\n */\nexport function useErrorBoundary(): {\n /**\n * The currently visible `Error` (if one has been thrown).\n */\n error: Error | null;\n\n /**\n * Method to reset and retry the nearest active error boundary (if one is active).\n */\n resetBoundary: () => void;\n\n /**\n * Trigger the nearest error boundary to display the error provided.\n *\n * ℹ️ React only handles errors thrown during render or during component lifecycle methods (e.g. effects and did-mount/did-update).\n * Errors thrown in event handlers, or after async code has run, will not be caught.\n * This method is a way to imperatively trigger an error boundary during these phases.\n */\n showBoundary: (error: Error) => void;\n} {\n const context = useContext(ErrorBoundaryContext);\n\n assertErrorBoundaryContext(context);\n\n const { error, resetErrorBoundary } = context;\n\n const [state, setState] = useState<UseErrorBoundaryState>({\n error: null,\n hasError: false,\n });\n\n const memoized = useMemo(\n () => ({\n error,\n resetBoundary: () => {\n resetErrorBoundary();\n setState({ error: null, hasError: false });\n },\n showBoundary: (error: Error) =>\n setState({\n error,\n hasError: true,\n }),\n }),\n [error, resetErrorBoundary],\n );\n\n if (state.hasError) {\n throw state.error;\n }\n\n return memoized;\n}\n","import {\n createElement,\n forwardRef,\n type ComponentClass,\n type ComponentType,\n} from \"react\";\nimport { ErrorBoundary } from \"../components/ErrorBoundary\";\nimport type { ErrorBoundaryProps } from \"../types\";\n\nexport function withErrorBoundary<\n Type extends ComponentClass<unknown>,\n Props extends object,\n>(Component: ComponentType<Props>, errorBoundaryProps: ErrorBoundaryProps) {\n const Wrapped = forwardRef<InstanceType<Type>, Props>((props, ref) =>\n createElement(\n ErrorBoundary,\n errorBoundaryProps,\n createElement(Component, { ...props, ref } as 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"],"names":["ErrorBoundaryContext","createContext","initialState","ErrorBoundary","Component","props","error","args","info","prevProps","prevState","didCatch","resetKeys","hasArrayChanged","children","fallbackRender","FallbackComponent","fallback","childToRender","createElement","a","b","item","index","isErrorBoundaryContext","value","assertErrorBoundaryContext","useErrorBoundary","context","useContext","resetErrorBoundary","state","setState","useState","memoized","useMemo","withErrorBoundary","errorBoundaryProps","Wrapped","forwardRef","ref","name"],"mappings":"sHAQaA,EACXC,EAAAA,cAA+C,IAAI,ECO/CC,EAAmC,CACvC,SAAU,GACV,MAAO,IACT,EAYO,MAAMC,UAAsBC,EAAAA,SAGjC,CACA,YAAYC,EAA2B,CACrC,MAAMA,CAAK,EAEX,KAAK,mBAAqB,KAAK,mBAAmB,KAAK,IAAI,EAC3D,KAAK,MAAQH,CACf,CAEA,OAAO,yBAAyBI,EAAc,CAC5C,MAAO,CAAE,SAAU,GAAM,MAAAA,CAAA,CAC3B,CAEA,sBAAsBC,EAAiB,CACrC,KAAM,CAAE,MAAAD,GAAU,KAAK,MAEnBA,IAAU,OACZ,KAAK,MAAM,UAAU,CACnB,KAAAC,EACA,OAAQ,gBAAA,CACT,EAED,KAAK,SAASL,CAAY,EAE9B,CAEA,kBAAkBI,EAAcE,EAAiB,CAC/C,KAAK,MAAM,UAAUF,EAAOE,CAAI,CAClC,CAEA,mBACEC,EACAC,EACA,CACA,KAAM,CAAE,SAAAC,GAAa,KAAK,MACpB,CAAE,UAAAC,GAAc,KAAK,MAQzBD,GACAD,EAAU,QAAU,MACpBG,EAAgBJ,EAAU,UAAWG,CAAS,IAE9C,KAAK,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hC,CAACG,EAAOC,CAAQ,EAAIC,WAAgC,CACxD,MAAO,KACP,SAAU,EAAA,CACX,EAEKC,EAAWC,EAAAA,QACf,KAAO,CACL,MAAA7B,EACA,cAAe,IAAM,CACnBwB,EAAA,EACAE,EAAS,CAAE,MAAO,KAAM,SAAU,GAAO,CAC3C,EACA,aAAe1B,GACb0B,EAAS,CACP,MAAA1B,EACA,SAAU,EAAA,CACX,CAAA,GAEL,CAACA,EAAOwB,CAAkB,CAAA,EAG5B,GAAIC,EAAM,SACR,MAAMA,EAAM,MAGd,OAAOG,CACT,CC9DO,SAASE,EAGdhC,EAAiCiC,EAAwC,CACzE,MAAMC,EAAUC,EAAAA,WAAsC,CAAClC,EAAOmC,IAC5DrB,EAAAA,cACEhB,EACAkC,EACAlB,EAAAA,cAAcf,EAAW,CAAE,GAAGC,EAAO,IAAAmC,EAAc,CAAA,CACrD,EAIIC,EAAOrC,EAAU,aAAeA,EAAU,MAAQ,UACxD,OAAAkC,EAAQ,YAAc,qBAAqBG,CAAI,IAExCH,CACT"}
1
+ {"version":3,"file":"react-error-boundary.cjs","sources":["../lib/context/ErrorBoundaryContext.ts","../lib/components/ErrorBoundary.tsx","../lib/utils/isErrorBoundaryContext.ts","../lib/utils/assertErrorBoundaryContext.ts","../lib/hooks/useErrorBoundary.ts","../lib/utils/withErrorBoundary.ts"],"sourcesContent":["import { createContext } from \"react\";\n\nexport type ErrorBoundaryContextType = {\n didCatch: boolean;\n error: Error | null;\n resetErrorBoundary: (...args: unknown[]) => void;\n};\n\nexport const ErrorBoundaryContext =\n createContext<ErrorBoundaryContextType | null>(null);\n","import { Component, createElement, type ErrorInfo } from \"react\";\nimport { ErrorBoundaryContext } from \"../context/ErrorBoundaryContext\";\nimport type { ErrorBoundaryProps, FallbackProps } from \"../types\";\n\nconst isDevelopment = import.meta.env.DEV;\n\ntype ErrorBoundaryState =\n | {\n didCatch: true;\n error: Error;\n }\n | {\n didCatch: false;\n error: null;\n };\n\nconst initialState: ErrorBoundaryState = {\n didCatch: false,\n error: null,\n};\n\n/**\n * A reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component.\n * Wrap this component around other React components to \"catch\" errors and render a fallback UI.\n *\n * This package is built on top of React [error boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary),\n * so it has all of the advantages and constraints of that API.\n * This means that it can't catch errors during:\n * - Server side rendering</li>\n * - Event handlers\n * - Asynchronous code (including effects)\n *\n * ℹ️ The component provides several ways to render a fallback: `fallback`, `fallbackRender`, and `FallbackComponent`.\n * Refer to the documentation to determine which is best for your application.\n *\n * ℹ️ This 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.\n */\nexport class ErrorBoundary extends Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n\n this.resetErrorBoundary = this.resetErrorBoundary.bind(this);\n this.state = initialState;\n }\n\n static getDerivedStateFromError(error: Error) {\n return { didCatch: true, error };\n }\n\n resetErrorBoundary(...args: unknown[]) {\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 (typeof fallbackRender === \"function\") {\n childToRender = fallbackRender(props);\n } else if (FallbackComponent) {\n childToRender = createElement(FallbackComponent, props);\n } else if (fallback !== undefined) {\n childToRender = fallback;\n } else {\n if (isDevelopment) {\n console.error(\n \"react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop\",\n );\n }\n\n throw error;\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: unknown[] = [], b: unknown[] = []) {\n return (\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n );\n}\n","import type { ErrorBoundaryContextType } from \"../context/ErrorBoundaryContext\";\n\nexport function isErrorBoundaryContext(\n value: unknown,\n): value is ErrorBoundaryContextType {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"didCatch\" in value &&\n typeof value.didCatch === \"boolean\" &&\n \"error\" in value &&\n \"resetErrorBoundary\" in value &&\n typeof value.resetErrorBoundary === \"function\"\n );\n}\n","import type { ErrorBoundaryContextType } from \"../context/ErrorBoundaryContext\";\nimport { isErrorBoundaryContext } from \"./isErrorBoundaryContext\";\n\nexport function assertErrorBoundaryContext(\n value: unknown,\n): asserts value is ErrorBoundaryContextType {\n if (!isErrorBoundaryContext(value)) {\n throw new Error(\"ErrorBoundaryContext not found\");\n }\n}\n","import { useContext, useMemo, useState } from \"react\";\nimport { ErrorBoundaryContext } from \"../context/ErrorBoundaryContext\";\nimport { assertErrorBoundaryContext } from \"../utils/assertErrorBoundaryContext\";\n\ntype UseErrorBoundaryState =\n | { error: Error; hasError: true }\n | { error: null; hasError: false };\n\nexport type UseErrorBoundaryApi = {\n error: Error | null;\n resetBoundary: () => void;\n showBoundary: (error: Error) => void;\n};\n\n/**\n * Convenience hook for imperatively showing or dismissing error boundaries.\n *\n * ⚠️ This hook must only be used within an `ErrorBoundary` subtree.\n */\nexport function useErrorBoundary(): {\n /**\n * The currently visible `Error` (if one has been thrown).\n */\n error: Error | null;\n\n /**\n * Method to reset and retry the nearest active error boundary (if one is active).\n */\n resetBoundary: () => void;\n\n /**\n * Trigger the nearest error boundary to display the error provided.\n *\n * ℹ️ React only handles errors thrown during render or during component lifecycle methods (e.g. effects and did-mount/did-update).\n * Errors thrown in event handlers, or after async code has run, will not be caught.\n * This method is a way to imperatively trigger an error boundary during these phases.\n */\n showBoundary: (error: Error) => void;\n} {\n const context = useContext(ErrorBoundaryContext);\n\n assertErrorBoundaryContext(context);\n\n const { error, resetErrorBoundary } = context;\n\n const [state, setState] = useState<UseErrorBoundaryState>({\n error: null,\n hasError: false,\n });\n\n const memoized = useMemo(\n () => ({\n error,\n resetBoundary: () => {\n resetErrorBoundary();\n setState({ error: null, hasError: false });\n },\n showBoundary: (error: Error) =>\n setState({\n error,\n hasError: true,\n }),\n }),\n [error, resetErrorBoundary],\n );\n\n if (state.hasError) {\n throw state.error;\n }\n\n return memoized;\n}\n","import {\n createElement,\n forwardRef,\n type ComponentClass,\n type ComponentType,\n} from \"react\";\nimport { ErrorBoundary } from \"../components/ErrorBoundary\";\nimport type { ErrorBoundaryProps } from \"../types\";\n\nexport function withErrorBoundary<\n Type extends ComponentClass<unknown>,\n Props extends object,\n>(Component: ComponentType<Props>, errorBoundaryProps: ErrorBoundaryProps) {\n const Wrapped = forwardRef<InstanceType<Type>, Props>((props, ref) =>\n createElement(\n ErrorBoundary,\n errorBoundaryProps,\n createElement(Component, { ...props, ref } as 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"],"names":["ErrorBoundaryContext","createContext","initialState","ErrorBoundary","Component","props","error","args","info","prevProps","prevState","didCatch","resetKeys","hasArrayChanged","children","fallbackRender","FallbackComponent","fallback","childToRender","createElement","a","b","item","index","isErrorBoundaryContext","value","assertErrorBoundaryContext","useErrorBoundary","context","useContext","resetErrorBoundary","state","setState","useState","memoized","useMemo","withErrorBoundary","errorBoundaryProps","Wrapped","forwardRef","ref","name"],"mappings":"sHAQaA,EACXC,EAAAA,cAA+C,IAAI,ECO/CC,EAAmC,CACvC,SAAU,GACV,MAAO,IACT,EAkBO,MAAMC,UAAsBC,EAAAA,SAGjC,CACA,YAAYC,EAA2B,CACrC,MAAMA,CAAK,EAEX,KAAK,mBAAqB,KAAK,mBAAmB,KAAK,IAAI,EAC3D,KAAK,MAAQH,CACf,CAEA,OAAO,yBAAyBI,EAAc,CAC5C,MAAO,CAAE,SAAU,GAAM,MAAAA,CAAA,CAC3B,CAEA,sBAAsBC,EAAiB,CACrC,KAAM,CAAE,MAAAD,GAAU,KAAK,MAEnBA,IAAU,OACZ,KAAK,MAAM,UAAU,CACnB,KAAAC,EACA,OAAQ,gBAAA,CACT,EAED,KAAK,SAASL,CAAY,EAE9B,CAEA,kBAAkBI,EAAcE,EAAiB,CAC/C,KAAK,MAAM,UAAUF,EAAOE,CAAI,CAClC,CAEA,mBACEC,EACAC,EACA,CACA,KAAM,CAAE,SAAAC,GAAa,KAAK,MACpB,CAAE,UAAAC,GAAc,KAAK,MAQzBD,GACAD,EAAU,QAAU,MACpBG,EAAgBJ,EAAU,UAAWG,CAAS,IAE9C,KAAK,MAAM,UAAU,CACnB,KAAMA,EACN,KAAMH,EAAU,UAChB,OAAQ,MAAA,CACT,EAED,KAAK,SAASP,CAAY,EAE9B,CAEA,QAAS,CACP,KAAM,CAAE,SAAAY,EAAU,eAAAC,EAAgB,kBAAAC,EAAmB,SAAAC,CAAA,EACnD,KAAK,MACD,CAAE,SAAAN,EAAU,MAAAL,CAAA,EAAU,KAAK,MAEjC,IAAIY,EAAgBJ,EAEpB,GAAIH,EAAU,CACZ,MAAMN,EAAuB,CAC3B,M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M,SACR,MAAMA,EAAM,MAGd,OAAOG,CACT,CC9DO,SAASE,EAGdhC,EAAiCiC,EAAwC,CACzE,MAAMC,EAAUC,EAAAA,WAAsC,CAAClC,EAAOmC,IAC5DrB,EAAAA,cACEhB,EACAkC,EACAlB,EAAAA,cAAcf,EAAW,CAAE,GAAGC,EAAO,IAAAmC,EAAc,CAAA,CACrD,EAIIC,EAAOrC,EAAU,aAAeA,EAAU,MAAQ,UACxD,OAAAkC,EAAQ,YAAc,qBAAqBG,CAAI,IAExCH,CACT"}
@@ -15,6 +15,12 @@ import { RefAttributes } from 'react';
15
15
  * A reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component.
16
16
  * Wrap this component around other React components to "catch" errors and render a fallback UI.
17
17
  *
18
+ * This package is built on top of React [error boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary),
19
+ * so it has all of the advantages and constraints of that API.
20
+ * This means that it can't catch errors during:
21
+ * - Server side rendering</li>
22
+ * - Event handlers
23
+ * - Asynchronous code (including effects)
18
24
  *
19
25
  * ℹ️ The component provides several ways to render a fallback: `fallback`, `fallbackRender`, and `FallbackComponent`.
20
26
  * Refer to the documentation to determine which is best for your application.
@@ -1 +1 @@
1
- {"version":3,"file":"react-error-boundary.js","sources":["../lib/context/ErrorBoundaryContext.ts","../lib/components/ErrorBoundary.tsx","../lib/utils/isErrorBoundaryContext.ts","../lib/utils/assertErrorBoundaryContext.ts","../lib/hooks/useErrorBoundary.ts","../lib/utils/withErrorBoundary.ts"],"sourcesContent":["import { createContext } from \"react\";\n\nexport type ErrorBoundaryContextType = {\n didCatch: boolean;\n error: Error | null;\n resetErrorBoundary: (...args: unknown[]) => void;\n};\n\nexport const ErrorBoundaryContext =\n createContext<ErrorBoundaryContextType | null>(null);\n","import { Component, createElement, type ErrorInfo } from \"react\";\nimport { ErrorBoundaryContext } from \"../context/ErrorBoundaryContext\";\nimport type { ErrorBoundaryProps, FallbackProps } from \"../types\";\n\nconst isDevelopment = import.meta.env.DEV;\n\ntype ErrorBoundaryState =\n | {\n didCatch: true;\n error: Error;\n }\n | {\n didCatch: false;\n error: null;\n };\n\nconst initialState: ErrorBoundaryState = {\n didCatch: false,\n error: null,\n};\n\n/**\n * A reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component.\n * Wrap this component around other React components to \"catch\" errors and render a fallback UI.\n *\n *\n * ℹ️ The component provides several ways to render a fallback: `fallback`, `fallbackRender`, and `FallbackComponent`.\n * Refer to the documentation to determine which is best for your application.\n *\n * ℹ️ This 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.\n */\nexport class ErrorBoundary extends Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n\n this.resetErrorBoundary = this.resetErrorBoundary.bind(this);\n this.state = initialState;\n }\n\n static getDerivedStateFromError(error: Error) {\n return { didCatch: true, error };\n }\n\n resetErrorBoundary(...args: unknown[]) {\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 (typeof fallbackRender === \"function\") {\n childToRender = fallbackRender(props);\n } else if (FallbackComponent) {\n childToRender = createElement(FallbackComponent, props);\n } else if (fallback !== undefined) {\n childToRender = fallback;\n } else {\n if (isDevelopment) {\n console.error(\n \"react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop\",\n );\n }\n\n throw error;\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: unknown[] = [], b: unknown[] = []) {\n return (\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n );\n}\n","import type { ErrorBoundaryContextType } from \"../context/ErrorBoundaryContext\";\n\nexport function isErrorBoundaryContext(\n value: unknown,\n): value is ErrorBoundaryContextType {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"didCatch\" in value &&\n typeof value.didCatch === \"boolean\" &&\n \"error\" in value &&\n \"resetErrorBoundary\" in value &&\n typeof value.resetErrorBoundary === \"function\"\n );\n}\n","import type { ErrorBoundaryContextType } from \"../context/ErrorBoundaryContext\";\nimport { isErrorBoundaryContext } from \"./isErrorBoundaryContext\";\n\nexport function assertErrorBoundaryContext(\n value: unknown,\n): asserts value is ErrorBoundaryContextType {\n if (!isErrorBoundaryContext(value)) {\n throw new Error(\"ErrorBoundaryContext not found\");\n }\n}\n","import { useContext, useMemo, useState } from \"react\";\nimport { ErrorBoundaryContext } from \"../context/ErrorBoundaryContext\";\nimport { assertErrorBoundaryContext } from \"../utils/assertErrorBoundaryContext\";\n\ntype UseErrorBoundaryState =\n | { error: Error; hasError: true }\n | { error: null; hasError: false };\n\nexport type UseErrorBoundaryApi = {\n error: Error | null;\n resetBoundary: () => void;\n showBoundary: (error: Error) => void;\n};\n\n/**\n * Convenience hook for imperatively showing or dismissing error boundaries.\n *\n * ⚠️ This hook must only be used within an `ErrorBoundary` subtree.\n */\nexport function useErrorBoundary(): {\n /**\n * The currently visible `Error` (if one has been thrown).\n */\n error: Error | null;\n\n /**\n * Method to reset and retry the nearest active error boundary (if one is active).\n */\n resetBoundary: () => void;\n\n /**\n * Trigger the nearest error boundary to display the error provided.\n *\n * ℹ️ React only handles errors thrown during render or during component lifecycle methods (e.g. effects and did-mount/did-update).\n * Errors thrown in event handlers, or after async code has run, will not be caught.\n * This method is a way to imperatively trigger an error boundary during these phases.\n */\n showBoundary: (error: Error) => void;\n} {\n const context = useContext(ErrorBoundaryContext);\n\n assertErrorBoundaryContext(context);\n\n const { error, resetErrorBoundary } = context;\n\n const [state, setState] = useState<UseErrorBoundaryState>({\n error: null,\n hasError: false,\n });\n\n const memoized = useMemo(\n () => ({\n error,\n resetBoundary: () => {\n resetErrorBoundary();\n setState({ error: null, hasError: false });\n },\n showBoundary: (error: Error) =>\n setState({\n error,\n hasError: true,\n }),\n }),\n [error, resetErrorBoundary],\n );\n\n if (state.hasError) {\n throw state.error;\n }\n\n return memoized;\n}\n","import {\n createElement,\n forwardRef,\n type ComponentClass,\n type ComponentType,\n} from \"react\";\nimport { ErrorBoundary } from \"../components/ErrorBoundary\";\nimport type { ErrorBoundaryProps } from \"../types\";\n\nexport function withErrorBoundary<\n Type extends ComponentClass<unknown>,\n Props extends object,\n>(Component: ComponentType<Props>, errorBoundaryProps: ErrorBoundaryProps) {\n const Wrapped = forwardRef<InstanceType<Type>, Props>((props, ref) =>\n createElement(\n ErrorBoundary,\n errorBoundaryProps,\n createElement(Component, { ...props, ref } as 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"],"names":["ErrorBoundaryContext","createContext","initialState","ErrorBoundary","Component","props","error","args","info","prevProps","prevState","didCatch","resetKeys","hasArrayChanged","children","fallbackRender","FallbackComponent","fallback","childToRender","createElement","a","b","item","index","isErrorBoundaryContext","value","assertErrorBoundaryContext","useErrorBoundary","context","useContext","resetErrorBoundary","state","setState","useState","memoized","useMemo","withErrorBoundary","errorBoundaryProps","Wrapped","forwardRef","ref","name"],"mappings":";;AAQO,MAAMA,IACXC,EAA+C,IAAI,GCO/CC,IAAmC;AAAA,EACvC,UAAU;AAAA,EACV,OAAO;AACT;AAYO,MAAMC,UAAsBC,EAGjC;AAAA,EACA,YAAYC,GAA2B;AACrC,UAAMA,CAAK,GAEX,KAAK,qBAAqB,KAAK,mBAAmB,KAAK,IAAI,GAC3D,KAAK,QAAQH;AAAA,EACf;AAAA,EAEA,OAAO,yBAAyBI,GAAc;AAC5C,WAAO,EAAE,UAAU,IAAM,OAAAA,EAAA;AAAA,EAC3B;AAAA,EAEA,sBAAsBC,GAAiB;AACrC,UAAM,EAAE,OAAAD,MAAU,KAAK;AAEvB,IAAIA,MAAU,SACZ,KAAK,MAAM,UAAU;AAAA,MACnB,MAAAC;AAAA,MACA,QAAQ;AAAA,IAAA,CACT,GAED,KAAK,SAASL,CAAY;AAAA,EAE9B;AAAA,EAEA,kBAAkBI,GAAcE,GAAiB;AAC/C,SAAK,MAAM,UAAUF,GAAOE,CAAI;AAAA,EAClC;AAAA,EAEA,mBACEC,GACAC,GACA;AACA,UAAM,EAAE,UAAAC,MAAa,KAAK,OACpB,EAAE,WAAAC,MAAc,KAAK;AAO3B,IACED,KACAD,EAAU,UAAU,QACpBG,EAAgBJ,EAAU,WAAWG,CAAS,MAE9C,KAAK,MAAM,UAAU;AAAA,MACnB,MAAMA;AAAA,MACN,MAAMH,EAAU;AAAA,MAChB,QAAQ;AAAA,IAAA,CACT,GAED,KAAK,SAASP,CAAY;AAAA,EAE9B;AAAA,EAEA,SAAS;AACP,UAAM,EAAE,UAAAY,GAAU,gBAAAC,GAAgB,mBAAAC,GAAmB,UAAAC,EAAA,IACnD,KAAK,OACD,EAAE,UAAAN,GAAU,OAAAL,EA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;AAAA,MACL,OAAA7B;AAAA,MACA,eAAe,MAAM;AACnB,QAAAwB,EAAA,GACAE,EAAS,EAAE,OAAO,MAAM,UAAU,IAAO;AAAA,MAC3C;AAAA,MACA,cAAc,CAAC1B,MACb0B,EAAS;AAAA,QACP,OAAA1B;AAAAA,QACA,UAAU;AAAA,MAAA,CACX;AAAA,IAAA;AAAA,IAEL,CAACA,GAAOwB,CAAkB;AAAA,EAAA;AAG5B,MAAIC,EAAM;AACR,UAAMA,EAAM;AAGd,SAAOG;AACT;AC9DO,SAASE,EAGdhC,GAAiCiC,GAAwC;AACzE,QAAMC,IAAUC;AAAA,IAAsC,CAAClC,GAAOmC,MAC5DrB;AAAA,MACEhB;AAAA,MACAkC;AAAA,MACAlB,EAAcf,GAAW,EAAE,GAAGC,GAAO,KAAAmC,GAAc;AAAA,IAAA;AAAA,EACrD,GAIIC,IAAOrC,EAAU,eAAeA,EAAU,QAAQ;AACxD,SAAAkC,EAAQ,cAAc,qBAAqBG,CAAI,KAExCH;AACT;"}
1
+ {"version":3,"file":"react-error-boundary.js","sources":["../lib/context/ErrorBoundaryContext.ts","../lib/components/ErrorBoundary.tsx","../lib/utils/isErrorBoundaryContext.ts","../lib/utils/assertErrorBoundaryContext.ts","../lib/hooks/useErrorBoundary.ts","../lib/utils/withErrorBoundary.ts"],"sourcesContent":["import { createContext } from \"react\";\n\nexport type ErrorBoundaryContextType = {\n didCatch: boolean;\n error: Error | null;\n resetErrorBoundary: (...args: unknown[]) => void;\n};\n\nexport const ErrorBoundaryContext =\n createContext<ErrorBoundaryContextType | null>(null);\n","import { Component, createElement, type ErrorInfo } from \"react\";\nimport { ErrorBoundaryContext } from \"../context/ErrorBoundaryContext\";\nimport type { ErrorBoundaryProps, FallbackProps } from \"../types\";\n\nconst isDevelopment = import.meta.env.DEV;\n\ntype ErrorBoundaryState =\n | {\n didCatch: true;\n error: Error;\n }\n | {\n didCatch: false;\n error: null;\n };\n\nconst initialState: ErrorBoundaryState = {\n didCatch: false,\n error: null,\n};\n\n/**\n * A reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component.\n * Wrap this component around other React components to \"catch\" errors and render a fallback UI.\n *\n * This package is built on top of React [error boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary),\n * so it has all of the advantages and constraints of that API.\n * This means that it can't catch errors during:\n * - Server side rendering</li>\n * - Event handlers\n * - Asynchronous code (including effects)\n *\n * ℹ️ The component provides several ways to render a fallback: `fallback`, `fallbackRender`, and `FallbackComponent`.\n * Refer to the documentation to determine which is best for your application.\n *\n * ℹ️ This 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.\n */\nexport class ErrorBoundary extends Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n\n this.resetErrorBoundary = this.resetErrorBoundary.bind(this);\n this.state = initialState;\n }\n\n static getDerivedStateFromError(error: Error) {\n return { didCatch: true, error };\n }\n\n resetErrorBoundary(...args: unknown[]) {\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 (typeof fallbackRender === \"function\") {\n childToRender = fallbackRender(props);\n } else if (FallbackComponent) {\n childToRender = createElement(FallbackComponent, props);\n } else if (fallback !== undefined) {\n childToRender = fallback;\n } else {\n if (isDevelopment) {\n console.error(\n \"react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop\",\n );\n }\n\n throw error;\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: unknown[] = [], b: unknown[] = []) {\n return (\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n );\n}\n","import type { ErrorBoundaryContextType } from \"../context/ErrorBoundaryContext\";\n\nexport function isErrorBoundaryContext(\n value: unknown,\n): value is ErrorBoundaryContextType {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"didCatch\" in value &&\n typeof value.didCatch === \"boolean\" &&\n \"error\" in value &&\n \"resetErrorBoundary\" in value &&\n typeof value.resetErrorBoundary === \"function\"\n );\n}\n","import type { ErrorBoundaryContextType } from \"../context/ErrorBoundaryContext\";\nimport { isErrorBoundaryContext } from \"./isErrorBoundaryContext\";\n\nexport function assertErrorBoundaryContext(\n value: unknown,\n): asserts value is ErrorBoundaryContextType {\n if (!isErrorBoundaryContext(value)) {\n throw new Error(\"ErrorBoundaryContext not found\");\n }\n}\n","import { useContext, useMemo, useState } from \"react\";\nimport { ErrorBoundaryContext } from \"../context/ErrorBoundaryContext\";\nimport { assertErrorBoundaryContext } from \"../utils/assertErrorBoundaryContext\";\n\ntype UseErrorBoundaryState =\n | { error: Error; hasError: true }\n | { error: null; hasError: false };\n\nexport type UseErrorBoundaryApi = {\n error: Error | null;\n resetBoundary: () => void;\n showBoundary: (error: Error) => void;\n};\n\n/**\n * Convenience hook for imperatively showing or dismissing error boundaries.\n *\n * ⚠️ This hook must only be used within an `ErrorBoundary` subtree.\n */\nexport function useErrorBoundary(): {\n /**\n * The currently visible `Error` (if one has been thrown).\n */\n error: Error | null;\n\n /**\n * Method to reset and retry the nearest active error boundary (if one is active).\n */\n resetBoundary: () => void;\n\n /**\n * Trigger the nearest error boundary to display the error provided.\n *\n * ℹ️ React only handles errors thrown during render or during component lifecycle methods (e.g. effects and did-mount/did-update).\n * Errors thrown in event handlers, or after async code has run, will not be caught.\n * This method is a way to imperatively trigger an error boundary during these phases.\n */\n showBoundary: (error: Error) => void;\n} {\n const context = useContext(ErrorBoundaryContext);\n\n assertErrorBoundaryContext(context);\n\n const { error, resetErrorBoundary } = context;\n\n const [state, setState] = useState<UseErrorBoundaryState>({\n error: null,\n hasError: false,\n });\n\n const memoized = useMemo(\n () => ({\n error,\n resetBoundary: () => {\n resetErrorBoundary();\n setState({ error: null, hasError: false });\n },\n showBoundary: (error: Error) =>\n setState({\n error,\n hasError: true,\n }),\n }),\n [error, resetErrorBoundary],\n );\n\n if (state.hasError) {\n throw state.error;\n }\n\n return memoized;\n}\n","import {\n createElement,\n forwardRef,\n type ComponentClass,\n type ComponentType,\n} from \"react\";\nimport { ErrorBoundary } from \"../components/ErrorBoundary\";\nimport type { ErrorBoundaryProps } from \"../types\";\n\nexport function withErrorBoundary<\n Type extends ComponentClass<unknown>,\n Props extends object,\n>(Component: ComponentType<Props>, errorBoundaryProps: ErrorBoundaryProps) {\n const Wrapped = forwardRef<InstanceType<Type>, Props>((props, ref) =>\n createElement(\n ErrorBoundary,\n errorBoundaryProps,\n createElement(Component, { ...props, ref } as 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"],"names":["ErrorBoundaryContext","createContext","initialState","ErrorBoundary","Component","props","error","args","info","prevProps","prevState","didCatch","resetKeys","hasArrayChanged","children","fallbackRender","FallbackComponent","fallback","childToRender","createElement","a","b","item","index","isErrorBoundaryContext","value","assertErrorBoundaryContext","useErrorBoundary","context","useContext","resetErrorBoundary","state","setState","useState","memoized","useMemo","withErrorBoundary","errorBoundaryProps","Wrapped","forwardRef","ref","name"],"mappings":";;AAQO,MAAMA,IACXC,EAA+C,IAAI,GCO/CC,IAAmC;AAAA,EACvC,UAAU;AAAA,EACV,OAAO;AACT;AAkBO,MAAMC,UAAsBC,EAGjC;AAAA,EACA,YAAYC,GAA2B;AACrC,UAAMA,CAAK,GAEX,KAAK,qBAAqB,KAAK,mBAAmB,KAAK,IAAI,GAC3D,KAAK,QAAQH;AAAA,EACf;AAAA,EAEA,OAAO,yBAAyBI,GAAc;AAC5C,WAAO,EAAE,UAAU,IAAM,OAAAA,EAAA;AAAA,EAC3B;AAAA,EAEA,sBAAsBC,GAAiB;AACrC,UAAM,EAAE,OAAAD,MAAU,KAAK;AAEvB,IAAIA,MAAU,SACZ,KAAK,MAAM,UAAU;AAAA,MACnB,MAAAC;AAAA,MACA,QAAQ;AAAA,IAAA,CACT,GAED,KAAK,SAASL,CAAY;AAAA,EAE9B;AAAA,EAEA,kBAAkBI,GAAcE,GAAiB;AAC/C,SAAK,MAAM,UAAUF,GAAOE,CAAI;AAAA,EAClC;AAAA,EAEA,mBACEC,GACAC,GACA;AACA,UAAM,EAAE,UAAAC,MAAa,KAAK,OACpB,EAAE,WAAAC,MAAc,KAAK;AAO3B,IACED,KACAD,EAAU,UAAU,QACpBG,EAAgBJ,EAAU,WAAWG,CAAS,MAE9C,KAAK,MAAM,UAAU;AAAA,MACnB,MAAMA;AAAA,MACN,MAAMH,EAAU;AAAA,MAChB,QAAQ;AAAA,IAAA,CACT,GAED,KAAK,SAASP,CAAY;AAAA,EAE9B;AAAA,EAEA,SAAS;AACP,UAAM,EAAE,UAAAY,GAAU,gBAAAC,GAAgB,mBAAAC,GAAmB,UAAAC,EAAA,IACnD,KAAK,OACD,EAAE,UAAAN,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AAAA,IACf,OAAO;AAAA,MACL,OAAA7B;AAAA,MACA,eAAe,MAAM;AACnB,QAAAwB,EAAA,GACAE,EAAS,EAAE,OAAO,MAAM,UAAU,IAAO;AAAA,MAC3C;AAAA,MACA,cAAc,CAAC1B,MACb0B,EAAS;AAAA,QACP,OAAA1B;AAAAA,QACA,UAAU;AAAA,MAAA,CACX;AAAA,IAAA;AAAA,IAEL,CAACA,GAAOwB,CAAkB;AAAA,EAAA;AAG5B,MAAIC,EAAM;AACR,UAAMA,EAAM;AAGd,SAAOG;AACT;AC9DO,SAASE,EAGdhC,GAAiCiC,GAAwC;AACzE,QAAMC,IAAUC;AAAA,IAAsC,CAAClC,GAAOmC,MAC5DrB;AAAA,MACEhB;AAAA,MACAkC;AAAA,MACAlB,EAAcf,GAAW,EAAE,GAAGC,GAAO,KAAAmC,GAAc;AAAA,IAAA;AAAA,EACrD,GAIIC,IAAOrC,EAAU,eAAeA,EAAU,QAAQ;AACxD,SAAAkC,EAAQ,cAAc,qBAAqBG,CAAI,KAExCH;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-error-boundary",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "type": "module",
5
5
  "description": "Simple reusable React error boundary component",
6
6
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
@@ -12,7 +12,7 @@
12
12
  "contributors": [
13
13
  "Brian Vaughn <brian.david.vaughn@gmail.com> (https://github.com/bvaughn/)"
14
14
  ],
15
- "homepage": "http://react-error-boundary.now.sh/",
15
+ "homepage": "https://react-error-boundary-lib.vercel.app/",
16
16
  "keywords": [
17
17
  "react",
18
18
  "reactjs",
@@ -35,12 +35,14 @@
35
35
  ],
36
36
  "scripts": {
37
37
  "dev": "vite",
38
+ "dev:integrations": "pnpm -C integrations/vite/ run dev",
38
39
  "build": "pnpm run build:lib && pnpm run build:docs",
39
40
  "build:docs": "TARGET=docs vite build",
40
41
  "build:lib": "TARGET=lib vite build",
41
42
  "compile": "pnpm run compile:docs && pnpm run compile:examples",
42
43
  "compile:docs": "tsx ./scripts/compile-docs",
43
44
  "compile:examples": "tsx ./scripts/compile-examples",
45
+ "compress:og-image": "tsx ./scripts/compress-og-image",
44
46
  "lint": "eslint .",
45
47
  "prerelease": "rm -rf dist && pnpm run build:lib",
46
48
  "prettier": "prettier --write \"**/*.{css,html,js,json,jsx,ts,tsx}\"",
@@ -59,38 +61,31 @@
59
61
  "react-dom": "^18.0.0 || ^19.0.0"
60
62
  },
61
63
  "devDependencies": {
62
- "@codemirror/lang-css": "latest",
63
- "@codemirror/lang-html": "latest",
64
- "@codemirror/lang-javascript": "latest",
65
- "@codemirror/lang-markdown": "latest",
66
- "@codemirror/language": "latest",
67
- "@codemirror/state": "latest",
68
64
  "@csstools/postcss-oklab-function": "^4.0.11",
69
65
  "@eslint/js": "^9.30.1",
70
66
  "@headlessui/react": "^2.2.4",
71
67
  "@headlessui/tailwindcss": "^0.2.2",
72
68
  "@heroicons/react": "^2.2.0",
73
- "@lezer/highlight": "latest",
74
69
  "@tailwindcss/vite": "^4.1.11",
75
70
  "@tailwindplus/elements": "^1.0.5",
76
71
  "@testing-library/jest-dom": "^6.6.4",
77
72
  "@testing-library/react": "^16.3.0",
78
73
  "@testing-library/user-event": "^14.6.1",
79
- "@ts-ast-parser/core": "^0.8.0",
74
+ "@types/bytes": "^3.1.5",
80
75
  "@types/compression": "^1.8.1",
81
- "@types/express": "^5.0.5",
82
76
  "@types/markdown-it": "^14.1.2",
83
77
  "@types/node": "^24.2.0",
84
78
  "@types/react": "^19.1.8",
85
79
  "@types/react-dom": "^19.2.3",
80
+ "@types/sharp": "^0.32.0",
86
81
  "@vitejs/plugin-react-swc": "^3.10.2",
82
+ "bytes": "^3.1.2",
87
83
  "clsx": "^2.1.1",
88
84
  "compression": "^1.8.1",
89
85
  "csstype": "^3.1.3",
90
86
  "eslint": "^9.30.1",
91
87
  "eslint-plugin-react-hooks": "^5.2.0",
92
88
  "eslint-plugin-react-refresh": "^0.4.20",
93
- "express": "^5.1.0",
94
89
  "globals": "^16.3.0",
95
90
  "husky": "^9.1.7",
96
91
  "jsdom": "^26.1.0",
@@ -104,11 +99,12 @@
104
99
  "react-docgen-typescript": "^2.4.0",
105
100
  "react-dom": "^19.2.3",
106
101
  "react-error-boundary": "^6.0.0",
107
- "react-lib-tools": "^0.0.10",
102
+ "react-lib-tools": "^0.0.30",
108
103
  "react-router-dom": "^7.6.3",
109
104
  "rollup-plugin-terser": "^7.0.2",
110
105
  "rollup-plugin-visualizer": "^6.0.3",
111
106
  "rollup-preserve-directives": "^1.1.3",
107
+ "sharp": "^0.34.5",
112
108
  "sirv": "^3.0.2",
113
109
  "tailwind-merge": "^3.3.1",
114
110
  "tailwindcss": "^4.1.11",