react-error-boundary 4.0.11 → 4.0.12
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/dist/declarations/src/ErrorBoundary.d.ts +4 -1
- package/dist/declarations/src/useErrorBoundary.d.ts +3 -3
- package/dist/react-error-boundary.cjs.js +5 -6
- package/dist/react-error-boundary.development.cjs.js +5 -6
- package/dist/react-error-boundary.development.esm.js +6 -7
- package/dist/react-error-boundary.esm.js +6 -7
- package/package.json +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Component, ErrorInfo } from "react";
|
|
2
2
|
import { ErrorBoundaryProps } from "./types.js";
|
|
3
3
|
type ErrorBoundaryState = {
|
|
4
|
-
didCatch:
|
|
4
|
+
didCatch: true;
|
|
5
5
|
error: any;
|
|
6
|
+
} | {
|
|
7
|
+
didCatch: false;
|
|
8
|
+
error: null;
|
|
6
9
|
};
|
|
7
10
|
export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
8
11
|
constructor(props: ErrorBoundaryProps);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type UseErrorBoundaryApi<
|
|
1
|
+
export type UseErrorBoundaryApi<TError> = {
|
|
2
2
|
resetBoundary: () => void;
|
|
3
|
-
showBoundary: (error:
|
|
3
|
+
showBoundary: (error: TError) => void;
|
|
4
4
|
};
|
|
5
|
-
export declare function useErrorBoundary<
|
|
5
|
+
export declare function useErrorBoundary<TError = any>(): UseErrorBoundaryApi<TError>;
|
|
@@ -83,12 +83,12 @@ class ErrorBoundary extends react.Component {
|
|
|
83
83
|
error,
|
|
84
84
|
resetErrorBoundary: this.resetErrorBoundary
|
|
85
85
|
};
|
|
86
|
-
if (
|
|
87
|
-
childToRender = fallback;
|
|
88
|
-
} else if (typeof fallbackRender === "function") {
|
|
86
|
+
if (typeof fallbackRender === "function") {
|
|
89
87
|
childToRender = fallbackRender(props);
|
|
90
88
|
} else if (FallbackComponent) {
|
|
91
89
|
childToRender = react.createElement(FallbackComponent, props);
|
|
90
|
+
} else if (fallback === null || react.isValidElement(fallback)) {
|
|
91
|
+
childToRender = fallback;
|
|
92
92
|
} else {
|
|
93
93
|
throw error;
|
|
94
94
|
}
|
|
@@ -112,7 +112,6 @@ function assertErrorBoundaryContext(value) {
|
|
|
112
112
|
if (value == null || typeof value.didCatch !== "boolean" || typeof value.resetErrorBoundary !== "function") {
|
|
113
113
|
throw new Error("ErrorBoundaryContext not found");
|
|
114
114
|
}
|
|
115
|
-
return true;
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
function useErrorBoundary() {
|
|
@@ -124,7 +123,7 @@ function useErrorBoundary() {
|
|
|
124
123
|
});
|
|
125
124
|
const memoized = react.useMemo(() => ({
|
|
126
125
|
resetBoundary: () => {
|
|
127
|
-
context
|
|
126
|
+
context.resetErrorBoundary();
|
|
128
127
|
setState({
|
|
129
128
|
error: null,
|
|
130
129
|
hasError: false
|
|
@@ -134,7 +133,7 @@ function useErrorBoundary() {
|
|
|
134
133
|
error,
|
|
135
134
|
hasError: true
|
|
136
135
|
})
|
|
137
|
-
}), [context
|
|
136
|
+
}), [context.resetErrorBoundary]);
|
|
138
137
|
if (state.hasError) {
|
|
139
138
|
throw state.error;
|
|
140
139
|
}
|
|
@@ -83,12 +83,12 @@ class ErrorBoundary extends react.Component {
|
|
|
83
83
|
error,
|
|
84
84
|
resetErrorBoundary: this.resetErrorBoundary
|
|
85
85
|
};
|
|
86
|
-
if (
|
|
87
|
-
childToRender = fallback;
|
|
88
|
-
} else if (typeof fallbackRender === "function") {
|
|
86
|
+
if (typeof fallbackRender === "function") {
|
|
89
87
|
childToRender = fallbackRender(props);
|
|
90
88
|
} else if (FallbackComponent) {
|
|
91
89
|
childToRender = react.createElement(FallbackComponent, props);
|
|
90
|
+
} else if (fallback === null || react.isValidElement(fallback)) {
|
|
91
|
+
childToRender = fallback;
|
|
92
92
|
} else {
|
|
93
93
|
{
|
|
94
94
|
console.error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");
|
|
@@ -115,7 +115,6 @@ function assertErrorBoundaryContext(value) {
|
|
|
115
115
|
if (value == null || typeof value.didCatch !== "boolean" || typeof value.resetErrorBoundary !== "function") {
|
|
116
116
|
throw new Error("ErrorBoundaryContext not found");
|
|
117
117
|
}
|
|
118
|
-
return true;
|
|
119
118
|
}
|
|
120
119
|
|
|
121
120
|
function useErrorBoundary() {
|
|
@@ -127,7 +126,7 @@ function useErrorBoundary() {
|
|
|
127
126
|
});
|
|
128
127
|
const memoized = react.useMemo(() => ({
|
|
129
128
|
resetBoundary: () => {
|
|
130
|
-
context
|
|
129
|
+
context.resetErrorBoundary();
|
|
131
130
|
setState({
|
|
132
131
|
error: null,
|
|
133
132
|
hasError: false
|
|
@@ -137,7 +136,7 @@ function useErrorBoundary() {
|
|
|
137
136
|
error,
|
|
138
137
|
hasError: true
|
|
139
138
|
})
|
|
140
|
-
}), [context
|
|
139
|
+
}), [context.resetErrorBoundary]);
|
|
141
140
|
if (state.hasError) {
|
|
142
141
|
throw state.error;
|
|
143
142
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, Component,
|
|
2
|
+
import { createContext, Component, createElement, isValidElement, useContext, useState, useMemo, forwardRef } from 'react';
|
|
3
3
|
|
|
4
4
|
const ErrorBoundaryContext = createContext(null);
|
|
5
5
|
|
|
@@ -79,12 +79,12 @@ class ErrorBoundary extends Component {
|
|
|
79
79
|
error,
|
|
80
80
|
resetErrorBoundary: this.resetErrorBoundary
|
|
81
81
|
};
|
|
82
|
-
if (
|
|
83
|
-
childToRender = fallback;
|
|
84
|
-
} else if (typeof fallbackRender === "function") {
|
|
82
|
+
if (typeof fallbackRender === "function") {
|
|
85
83
|
childToRender = fallbackRender(props);
|
|
86
84
|
} else if (FallbackComponent) {
|
|
87
85
|
childToRender = createElement(FallbackComponent, props);
|
|
86
|
+
} else if (fallback === null || isValidElement(fallback)) {
|
|
87
|
+
childToRender = fallback;
|
|
88
88
|
} else {
|
|
89
89
|
{
|
|
90
90
|
console.error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");
|
|
@@ -111,7 +111,6 @@ function assertErrorBoundaryContext(value) {
|
|
|
111
111
|
if (value == null || typeof value.didCatch !== "boolean" || typeof value.resetErrorBoundary !== "function") {
|
|
112
112
|
throw new Error("ErrorBoundaryContext not found");
|
|
113
113
|
}
|
|
114
|
-
return true;
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
function useErrorBoundary() {
|
|
@@ -123,7 +122,7 @@ function useErrorBoundary() {
|
|
|
123
122
|
});
|
|
124
123
|
const memoized = useMemo(() => ({
|
|
125
124
|
resetBoundary: () => {
|
|
126
|
-
context
|
|
125
|
+
context.resetErrorBoundary();
|
|
127
126
|
setState({
|
|
128
127
|
error: null,
|
|
129
128
|
hasError: false
|
|
@@ -133,7 +132,7 @@ function useErrorBoundary() {
|
|
|
133
132
|
error,
|
|
134
133
|
hasError: true
|
|
135
134
|
})
|
|
136
|
-
}), [context
|
|
135
|
+
}), [context.resetErrorBoundary]);
|
|
137
136
|
if (state.hasError) {
|
|
138
137
|
throw state.error;
|
|
139
138
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, Component,
|
|
2
|
+
import { createContext, Component, createElement, isValidElement, useContext, useState, useMemo, forwardRef } from 'react';
|
|
3
3
|
|
|
4
4
|
const ErrorBoundaryContext = createContext(null);
|
|
5
5
|
|
|
@@ -79,12 +79,12 @@ class ErrorBoundary extends Component {
|
|
|
79
79
|
error,
|
|
80
80
|
resetErrorBoundary: this.resetErrorBoundary
|
|
81
81
|
};
|
|
82
|
-
if (
|
|
83
|
-
childToRender = fallback;
|
|
84
|
-
} else if (typeof fallbackRender === "function") {
|
|
82
|
+
if (typeof fallbackRender === "function") {
|
|
85
83
|
childToRender = fallbackRender(props);
|
|
86
84
|
} else if (FallbackComponent) {
|
|
87
85
|
childToRender = createElement(FallbackComponent, props);
|
|
86
|
+
} else if (fallback === null || isValidElement(fallback)) {
|
|
87
|
+
childToRender = fallback;
|
|
88
88
|
} else {
|
|
89
89
|
throw error;
|
|
90
90
|
}
|
|
@@ -108,7 +108,6 @@ function assertErrorBoundaryContext(value) {
|
|
|
108
108
|
if (value == null || typeof value.didCatch !== "boolean" || typeof value.resetErrorBoundary !== "function") {
|
|
109
109
|
throw new Error("ErrorBoundaryContext not found");
|
|
110
110
|
}
|
|
111
|
-
return true;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
function useErrorBoundary() {
|
|
@@ -120,7 +119,7 @@ function useErrorBoundary() {
|
|
|
120
119
|
});
|
|
121
120
|
const memoized = useMemo(() => ({
|
|
122
121
|
resetBoundary: () => {
|
|
123
|
-
context
|
|
122
|
+
context.resetErrorBoundary();
|
|
124
123
|
setState({
|
|
125
124
|
error: null,
|
|
126
125
|
hasError: false
|
|
@@ -130,7 +129,7 @@ function useErrorBoundary() {
|
|
|
130
129
|
error,
|
|
131
130
|
hasError: true
|
|
132
131
|
})
|
|
133
|
-
}), [context
|
|
132
|
+
}), [context.resetErrorBoundary]);
|
|
134
133
|
if (state.hasError) {
|
|
135
134
|
throw state.error;
|
|
136
135
|
}
|