react-error-boundary 4.0.12 → 4.1.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 +4 -4
- package/dist/declarations/src/types.d.ts +2 -2
- package/dist/declarations/src/withErrorBoundary.d.ts +1 -1
- package/dist/react-error-boundary.cjs.js +1 -1
- package/dist/react-error-boundary.development.cjs.js +1 -1
- package/dist/react-error-boundary.development.esm.js +2 -2
- package/dist/react-error-boundary.esm.js +2 -2
- package/package.json +17 -14
package/README.md
CHANGED
|
@@ -20,12 +20,12 @@ yarn add react-error-boundary
|
|
|
20
20
|
## API
|
|
21
21
|
|
|
22
22
|
### `ErrorBoundary` component
|
|
23
|
-
Wrap an `ErrorBoundary` around other React components to "catch" errors and render a fallback UI. The component supports several ways to render a fallback (shown below).
|
|
23
|
+
Wrap an `ErrorBoundary` component around other React components to "catch" errors and render a fallback UI. The component supports several ways to render a fallback (as shown below).
|
|
24
24
|
|
|
25
25
|
> **Note** `ErrorBoundary` is a _client_ component. You can only pass props to it that are serializeable or use it in files that have a `"use client";` directive.
|
|
26
26
|
|
|
27
27
|
#### `ErrorBoundary` with `fallback` prop
|
|
28
|
-
The simplest way to render a default "something went wrong" type error message.
|
|
28
|
+
The simplest way to render a default "something went wrong" type of error message.
|
|
29
29
|
```js
|
|
30
30
|
"use client";
|
|
31
31
|
|
|
@@ -142,7 +142,7 @@ function Example() {
|
|
|
142
142
|
```
|
|
143
143
|
|
|
144
144
|
#### Dismiss the nearest error boundary
|
|
145
|
-
A fallback component can use this hook to request the nearest error boundary retry the render that
|
|
145
|
+
A fallback component can use this hook to request the nearest error boundary retry the render that originally failed.
|
|
146
146
|
|
|
147
147
|
```js
|
|
148
148
|
"use client";
|
|
@@ -211,4 +211,4 @@ If using Yarn:
|
|
|
211
211
|
|
|
212
212
|
---
|
|
213
213
|
|
|
214
|
-
[This blog post](https://kentcdodds.com/blog/use-react-error-boundary-to-handle-errors-in-react) shows more examples of how this package can be used, although it was written for the [version 3 API](https://github.com/bvaughn/react-error-boundary/releases/tag/v3.1.4).
|
|
214
|
+
[This blog post](https://kentcdodds.com/blog/use-react-error-boundary-to-handle-errors-in-react) shows more examples of how this package can be used, although it was written for the [version 3 API](https://github.com/bvaughn/react-error-boundary/releases/tag/v3.1.4).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentType, ErrorInfo, PropsWithChildren, ReactNode } from "react";
|
|
2
2
|
declare function FallbackRender(props: FallbackProps): ReactNode;
|
|
3
3
|
export type FallbackProps = {
|
|
4
4
|
error: any;
|
|
@@ -27,7 +27,7 @@ export type ErrorBoundaryPropsWithRender = ErrorBoundarySharedProps & {
|
|
|
27
27
|
fallbackRender: typeof FallbackRender;
|
|
28
28
|
};
|
|
29
29
|
export type ErrorBoundaryPropsWithFallback = ErrorBoundarySharedProps & {
|
|
30
|
-
fallback:
|
|
30
|
+
fallback: ReactNode;
|
|
31
31
|
FallbackComponent?: never;
|
|
32
32
|
fallbackRender?: never;
|
|
33
33
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { RefAttributes, ForwardRefExoticComponent, PropsWithoutRef, ComponentType } from "react";
|
|
2
2
|
import { ErrorBoundaryProps } from "./types.js";
|
|
3
|
-
export declare function withErrorBoundary<Props extends
|
|
3
|
+
export declare function withErrorBoundary<Props extends object>(component: ComponentType<Props>, errorBoundaryProps: ErrorBoundaryProps): ForwardRefExoticComponent<PropsWithoutRef<Props> & RefAttributes<any>>;
|
|
@@ -87,7 +87,7 @@ class ErrorBoundary extends react.Component {
|
|
|
87
87
|
childToRender = fallbackRender(props);
|
|
88
88
|
} else if (FallbackComponent) {
|
|
89
89
|
childToRender = react.createElement(FallbackComponent, props);
|
|
90
|
-
} else if (fallback
|
|
90
|
+
} else if (fallback !== undefined) {
|
|
91
91
|
childToRender = fallback;
|
|
92
92
|
} else {
|
|
93
93
|
throw error;
|
|
@@ -87,7 +87,7 @@ class ErrorBoundary extends react.Component {
|
|
|
87
87
|
childToRender = fallbackRender(props);
|
|
88
88
|
} else if (FallbackComponent) {
|
|
89
89
|
childToRender = react.createElement(FallbackComponent, props);
|
|
90
|
-
} else if (fallback
|
|
90
|
+
} else if (fallback !== undefined) {
|
|
91
91
|
childToRender = fallback;
|
|
92
92
|
} else {
|
|
93
93
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, Component, createElement,
|
|
2
|
+
import { createContext, Component, createElement, useContext, useState, useMemo, forwardRef } from 'react';
|
|
3
3
|
|
|
4
4
|
const ErrorBoundaryContext = createContext(null);
|
|
5
5
|
|
|
@@ -83,7 +83,7 @@ class ErrorBoundary extends Component {
|
|
|
83
83
|
childToRender = fallbackRender(props);
|
|
84
84
|
} else if (FallbackComponent) {
|
|
85
85
|
childToRender = createElement(FallbackComponent, props);
|
|
86
|
-
} else if (fallback
|
|
86
|
+
} else if (fallback !== undefined) {
|
|
87
87
|
childToRender = fallback;
|
|
88
88
|
} else {
|
|
89
89
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, Component, createElement,
|
|
2
|
+
import { createContext, Component, createElement, useContext, useState, useMemo, forwardRef } from 'react';
|
|
3
3
|
|
|
4
4
|
const ErrorBoundaryContext = createContext(null);
|
|
5
5
|
|
|
@@ -83,7 +83,7 @@ class ErrorBoundary extends Component {
|
|
|
83
83
|
childToRender = fallbackRender(props);
|
|
84
84
|
} else if (FallbackComponent) {
|
|
85
85
|
childToRender = createElement(FallbackComponent, props);
|
|
86
|
-
} else if (fallback
|
|
86
|
+
} else if (fallback !== undefined) {
|
|
87
87
|
childToRender = fallback;
|
|
88
88
|
} else {
|
|
89
89
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-error-boundary",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Simple reusable React error boundary component",
|
|
5
5
|
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"packageManager": "pnpm@8.6.10",
|
|
8
7
|
"repository": {
|
|
9
8
|
"type": "git",
|
|
10
9
|
"url": "https://github.com/bvaughn/react-error-boundary"
|
|
11
10
|
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=20",
|
|
13
|
+
"pnpm": "=9"
|
|
14
|
+
},
|
|
12
15
|
"main": "dist/react-error-boundary.cjs.js",
|
|
13
16
|
"module": "dist/react-error-boundary.esm.js",
|
|
14
17
|
"exports": {
|
|
@@ -40,12 +43,12 @@
|
|
|
40
43
|
],
|
|
41
44
|
"sideEffects": false,
|
|
42
45
|
"scripts": {
|
|
43
|
-
"clear": "
|
|
46
|
+
"clear": "pnpm clear:builds & pnpm clear:node_modules",
|
|
44
47
|
"clear:builds": "rm -rf ./dist",
|
|
45
48
|
"clear:node_modules": "rm -rf ./node_modules",
|
|
46
49
|
"prerelease": "preconstruct build",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
50
|
+
"lint": "eslint .",
|
|
51
|
+
"lint:fix": "eslint . --fix",
|
|
49
52
|
"test": "jest",
|
|
50
53
|
"test:watch": "jest --watch",
|
|
51
54
|
"typescript": "tsc --noEmit",
|
|
@@ -58,12 +61,20 @@
|
|
|
58
61
|
"@babel/preset-env": "^7.22.5",
|
|
59
62
|
"@babel/preset-typescript": "^7.21.5",
|
|
60
63
|
"@preconstruct/cli": "^2.8.1",
|
|
64
|
+
"@types/assert": "^1.5.10",
|
|
61
65
|
"@types/jest": "^26.0.15",
|
|
62
66
|
"@types/react": "^18",
|
|
63
67
|
"@types/react-dom": "^18",
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
|
69
|
+
"assert": "^2.0.0",
|
|
70
|
+
"eslint": "^8.0.1",
|
|
71
|
+
"eslint-config-prettier": "^9.0.0",
|
|
72
|
+
"eslint-plugin-import": "^2.25.2",
|
|
73
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
74
|
+
"eslint-plugin-react": "^7.33.1",
|
|
64
75
|
"jest": "^29.4.3",
|
|
65
76
|
"jest-environment-jsdom": "^29.4.3",
|
|
66
|
-
"prettier": "^
|
|
77
|
+
"prettier": "^3.0.1",
|
|
67
78
|
"react": "^18",
|
|
68
79
|
"react-dom": "^18",
|
|
69
80
|
"ts-jest": "^29.0.5",
|
|
@@ -72,14 +83,6 @@
|
|
|
72
83
|
"peerDependencies": {
|
|
73
84
|
"react": ">=16.13.1"
|
|
74
85
|
},
|
|
75
|
-
"eslintConfig": {
|
|
76
|
-
"extends": "./node_modules/kcd-scripts/eslint.js",
|
|
77
|
-
"rules": {
|
|
78
|
-
"react/prop-types": "off",
|
|
79
|
-
"react/no-did-update-set-state": "off",
|
|
80
|
-
"babel/no-unused-expressions": "off"
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
86
|
"preconstruct": {
|
|
84
87
|
"exports": {
|
|
85
88
|
"importConditionDefaultExport": "default"
|