@@ -11,22 +11,23 @@ const VersionSelector = () => {
1111 const [ versions , setVersions ] = useState < string [ ] > ( [ ] ) ;
1212 const [ selectedVersion , setSelectedVersion ] = useState < string | null > ( null ) ;
1313 const [ isOpen , setIsOpen ] = useState < boolean > ( false ) ;
14+ const [ redirectUrl , setRedirectUrl ] = useState < string | null > ( null ) ;
1415
1516 useEffect ( ( ) => {
1617 const { hostname, pathname, origin } = window . location ;
1718 const pathSegments = pathname . split ( "/" ) . filter ( Boolean ) ;
1819
1920 const isGitHubPages = hostname . endsWith ( "github.io" ) ;
20- const isLocalhost =
21- hostname === "localhost" || hostname . startsWith ( "10." ) ;
21+ const isLocalhost = hostname === "localhost" || hostname . startsWith ( "10." ) ;
2222
23- const repoBase =
24- isGitHubPages && pathSegments . length ? `/${ pathSegments [ 0 ] } ` : "" ;
23+ const repoBase = isGitHubPages && pathSegments . length ? `/${ pathSegments [ 0 ] } ` : "" ;
2524
2625 // dev mode: no versions.json
2726 if ( isLocalhost ) {
28- setVersions ( [ "latest" ] ) ;
29- setSelectedVersion ( "latest" ) ;
27+ setTimeout ( ( ) => {
28+ setVersions ( [ "latest" ] ) ;
29+ setSelectedVersion ( "latest" ) ;
30+ } , 0 ) ;
3031 return ;
3132 }
3233
@@ -73,16 +74,16 @@ const VersionSelector = () => {
7374 const pathSegments = pathname . split ( "/" ) . filter ( Boolean ) ;
7475
7576 const isGitHubPages = hostname . endsWith ( "github.io" ) ;
76- const repoBase =
77- isGitHubPages && pathSegments . length ? `/${ pathSegments [ 0 ] } ` : "" ;
78-
79- // Always use /latest/ for latest, regardless of domain
80- if ( version === "latest" ) {
81- window . location . href = `${ repoBase } /latest/` ;
82- } else {
83- window . location . href = `${ repoBase } /${ version } /` ;
84- }
77+ const repoBase = isGitHubPages && pathSegments . length ? `/${ pathSegments [ 0 ] } ` : "" ;
78+
79+ const targetUrl = version === "latest" ? `${ repoBase } /latest/` : `${ repoBase } /${ version } /` ;
80+ setRedirectUrl ( targetUrl ) ;
8581 } ;
82+ useEffect ( ( ) => {
83+ if ( redirectUrl ) {
84+ window . location . href = redirectUrl ;
85+ }
86+ } , [ redirectUrl ] ) ;
8687
8788 if ( ! versions . length || ! selectedVersion ) return null ;
8889
0 commit comments