react-error-boundary 4.0.4 → 4.0.6

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.
@@ -45,12 +45,12 @@ type ErrorBoundaryState = {
45
45
  error: any;
46
46
  };
47
47
  export class ErrorBoundary extends Component<PropsWithRef<PropsWithChildren<ErrorBoundaryProps>>, ErrorBoundaryState> {
48
- state: ErrorBoundaryState;
48
+ constructor(props: ErrorBoundaryProps);
49
49
  static getDerivedStateFromError(error: Error): {
50
50
  didCatch: boolean;
51
51
  error: Error;
52
52
  };
53
- resetErrorBoundary: (...args: any[]) => void;
53
+ resetErrorBoundary(...args: any[]): void;
54
54
  componentDidCatch(error: Error, info: ErrorInfo): void;
55
55
  componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState): void;
56
56
  render(): ReactElement<any, string | import("react").JSXElementConstructor<any>>;
@@ -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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K,IAAI;IACvC,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,YAAY,EAAE,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"}
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;IACn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EAAE,KAAK,EAAE,IAAI,EAAE,SAAS;IAI/C,kBAAkB,CAChB,SAAS,EAAE,kBAAkB,EAC7B,SAAS,EAAE,kBAAkB;IAyB/B,MAAM;CAsCP;AEhHD,gCAAgC,KAAK,IAAI;IACvC,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,YAAY,EAAE,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,"export * 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"}
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  var $8zHUo$react = require("react");
2
4
 
3
5
  function $parcel$exportWildcard(dest, source) {
@@ -35,14 +37,18 @@ const $6d6d4999e62b3ee0$var$initialState = {
35
37
  error: null
36
38
  };
37
39
  class $6d6d4999e62b3ee0$export$e926676385687eaf extends (0, $8zHUo$react.Component) {
38
- state = $6d6d4999e62b3ee0$var$initialState;
40
+ constructor(props){
41
+ super(props);
42
+ this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
43
+ this.state = $6d6d4999e62b3ee0$var$initialState;
44
+ }
39
45
  static getDerivedStateFromError(error) {
40
46
  return {
41
47
  didCatch: true,
42
48
  error: error
43
49
  };
44
50
  }
45
- resetErrorBoundary = (...args)=>{
51
+ resetErrorBoundary(...args) {
46
52
  const { error: error } = this.state;
47
53
  if (error !== null) {
48
54
  this.props.onReset?.({
@@ -51,7 +57,7 @@ class $6d6d4999e62b3ee0$export$e926676385687eaf extends (0, $8zHUo$react.Compone
51
57
  });
52
58
  this.setState($6d6d4999e62b3ee0$var$initialState);
53
59
  }
54
- };
60
+ }
55
61
  componentDidCatch(error, info) {
56
62
  this.props.onError?.(error, info);
57
63
  }
@@ -158,7 +164,6 @@ function $9e88dd86e0bb2944$export$f0c7a449e0cfaec7(component, errorBoundaryProps
158
164
  var $faefaad95e5fcca0$exports = {};
159
165
 
160
166
 
161
- "use client";
162
167
  $parcel$exportWildcard(module.exports, $6d6d4999e62b3ee0$exports);
163
168
  $parcel$exportWildcard(module.exports, $4a61716688322eb0$exports);
164
169
  $parcel$exportWildcard(module.exports, $3c4937b727a6fcfb$exports);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;ACAA;;;;ACAA;AAQO,MAAM,4CACX,CAAA,GAAA,0BAAY,EAAmC,IAAI;;;ADKrD,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,I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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
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEQO,MAAM,4CACX,CAAA,GAAA,0BAAY,EAAmC;;;ADKjD,MAAM,qCAAmC;IACvC,UAAU;IACV,OAAO;AACT;AAEO,MAAM,kDAAsB,CAAA,GAAA,sBAAQ;IAIzC,YAAY,KAAyB,CAAE;QACrC,KAAK,CAAC;QAEN,IAAI,CAAC,qBAAqB,IAAI,CAAC,mBAAmB,KAAK,IAAI;QAC3D,IAAI,CAAC,QAAQ;IACf;IAEA,OAAO,yBAAyB,KAAY,EAAE;QAC5C,OAAO;YAAE,UAAU;mBAAM;QAAM;IACjC;IAEA,mBAAmB,GAAG,IAAW,EAAE;QACjC,MAAM,SAAE,MAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,UAAU,MAAM;YAClB,IAAI,CAAC,MAAM,UAAU;sBACnB;gBACA,QAAQ;YACV;YAEA,IAAI,CAAC,SAAS;QAChB;IACF;IAEA,kBAAkB,KAAY,EAAE,IAAe,EAAE;QAC/C,IAAI,CAAC,MAAM,UAAU,OAAO;IAC9B;IAEA,mBACE,SAA6B,EAC7B,SAA6B,EAC7B;QACA,MAAM,YAAE,SAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,MAAM,aAAE,UAAS,EAAE,GAAG,IAAI,CAAC;QAE3B,gHAAgH;QAChH,wDAAwD;QACxD,yDAAyD;QACzD,qGAAqG;QAErG,IACE,YACA,UAAU,UAAU,Q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G9B;QACD,OAAO;QACP,UAAU;IACZ;IAEA,MAAM,WAAW,CAAA,GAAA,oBAAM,EACrB,IAAO,CAAA;YACL,eAAe;gBACb,SAAS;gBACT,SAAS;oBAAE,OAAO;oBAAM,UAAU;gBAAM;YAC1C;YACA,cAAc,CAAC,QACb,SAAS;2BACP;oBACA,UAAU;gBACZ;QACJ,CAAA,GACA;QAAC,SAAS;KAAmB;IAG/B,IAAI,MAAM,UACR,MAAM,MAAM;IAGd,OAAO;AACT;;;;;;;;AE9BO,SAAS,0CACd,SAA+B,EAC/B,kBAAsC;IAEtC,MAAM,UAAU,CAAA,GAAA,uBAAS,EACvB,CAAC,OAAc,MACb,CAAA,GAAA,0BAAY,EACV,CAAA,GAAA,yCAAY,GACZ,oBACA,CAAA,GAAA,0BAAY,EAAE,WAAW;YAAE,GAAG,KAAK;iBAAE;QAAI;IAI/C,iCAAiC;IACjC,MAAM,OAAO,UAAU,eAAe,UAAU,QAAQ;IACxD,QAAQ,cAAc,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 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 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: 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,3 +1,5 @@
1
+ "use client";
2
+
1
3
  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
4
 
3
5
  function $parcel$export(e, n, v, s) {
@@ -19,14 +21,18 @@ const $44d7e150ebc754d2$var$initialState = {
19
21
  error: null
20
22
  };
21
23
  class $44d7e150ebc754d2$export$e926676385687eaf extends (0, $hgUW1$Component) {
22
- state = $44d7e150ebc754d2$var$initialState;
24
+ constructor(props){
25
+ super(props);
26
+ this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
27
+ this.state = $44d7e150ebc754d2$var$initialState;
28
+ }
23
29
  static getDerivedStateFromError(error) {
24
30
  return {
25
31
  didCatch: true,
26
32
  error: error
27
33
  };
28
34
  }
29
- resetErrorBoundary = (...args)=>{
35
+ resetErrorBoundary(...args) {
30
36
  const { error: error } = this.state;
31
37
  if (error !== null) {
32
38
  this.props.onReset?.({
@@ -35,7 +41,7 @@ class $44d7e150ebc754d2$export$e926676385687eaf extends (0, $hgUW1$Component) {
35
41
  });
36
42
  this.setState($44d7e150ebc754d2$var$initialState);
37
43
  }
38
- };
44
+ }
39
45
  componentDidCatch(error, info) {
40
46
  this.props.onError?.(error, info);
41
47
  }
@@ -142,7 +148,6 @@ function $62ff477d53f02a5b$export$f0c7a449e0cfaec7(component, errorBoundaryProps
142
148
  var $81c1b644006d48ec$exports = {};
143
149
 
144
150
 
145
- "use client";
146
151
 
147
152
 
148
153
  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,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,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,SAAS,0CACd,SAA+B,EAC/B,kBAAsC,EACkC;IACxE,MAAM,UAAU,CAAA,GAAA,iBAAU,AAAD,EACvB,CAAC,OAAc,MACb,CAAA,GAAA,oBAAY,EACV,CAAA,GAAA,yCAAa,AAAD,GACZ,oBACA,CAAA,GAAA,oBAAY,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.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;AEQO,MAAM,4CACX,CAAA,GAAA,oBAAY,EAAmC;;;ADKjD,MAAM,qCAAmC;IACvC,UAAU;IACV,OAAO;AACT;AAEO,MAAM,kDAAsB,CAAA,GAAA,gBAAQ;IAIzC,YAAY,KAAyB,CAAE;QACrC,KAAK,CAAC;QAEN,IAAI,CAAC,qBAAqB,IAAI,CAAC,mBAAmB,KAAK,IAAI;QAC3D,IAAI,CAAC,QAAQ;IACf;IAEA,OAAO,yBAAyB,KAAY,EAAE;QAC5C,OAAO;YAAE,UAAU;mBAAM;QAAM;IACjC;IAEA,mBAAmB,GAAG,IAAW,EAAE;QACjC,MAAM,SAAE,MAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,UAAU,MAAM;YAClB,IAAI,CAAC,MAAM,UAAU;sBACnB;gBACA,QAAQ;YACV;YAEA,IAAI,CAAC,S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M;AAE9E;;;;;;;;AGxHO,SAAS,0CACd,KAAU;IAEV,IACE,SAAS,QACT,OAAO,MAAM,aAAa,aAC1B,OAAO,MAAM,uBAAuB,YAEpC,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;;;;ADLO,SAAS;IACd,MAAM,UAAU,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,yCAAmB;IAE9C,CAAA,GAAA,yCAAyB,EAAE;IAE3B,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAG9B;QACD,OAAO;QACP,UAAU;IACZ;IAEA,MAAM,WAAW,CAAA,GAAA,cAAM,EACrB,IAAO,CAAA;YACL,eAAe;gBACb,SAAS;gBACT,SAAS;oBAAE,OAAO;oBAAM,UAAU;gBAAM;YAC1C;YACA,cAAc,CAAC,QACb,SAAS;2BACP;oBACA,UAAU;gBACZ;QACJ,CAAA,GACA;QAAC,SAAS;KAAmB;IAG/B,IAAI,MAAM,UACR,MAAM,MAAM;IAGd,OAAO;AACT;;;;;;;;AE9BO,SAAS,0CACd,SAA+B,EAC/B,kBAAsC;IAEtC,MAAM,UAAU,CAAA,GAAA,iBAAS,EACvB,CAAC,OAAc,MACb,CAAA,GAAA,oBAAY,EACV,CAAA,GAAA,yCAAY,GACZ,oBACA,CAAA,GAAA,oBAAY,EAAE,WAAW;YAAE,GAAG,KAAK;iBAAE;QAAI;IAI/C,iCAAiC;IACjC,MAAM,OAAO,UAAU,eAAe,UAAU,QAAQ;IACxD,QAAQ,cAAc,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 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 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: 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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-error-boundary",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "description": "Simple reusable React error boundary component",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
@@ -15,12 +15,13 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
+ "sideEffects": false,
18
19
  "scripts": {
19
20
  "clear": "npm run clear:parcel-cache & npm run clear:builds & npm run clear:node_modules",
20
- "clear:builds": "rm -rf ./packages/*/dist",
21
+ "clear:builds": "rm -rf ./dist",
21
22
  "clear:parcel-cache": "rm -rf ./.parcel-cache",
22
23
  "clear:node_modules": "rm -rf ./node_modules",
23
- "prerelease": "rm -rf ./.parcel-cache && parcel build",
24
+ "prerelease": "rm -rf ./.parcel-cache && parcel build && ./postprocess.js",
24
25
  "prettier": "prettier --write \"**/*.{css,html,js,json,jsx,ts,tsx}\"",
25
26
  "prettier:ci": "prettier --check \"**/*.{css,html,js,json,jsx,ts,tsx}\"",
26
27
  "test": "jest",
@@ -32,15 +33,15 @@
32
33
  "@babel/runtime": "^7.12.5"
33
34
  },
34
35
  "devDependencies": {
35
- "@parcel/core": "^2.8.3",
36
- "@parcel/packager-ts": "^2.8.3",
37
- "@parcel/transformer-typescript-types": "^2.8.3",
36
+ "@parcel/core": "^2.9.0",
37
+ "@parcel/packager-ts": "^2.9.0",
38
+ "@parcel/transformer-typescript-types": "^2.9.0",
38
39
  "@types/jest": "^26.0.15",
39
40
  "@types/react": "^18",
40
41
  "@types/react-dom": "^18",
41
42
  "jest": "^29.4.3",
42
43
  "jest-environment-jsdom": "^29.4.3",
43
- "parcel": "^2.8.3",
44
+ "parcel": "^2.9.0",
44
45
  "prettier": "^2.8.6",
45
46
  "react": "^18",
46
47
  "react-dom": "^18",