File tree Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " react-router " : patch
3
+ ---
4
+
5
+ Properly handle falsy error values in ErrorBoundary's
Original file line number Diff line number Diff line change @@ -2014,6 +2014,50 @@ describe("createMemoryRouter", () => {
2014
2014
}
2015
2015
} ) ;
2016
2016
2017
+ it ( "handles a `null` render-error" , async ( ) => {
2018
+ let router = createMemoryRouter ( [
2019
+ {
2020
+ path : "/" ,
2021
+ Component ( ) {
2022
+ throw null ;
2023
+ } ,
2024
+ ErrorBoundary ( ) {
2025
+ return < pre > { useRouteError ( ) === null ? "Yes" : "No" } </ pre > ;
2026
+ } ,
2027
+ } ,
2028
+ ] ) ;
2029
+ let { container } = render ( < RouterProvider router = { router } /> ) ;
2030
+
2031
+ await waitFor ( ( ) => screen . getByText ( "Yes" ) ) ;
2032
+ expect ( getHtml ( container ) ) . toMatch ( "Yes" ) ;
2033
+ } ) ;
2034
+
2035
+ it ( "handles a `null` render-error from a defer() call" , async ( ) => {
2036
+ let router = createMemoryRouter ( [
2037
+ {
2038
+ path : "/" ,
2039
+ loader ( ) {
2040
+ return defer ( { lazy : Promise . reject ( null ) } ) ;
2041
+ } ,
2042
+ Component ( ) {
2043
+ let data = useLoaderData ( ) as { lazy : Promise < unknown > } ;
2044
+ return (
2045
+ < React . Suspense >
2046
+ < Await resolve = { data . lazy } > No</ Await >
2047
+ </ React . Suspense >
2048
+ ) ;
2049
+ } ,
2050
+ ErrorBoundary ( ) {
2051
+ return < pre > { useRouteError ( ) === null ? "Yes" : "No" } </ pre > ;
2052
+ } ,
2053
+ } ,
2054
+ ] ) ;
2055
+ let { container } = render ( < RouterProvider router = { router } /> ) ;
2056
+
2057
+ await waitFor ( ( ) => screen . getByText ( "Yes" ) ) ;
2058
+ expect ( getHtml ( container ) ) . toMatch ( "Yes" ) ;
2059
+ } ) ;
2060
+
2017
2061
it ( "handles back button routing away from a child error boundary" , async ( ) => {
2018
2062
let router = createMemoryRouter (
2019
2063
createRoutesFromElements (
Original file line number Diff line number Diff line change @@ -600,7 +600,7 @@ export class RenderErrorBoundary extends React.Component<
600
600
// this because the error provided from the app state may be cleared without
601
601
// the location changing.
602
602
return {
603
- error : props . error || state . error ,
603
+ error : props . error !== undefined ? props . error : state . error ,
604
604
location : state . location ,
605
605
revalidation : props . revalidation || state . revalidation ,
606
606
} ;
@@ -615,7 +615,7 @@ export class RenderErrorBoundary extends React.Component<
615
615
}
616
616
617
617
render ( ) {
618
- return this . state . error ? (
618
+ return this . state . error !== undefined ? (
619
619
< RouteContext . Provider value = { this . props . routeContext } >
620
620
< RouteErrorContext . Provider
621
621
value = { this . state . error }
@@ -891,7 +891,7 @@ export function useRouteError(): unknown {
891
891
892
892
// If this was a render error, we put it in a RouteError context inside
893
893
// of RenderErrorBoundary
894
- if ( error ) {
894
+ if ( error !== undefined ) {
895
895
return error ;
896
896
}
897
897
You can’t perform that action at this time.
0 commit comments