@@ -78,27 +78,27 @@ export const RouterHost = ({
7878 ( ) => globalX . __INITIAL_ROUTE__
7979 ) ;
8080 const [ current , setCurrent ] = useState ( children ) ;
81- const version = useRef < number > ( 0 ) ;
81+ const [ version , setVersion ] = useState ( 0 ) ;
82+ const versionRef = useRef < number > ( version ) ;
8283 const reload = useCallback (
8384 async ( target = location . pathname + location . search ) => {
8485 if ( typeof target !== "string" ) throw new Error ( "invalid target" , target ) ;
85- const currentVersion = ++ version . current ;
86+ const currentVersion = ++ versionRef . current ;
8687 const [ module , props ] = await Promise . all ( [
8788 import ( match ( target . split ( "?" ) [ 0 ] ) ! . value ) ,
8889 fetchServerSideProps ( target ) ,
8990 ] ) ;
90- if ( currentVersion === version . current ) {
91+ if ( currentVersion === versionRef . current ) {
9192 if ( props ?. redirect ) {
9293 navigate ( props . redirect ) ;
9394 } else {
9495 startTransition ( ( ) => {
9596 onRouteUpdated ?.( target ) ;
97+ setVersion ( currentVersion ) ;
9698 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 >
102102 ) ;
103103 } ) ;
104104 }
@@ -119,7 +119,11 @@ export const RouterHost = ({
119119 }
120120 } , [ pathname ] ) ;
121121 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 >
123127 ) ;
124128} ;
125129
0 commit comments