File tree 2 files changed +14
-3
lines changed
2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 1
- import { hydrateRoot } from "react-dom/client" ;
1
+ import { hydrateRoot , type ErrorInfo } from "react-dom/client" ;
2
2
import { RouterHost } from "./router" ;
3
3
import { getRouteMatcher } from "./router/utils/get-route-matcher" ;
4
4
import { ServerSideProps } from "./types" ;
@@ -16,7 +16,12 @@ export async function hydrate(
16
16
Shell : React . ComponentType <
17
17
{ children : React . ReactElement } & ServerSideProps
18
18
> ,
19
- options ?: Omit < React . PropsWithoutRef < typeof RouterHost > , "children" | "Shell" >
19
+ {
20
+ onRecoverableError = ( ) => void 8 ,
21
+ ...options
22
+ } : Omit < React . PropsWithoutRef < typeof RouterHost > , "children" | "Shell" > & {
23
+ onRecoverableError ?: ( error : unknown , errorInfo : ErrorInfo ) => void ;
24
+ } = { }
20
25
) {
21
26
const matched = match ( globalX . __INITIAL_ROUTE__ . split ( "?" ) [ 0 ] ) ! ;
22
27
const Initial = await import ( matched . value ) ;
@@ -26,6 +31,7 @@ export async function hydrate(
26
31
< Shell { ...globalX . __SERVERSIDE_PROPS__ } >
27
32
< Initial . default { ...globalX . __SERVERSIDE_PROPS__ ?. props } />
28
33
</ Shell >
29
- </ RouterHost >
34
+ </ RouterHost > ,
35
+ { onRecoverableError }
30
36
) ;
31
37
}
Original file line number Diff line number Diff line change @@ -40,11 +40,15 @@ export class StaticRouters {
40
40
preloadScript,
41
41
bootstrapModules,
42
42
context,
43
+ onError = ( error , errorInfo ) => {
44
+ console . error ( error , errorInfo ) ;
45
+ } ,
43
46
} : {
44
47
Shell : React . ComponentType < { children : React . ReactElement } > ;
45
48
preloadScript ?: string ;
46
49
bootstrapModules ?: string [ ] ;
47
50
context ?: T ;
51
+ onError ( error : unknown , errorInfo : React . ErrorInfo ) : string | void ;
48
52
}
49
53
) : Promise < Response | null > {
50
54
const { pathname, search } = new URL ( request . url ) ;
@@ -98,6 +102,7 @@ export class StaticRouters {
98
102
. filter ( Boolean )
99
103
. join ( ";" ) ,
100
104
bootstrapModules,
105
+ onError,
101
106
}
102
107
) ;
103
108
return new Response ( stream , {
You can’t perform that action at this time.
0 commit comments