@@ -78,27 +78,27 @@ export const RouterHost = ({
78
78
( ) => globalX . __INITIAL_ROUTE__
79
79
) ;
80
80
const [ current , setCurrent ] = useState ( children ) ;
81
- const version = useRef < number > ( 0 ) ;
81
+ const [ version , setVersion ] = useState ( 0 ) ;
82
+ const versionRef = useRef < number > ( version ) ;
82
83
const reload = useCallback (
83
84
async ( target = location . pathname + location . search ) => {
84
85
if ( typeof target !== "string" ) throw new Error ( "invalid target" , target ) ;
85
- const currentVersion = ++ version . current ;
86
+ const currentVersion = ++ versionRef . current ;
86
87
const [ module , props ] = await Promise . all ( [
87
88
import ( match ( target . split ( "?" ) [ 0 ] ) ! . value ) ,
88
89
fetchServerSideProps ( target ) ,
89
90
] ) ;
90
- if ( currentVersion === version . current ) {
91
+ if ( currentVersion === versionRef . current ) {
91
92
if ( props ?. redirect ) {
92
93
navigate ( props . redirect ) ;
93
94
} else {
94
95
startTransition ( ( ) => {
95
96
onRouteUpdated ?.( target ) ;
97
+ setVersion ( currentVersion ) ;
96
98
setCurrent (
97
- < VersionContext . Provider value = { currentVersion } >
98
- < Shell { ...props } >
99
- < module . default { ...props ?. props } />
100
- </ Shell >
101
- </ VersionContext . Provider >
99
+ < Shell { ...props } >
100
+ < module . default { ...props ?. props } />
101
+ </ Shell >
102
102
) ;
103
103
} ) ;
104
104
}
@@ -119,7 +119,11 @@ export const RouterHost = ({
119
119
}
120
120
} , [ pathname ] ) ;
121
121
return (
122
- < ReloadContext . Provider value = { reload } > { current } </ ReloadContext . Provider >
122
+ < ReloadContext . Provider value = { reload } >
123
+ < VersionContext . Provider value = { version } >
124
+ { current }
125
+ </ VersionContext . Provider >
126
+ </ ReloadContext . Provider >
123
127
) ;
124
128
} ;
125
129
0 commit comments