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.
@@ -1,8 +1,11 @@
1
1
  import { Component, ErrorInfo } from "react";
2
2
  import { ErrorBoundaryProps } from "./types.js";
3
3
  type ErrorBoundaryState = {
4
- didCatch: boolean;
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<Error> = {
1
+ export type UseErrorBoundaryApi<TError> = {
2
2
  resetBoundary: () => void;
3
- showBoundary: (error: Error) => void;
3
+ showBoundary: (error: TError) => void;
4
4
  };
5
- export declare function useErrorBoundary<Error = any>(): UseErrorBoundaryApi<Error>;
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 (react.isValidElement(fallback)) {
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 === null || context === void 0 ? void 0 : context.resetErrorBoundary();
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 === null || context === void 0 ? void 0 : context.resetErrorBoundary]);
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 (react.isValidElement(fallback)) {
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 === null || context === void 0 ? void 0 : context.resetErrorBoundary();
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 === null || context === void 0 ? void 0 : context.resetErrorBoundary]);
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, isValidElement, createElement, useContext, useState, useMemo, forwardRef } from 'react';
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 (isValidElement(fallback)) {
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 === null || context === void 0 ? void 0 : context.resetErrorBoundary();
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 === null || context === void 0 ? void 0 : context.resetErrorBoundary]);
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, isValidElement, createElement, useContext, useState, useMemo, forwardRef } from 'react';
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 (isValidElement(fallback)) {
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 === null || context === void 0 ? void 0 : context.resetErrorBoundary();
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 === null || context === void 0 ? void 0 : context.resetErrorBoundary]);
132
+ }), [context.resetErrorBoundary]);
134
133
  if (state.hasError) {
135
134
  throw state.error;
136
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-error-boundary",
3
- "version": "4.0.11",
3
+ "version": "4.0.12",
4
4
  "description": "Simple reusable React error boundary component",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",