react-error-boundary 3.1.4 → 4.0.0
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 +94 -398
- package/dist/react-error-boundary.d.ts +65 -0
- package/dist/react-error-boundary.d.ts.map +1 -0
- package/dist/react-error-boundary.js +166 -0
- package/dist/react-error-boundary.js.map +1 -0
- package/dist/react-error-boundary.module.js +146 -0
- package/dist/react-error-boundary.module.js.map +1 -0
- package/package.json +28 -33
- package/CHANGELOG.md +0 -5
- package/dist/index.d.ts +0 -58
- package/dist/react-error-boundary.cjs.d.ts +0 -1
- package/dist/react-error-boundary.cjs.js +0 -171
- package/dist/react-error-boundary.esm.d.ts +0 -1
- package/dist/react-error-boundary.esm.js +0 -142
- package/dist/react-error-boundary.umd.d.ts +0 -1
- package/dist/react-error-boundary.umd.js +0 -187
- package/dist/react-error-boundary.umd.js.map +0 -1
- package/dist/react-error-boundary.umd.min.d.ts +0 -1
- package/dist/react-error-boundary.umd.min.js +0 -2
- package/dist/react-error-boundary.umd.min.js.map +0 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
var $8zHUo$react = require("react");
|
|
2
|
+
|
|
3
|
+
function $parcel$exportWildcard(dest, source) {
|
|
4
|
+
Object.keys(source).forEach(function(key) {
|
|
5
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(dest, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function get() {
|
|
12
|
+
return source[key];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return dest;
|
|
18
|
+
}
|
|
19
|
+
function $parcel$export(e, n, v, s) {
|
|
20
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
21
|
+
}
|
|
22
|
+
var $6d6d4999e62b3ee0$exports = {};
|
|
23
|
+
|
|
24
|
+
$parcel$export($6d6d4999e62b3ee0$exports, "ErrorBoundary", () => $6d6d4999e62b3ee0$export$e926676385687eaf);
|
|
25
|
+
|
|
26
|
+
var $4a61716688322eb0$exports = {};
|
|
27
|
+
|
|
28
|
+
$parcel$export($4a61716688322eb0$exports, "ErrorBoundaryContext", () => $4a61716688322eb0$export$b16d9fb1a22de840);
|
|
29
|
+
|
|
30
|
+
const $4a61716688322eb0$export$b16d9fb1a22de840 = (0, $8zHUo$react.createContext)(null);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const $6d6d4999e62b3ee0$var$initialState = {
|
|
34
|
+
didCatch: false,
|
|
35
|
+
error: null
|
|
36
|
+
};
|
|
37
|
+
class $6d6d4999e62b3ee0$export$e926676385687eaf extends (0, $8zHUo$react.Component) {
|
|
38
|
+
state = $6d6d4999e62b3ee0$var$initialState;
|
|
39
|
+
static getDerivedStateFromError(error) {
|
|
40
|
+
return {
|
|
41
|
+
didCatch: true,
|
|
42
|
+
error: error
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
resetErrorBoundary = (...args)=>{
|
|
46
|
+
const { error: error } = this.state;
|
|
47
|
+
if (error !== null) {
|
|
48
|
+
this.props.onReset?.({
|
|
49
|
+
args: args,
|
|
50
|
+
reason: "imperative-api"
|
|
51
|
+
});
|
|
52
|
+
this.setState($6d6d4999e62b3ee0$var$initialState);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
componentDidCatch(error, info) {
|
|
56
|
+
this.props.onError?.(error, info);
|
|
57
|
+
}
|
|
58
|
+
componentDidUpdate(prevProps, prevState) {
|
|
59
|
+
const { didCatch: didCatch } = this.state;
|
|
60
|
+
const { resetKeys: resetKeys } = this.props;
|
|
61
|
+
// There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,
|
|
62
|
+
// we'd end up resetting the error boundary immediately.
|
|
63
|
+
// This would likely trigger a second error to be thrown.
|
|
64
|
+
// So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.
|
|
65
|
+
if (didCatch && prevState.error !== null && $6d6d4999e62b3ee0$var$hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
66
|
+
this.props.onReset?.({
|
|
67
|
+
next: resetKeys,
|
|
68
|
+
prev: prevProps.resetKeys,
|
|
69
|
+
reason: "keys"
|
|
70
|
+
});
|
|
71
|
+
this.setState($6d6d4999e62b3ee0$var$initialState);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
render() {
|
|
75
|
+
const { children: children , fallbackRender: fallbackRender , FallbackComponent: FallbackComponent , fallback: fallback } = this.props;
|
|
76
|
+
const { didCatch: didCatch , error: error } = this.state;
|
|
77
|
+
if (didCatch) {
|
|
78
|
+
const props = {
|
|
79
|
+
error: error,
|
|
80
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
81
|
+
};
|
|
82
|
+
if ((0, $8zHUo$react.isValidElement)(fallback)) return fallback;
|
|
83
|
+
else if (typeof fallbackRender === "function") return fallbackRender(props);
|
|
84
|
+
else if (FallbackComponent) return (0, $8zHUo$react.createElement)(FallbackComponent, props);
|
|
85
|
+
else throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");
|
|
86
|
+
}
|
|
87
|
+
return (0, $8zHUo$react.createElement)((0, $4a61716688322eb0$export$b16d9fb1a22de840).Provider, {
|
|
88
|
+
value: {
|
|
89
|
+
didCatch: didCatch,
|
|
90
|
+
error: error,
|
|
91
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
92
|
+
}
|
|
93
|
+
}, children);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function $6d6d4999e62b3ee0$var$hasArrayChanged(a = [], b = []) {
|
|
97
|
+
return a.length !== b.length || a.some((item, index)=>!Object.is(item, b[index]));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
var $3c4937b727a6fcfb$exports = {};
|
|
103
|
+
|
|
104
|
+
$parcel$export($3c4937b727a6fcfb$exports, "useErrorBoundary", () => $3c4937b727a6fcfb$export$c052f6604b7d51fe);
|
|
105
|
+
|
|
106
|
+
function $f8678e3a8e88e8a4$export$f20aa86254872370(value) {
|
|
107
|
+
if (value == null || typeof value.didCatch !== "boolean" || typeof value.resetErrorBoundary !== "function") throw new Error("ErrorBoundaryContext not found");
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
function $3c4937b727a6fcfb$export$c052f6604b7d51fe() {
|
|
114
|
+
const context = (0, $8zHUo$react.useContext)((0, $4a61716688322eb0$export$b16d9fb1a22de840));
|
|
115
|
+
(0, $f8678e3a8e88e8a4$export$f20aa86254872370)(context);
|
|
116
|
+
const [state, setState] = (0, $8zHUo$react.useState)({
|
|
117
|
+
error: null,
|
|
118
|
+
hasError: false
|
|
119
|
+
});
|
|
120
|
+
const memoized = (0, $8zHUo$react.useMemo)(()=>({
|
|
121
|
+
resetBoundary: ()=>{
|
|
122
|
+
context?.resetErrorBoundary();
|
|
123
|
+
setState({
|
|
124
|
+
error: null,
|
|
125
|
+
hasError: false
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
showBoundary: (error)=>setState({
|
|
129
|
+
error: error,
|
|
130
|
+
hasError: true
|
|
131
|
+
})
|
|
132
|
+
}), [
|
|
133
|
+
context?.resetErrorBoundary
|
|
134
|
+
]);
|
|
135
|
+
if (state.hasError) throw state.error;
|
|
136
|
+
return memoized;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
var $9e88dd86e0bb2944$exports = {};
|
|
141
|
+
|
|
142
|
+
$parcel$export($9e88dd86e0bb2944$exports, "withErrorBoundary", () => $9e88dd86e0bb2944$export$f0c7a449e0cfaec7);
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
function $9e88dd86e0bb2944$export$f0c7a449e0cfaec7(Component, errorBoundaryProps) {
|
|
146
|
+
const Wrapped = (props)=>{
|
|
147
|
+
return (0, $8zHUo$react.createElement)((0, $6d6d4999e62b3ee0$export$e926676385687eaf), errorBoundaryProps, (0, $8zHUo$react.createElement)(Component, props));
|
|
148
|
+
};
|
|
149
|
+
// Format for display in DevTools
|
|
150
|
+
const name = Component.displayName || Component.name || "Unknown";
|
|
151
|
+
Wrapped.displayName = `withErrorBoundary(${name})`;
|
|
152
|
+
return Wrapped;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
var $faefaad95e5fcca0$exports = {};
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
$parcel$exportWildcard(module.exports, $6d6d4999e62b3ee0$exports);
|
|
160
|
+
$parcel$exportWildcard(module.exports, $4a61716688322eb0$exports);
|
|
161
|
+
$parcel$exportWildcard(module.exports, $3c4937b727a6fcfb$exports);
|
|
162
|
+
$parcel$exportWildcard(module.exports, $9e88dd86e0bb2944$exports);
|
|
163
|
+
$parcel$exportWildcard(module.exports, $faefaad95e5fcca0$exports);
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
//# sourceMappingURL=react-error-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;ACAA;;;;ACAA;AAQO,MAAM,4CACX,CAAA,GAAA,0BAAY,EAAmC,IAAI;;;ADOrD,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;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AAE,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 {\n ErrorBoundaryContextType,\n ErrorBoundaryContext,\n} 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 if (didCatch) {\n const props: FallbackProps = {\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n };\n\n if (isValidElement(fallback)) {\n return fallback;\n } else if (typeof fallbackRender === \"function\") {\n return fallbackRender(props);\n } else if (FallbackComponent) {\n return 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 children\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: false;\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"}
|
|
@@ -0,0 +1,146 @@
|
|
|
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";
|
|
2
|
+
|
|
3
|
+
function $parcel$export(e, n, v, s) {
|
|
4
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
5
|
+
}
|
|
6
|
+
var $44d7e150ebc754d2$exports = {};
|
|
7
|
+
|
|
8
|
+
$parcel$export($44d7e150ebc754d2$exports, "ErrorBoundary", () => $44d7e150ebc754d2$export$e926676385687eaf);
|
|
9
|
+
|
|
10
|
+
var $ebb31c7feaa4405e$exports = {};
|
|
11
|
+
|
|
12
|
+
$parcel$export($ebb31c7feaa4405e$exports, "ErrorBoundaryContext", () => $ebb31c7feaa4405e$export$b16d9fb1a22de840);
|
|
13
|
+
|
|
14
|
+
const $ebb31c7feaa4405e$export$b16d9fb1a22de840 = (0, $hgUW1$createContext)(null);
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const $44d7e150ebc754d2$var$initialState = {
|
|
18
|
+
didCatch: false,
|
|
19
|
+
error: null
|
|
20
|
+
};
|
|
21
|
+
class $44d7e150ebc754d2$export$e926676385687eaf extends (0, $hgUW1$Component) {
|
|
22
|
+
state = $44d7e150ebc754d2$var$initialState;
|
|
23
|
+
static getDerivedStateFromError(error) {
|
|
24
|
+
return {
|
|
25
|
+
didCatch: true,
|
|
26
|
+
error: error
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
resetErrorBoundary = (...args)=>{
|
|
30
|
+
const { error: error } = this.state;
|
|
31
|
+
if (error !== null) {
|
|
32
|
+
this.props.onReset?.({
|
|
33
|
+
args: args,
|
|
34
|
+
reason: "imperative-api"
|
|
35
|
+
});
|
|
36
|
+
this.setState($44d7e150ebc754d2$var$initialState);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
componentDidCatch(error, info) {
|
|
40
|
+
this.props.onError?.(error, info);
|
|
41
|
+
}
|
|
42
|
+
componentDidUpdate(prevProps, prevState) {
|
|
43
|
+
const { didCatch: didCatch } = this.state;
|
|
44
|
+
const { resetKeys: resetKeys } = this.props;
|
|
45
|
+
// There's an edge case where if the thing that triggered the error happens to *also* be in the resetKeys array,
|
|
46
|
+
// we'd end up resetting the error boundary immediately.
|
|
47
|
+
// This would likely trigger a second error to be thrown.
|
|
48
|
+
// So we make sure that we don't check the resetKeys on the first call of cDU after the error is set.
|
|
49
|
+
if (didCatch && prevState.error !== null && $44d7e150ebc754d2$var$hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
50
|
+
this.props.onReset?.({
|
|
51
|
+
next: resetKeys,
|
|
52
|
+
prev: prevProps.resetKeys,
|
|
53
|
+
reason: "keys"
|
|
54
|
+
});
|
|
55
|
+
this.setState($44d7e150ebc754d2$var$initialState);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
render() {
|
|
59
|
+
const { children: children , fallbackRender: fallbackRender , FallbackComponent: FallbackComponent , fallback: fallback } = this.props;
|
|
60
|
+
const { didCatch: didCatch , error: error } = this.state;
|
|
61
|
+
if (didCatch) {
|
|
62
|
+
const props = {
|
|
63
|
+
error: error,
|
|
64
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
65
|
+
};
|
|
66
|
+
if ((0, $hgUW1$isValidElement)(fallback)) return fallback;
|
|
67
|
+
else if (typeof fallbackRender === "function") return fallbackRender(props);
|
|
68
|
+
else if (FallbackComponent) return (0, $hgUW1$createElement)(FallbackComponent, props);
|
|
69
|
+
else throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");
|
|
70
|
+
}
|
|
71
|
+
return (0, $hgUW1$createElement)((0, $ebb31c7feaa4405e$export$b16d9fb1a22de840).Provider, {
|
|
72
|
+
value: {
|
|
73
|
+
didCatch: didCatch,
|
|
74
|
+
error: error,
|
|
75
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
76
|
+
}
|
|
77
|
+
}, children);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function $44d7e150ebc754d2$var$hasArrayChanged(a = [], b = []) {
|
|
81
|
+
return a.length !== b.length || a.some((item, index)=>!Object.is(item, b[index]));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
var $7c3c25b3f398a9d6$exports = {};
|
|
87
|
+
|
|
88
|
+
$parcel$export($7c3c25b3f398a9d6$exports, "useErrorBoundary", () => $7c3c25b3f398a9d6$export$c052f6604b7d51fe);
|
|
89
|
+
|
|
90
|
+
function $75c9d331f9c1ed1a$export$f20aa86254872370(value) {
|
|
91
|
+
if (value == null || typeof value.didCatch !== "boolean" || typeof value.resetErrorBoundary !== "function") throw new Error("ErrorBoundaryContext not found");
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
function $7c3c25b3f398a9d6$export$c052f6604b7d51fe() {
|
|
98
|
+
const context = (0, $hgUW1$useContext)((0, $ebb31c7feaa4405e$export$b16d9fb1a22de840));
|
|
99
|
+
(0, $75c9d331f9c1ed1a$export$f20aa86254872370)(context);
|
|
100
|
+
const [state, setState] = (0, $hgUW1$useState)({
|
|
101
|
+
error: null,
|
|
102
|
+
hasError: false
|
|
103
|
+
});
|
|
104
|
+
const memoized = (0, $hgUW1$useMemo)(()=>({
|
|
105
|
+
resetBoundary: ()=>{
|
|
106
|
+
context?.resetErrorBoundary();
|
|
107
|
+
setState({
|
|
108
|
+
error: null,
|
|
109
|
+
hasError: false
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
showBoundary: (error)=>setState({
|
|
113
|
+
error: error,
|
|
114
|
+
hasError: true
|
|
115
|
+
})
|
|
116
|
+
}), [
|
|
117
|
+
context?.resetErrorBoundary
|
|
118
|
+
]);
|
|
119
|
+
if (state.hasError) throw state.error;
|
|
120
|
+
return memoized;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
var $62ff477d53f02a5b$exports = {};
|
|
125
|
+
|
|
126
|
+
$parcel$export($62ff477d53f02a5b$exports, "withErrorBoundary", () => $62ff477d53f02a5b$export$f0c7a449e0cfaec7);
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
function $62ff477d53f02a5b$export$f0c7a449e0cfaec7(Component, errorBoundaryProps) {
|
|
130
|
+
const Wrapped = (props)=>{
|
|
131
|
+
return (0, $hgUW1$createElement)((0, $44d7e150ebc754d2$export$e926676385687eaf), errorBoundaryProps, (0, $hgUW1$createElement)(Component, props));
|
|
132
|
+
};
|
|
133
|
+
// Format for display in DevTools
|
|
134
|
+
const name = Component.displayName || Component.name || "Unknown";
|
|
135
|
+
Wrapped.displayName = `withErrorBoundary(${name})`;
|
|
136
|
+
return Wrapped;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
var $81c1b644006d48ec$exports = {};
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
export {$44d7e150ebc754d2$export$e926676385687eaf as ErrorBoundary, $ebb31c7feaa4405e$export$b16d9fb1a22de840 as ErrorBoundaryContext, $7c3c25b3f398a9d6$export$c052f6604b7d51fe as useErrorBoundary, $62ff477d53f02a5b$export$f0c7a449e0cfaec7 as withErrorBoundary};
|
|
146
|
+
//# sourceMappingURL=react-error-boundary.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;ACAA;;;;ACAA;AAQO,MAAM,4CACX,CAAA,GAAA,oBAAY,EAAmC,IAAI;;;ADOrD,MAAM,qCAAmC;IACvC,UAAU,KAAK;IACf,OAAO,IAAI;AACb;AAEO,MAAM,kDAAs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,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 {\n ErrorBoundaryContextType,\n ErrorBoundaryContext,\n} 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 if (didCatch) {\n const props: FallbackProps = {\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n };\n\n if (isValidElement(fallback)) {\n return fallback;\n } else if (typeof fallbackRender === \"function\") {\n return fallbackRender(props);\n } else if (FallbackComponent) {\n return 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 children\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: false;\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"}
|
package/package.json
CHANGED
|
@@ -1,55 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-error-boundary",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Simple reusable React error boundary component",
|
|
5
|
-
"main": "dist/react-error-boundary.cjs.js",
|
|
6
|
-
"module": "dist/react-error-boundary.esm.js",
|
|
7
|
-
"browser": "dist/react-error-boundary.umd.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"sideEffects": false,
|
|
10
|
-
"keywords": [
|
|
11
|
-
"react",
|
|
12
|
-
"error boundary",
|
|
13
|
-
"error handling"
|
|
14
|
-
],
|
|
15
5
|
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
|
|
16
6
|
"license": "MIT",
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=10",
|
|
19
|
-
"npm": ">=6"
|
|
20
|
-
},
|
|
21
7
|
"repository": {
|
|
22
8
|
"type": "git",
|
|
23
9
|
"url": "https://github.com/bvaughn/react-error-boundary"
|
|
24
10
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
11
|
+
"source": "src/index.ts",
|
|
12
|
+
"main": "dist/react-error-boundary.js",
|
|
13
|
+
"module": "dist/react-error-boundary.module.js",
|
|
14
|
+
"types": "dist/react-error-boundary.d.ts",
|
|
29
15
|
"files": [
|
|
30
16
|
"dist"
|
|
31
17
|
],
|
|
32
18
|
"scripts": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
19
|
+
"clear": "npm run clear:parcel-cache & npm run clear:builds & npm run clear:node_modules",
|
|
20
|
+
"clear:builds": "rm -rf ./packages/*/dist",
|
|
21
|
+
"clear:parcel-cache": "rm -rf ./.parcel-cache",
|
|
22
|
+
"clear:node_modules": "rm -rf ./node_modules",
|
|
23
|
+
"prerelease": "rm -rf ./.parcel-cache && parcel build",
|
|
24
|
+
"prettier": "prettier --write \"**/*.{css,html,js,json,jsx,ts,tsx}\"",
|
|
25
|
+
"prettier:ci": "prettier --check \"**/*.{css,html,js,json,jsx,ts,tsx}\"",
|
|
26
|
+
"test": "jest",
|
|
27
|
+
"test:watch": "jest --watch",
|
|
28
|
+
"typescript": "tsc --noEmit",
|
|
29
|
+
"typescript:watch": "tsc --noEmit --watch"
|
|
40
30
|
},
|
|
41
31
|
"dependencies": {
|
|
42
32
|
"@babel/runtime": "^7.12.5"
|
|
43
33
|
},
|
|
44
34
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
35
|
+
"@parcel/core": "^2.8.3",
|
|
36
|
+
"@parcel/packager-ts": "^2.8.3",
|
|
37
|
+
"@parcel/transformer-typescript-types": "^2.8.3",
|
|
48
38
|
"@types/jest": "^26.0.15",
|
|
49
|
-
"@types/react": "^
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
39
|
+
"@types/react": "^18",
|
|
40
|
+
"@types/react-dom": "^18",
|
|
41
|
+
"jest": "^29.4.3",
|
|
42
|
+
"jest-environment-jsdom": "^29.4.3",
|
|
43
|
+
"parcel": "^2.8.3",
|
|
44
|
+
"prettier": "^2.8.6",
|
|
45
|
+
"react": "^18",
|
|
46
|
+
"react-dom": "^18",
|
|
47
|
+
"ts-jest": "^29.0.5",
|
|
53
48
|
"typescript": "^4.1.2"
|
|
54
49
|
},
|
|
55
50
|
"peerDependencies": {
|
package/CHANGELOG.md
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
interface FallbackProps {
|
|
3
|
-
error: Error;
|
|
4
|
-
resetErrorBoundary: (...args: Array<unknown>) => void;
|
|
5
|
-
}
|
|
6
|
-
interface ErrorBoundaryPropsWithComponent {
|
|
7
|
-
onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
|
|
8
|
-
onReset?: (...args: Array<unknown>) => void;
|
|
9
|
-
onError?: (error: Error, info: {
|
|
10
|
-
componentStack: string;
|
|
11
|
-
}) => void;
|
|
12
|
-
resetKeys?: Array<unknown>;
|
|
13
|
-
fallback?: never;
|
|
14
|
-
FallbackComponent: React.ComponentType<FallbackProps>;
|
|
15
|
-
fallbackRender?: never;
|
|
16
|
-
}
|
|
17
|
-
declare function FallbackRender(props: FallbackProps): React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
|
|
18
|
-
interface ErrorBoundaryPropsWithRender {
|
|
19
|
-
onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
|
|
20
|
-
onReset?: (...args: Array<unknown>) => void;
|
|
21
|
-
onError?: (error: Error, info: {
|
|
22
|
-
componentStack: string;
|
|
23
|
-
}) => void;
|
|
24
|
-
resetKeys?: Array<unknown>;
|
|
25
|
-
fallback?: never;
|
|
26
|
-
FallbackComponent?: never;
|
|
27
|
-
fallbackRender: typeof FallbackRender;
|
|
28
|
-
}
|
|
29
|
-
interface ErrorBoundaryPropsWithFallback {
|
|
30
|
-
onResetKeysChange?: (prevResetKeys: Array<unknown> | undefined, resetKeys: Array<unknown> | undefined) => void;
|
|
31
|
-
onReset?: (...args: Array<unknown>) => void;
|
|
32
|
-
onError?: (error: Error, info: {
|
|
33
|
-
componentStack: string;
|
|
34
|
-
}) => void;
|
|
35
|
-
resetKeys?: Array<unknown>;
|
|
36
|
-
fallback: React.ReactElement<unknown, string | React.FunctionComponent | typeof React.Component> | null;
|
|
37
|
-
FallbackComponent?: never;
|
|
38
|
-
fallbackRender?: never;
|
|
39
|
-
}
|
|
40
|
-
declare type ErrorBoundaryProps = ErrorBoundaryPropsWithFallback | ErrorBoundaryPropsWithComponent | ErrorBoundaryPropsWithRender;
|
|
41
|
-
declare type ErrorBoundaryState = {
|
|
42
|
-
error: Error | null;
|
|
43
|
-
};
|
|
44
|
-
declare class ErrorBoundary extends React.Component<React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>, ErrorBoundaryState> {
|
|
45
|
-
static getDerivedStateFromError(error: Error): {
|
|
46
|
-
error: Error;
|
|
47
|
-
};
|
|
48
|
-
state: ErrorBoundaryState;
|
|
49
|
-
resetErrorBoundary: (...args: Array<unknown>) => void;
|
|
50
|
-
reset(): void;
|
|
51
|
-
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
52
|
-
componentDidUpdate(prevProps: ErrorBoundaryProps, prevState: ErrorBoundaryState): void;
|
|
53
|
-
render(): React.ReactNode;
|
|
54
|
-
}
|
|
55
|
-
declare function withErrorBoundary<P>(Component: React.ComponentType<P>, errorBoundaryProps: ErrorBoundaryProps): React.ComponentType<P>;
|
|
56
|
-
declare function useErrorHandler(givenError?: unknown): (error: unknown) => void;
|
|
57
|
-
export { ErrorBoundary, withErrorBoundary, useErrorHandler };
|
|
58
|
-
export type { FallbackProps, ErrorBoundaryPropsWithComponent, ErrorBoundaryPropsWithRender, ErrorBoundaryPropsWithFallback, ErrorBoundaryProps, };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../dist/index";
|