@@ -7,6 +7,12 @@ import { TideStationIsland } from "../../../components/tides/TideStationIsland";
77import { NearbyStationsIsland } from " ../../../components/tides/NearbyStations" ;
88import { Icon } from " astro-icon/components" ;
99import { API_HOST } from " ../../../utils/constants" ;
10+ import {
11+ createQueryClient ,
12+ prefetchTideStation ,
13+ prefetchNearbyStations ,
14+ dehydrate ,
15+ } from " @neaps/react" ;
1016
1117// Enable server-side rendering for this route
1218export const prerender = false ;
@@ -26,6 +32,21 @@ if (station.offsets?.reference) {
2632 referenceStation = await refResponse .json ();
2733 }
2834}
35+
36+ // Determine locale from Accept-Language header
37+ const acceptLang = Astro .request .headers .get (" accept-language" ) ?? " " ;
38+ const locale = acceptLang .split (" ," )[0 ]?.split (" ;" )[0 ]?.trim () || " en-US" ;
39+
40+ // Prefetch tide data so React islands render with data immediately
41+ const queryClient = createQueryClient ();
42+ await Promise .all ([
43+ prefetchTideStation (queryClient , API_HOST , station .id , { locale }),
44+ prefetchNearbyStations (queryClient , API_HOST , {
45+ latitude: station .latitude ,
46+ longitude: station .longitude ,
47+ }),
48+ ]);
49+ const dehydratedState = dehydrate (queryClient );
2950---
3051
3152<MainLayout title ={ station .name } description ={ ` Tide station: ${station .name } ` } >
@@ -58,7 +79,11 @@ if (station.offsets?.reference) {
5879 )
5980 }
6081
61- <TideStationIsland client:load id ={ station .id } />
82+ <TideStationIsland
83+ client:load
84+ id ={ station .id }
85+ dehydratedState ={ dehydratedState }
86+ />
6287
6388 <Card class =" mt-8" >
6489 <section >
@@ -288,6 +313,7 @@ console.log(extremes);`}</code></pre>
288313 stationId ={ station .id }
289314 latitude ={ station .latitude }
290315 longitude ={ station .longitude }
316+ dehydratedState ={ dehydratedState }
291317 />
292318 </div >
293319 </div >
0 commit comments