@@ -28,7 +28,7 @@ function useCsrContent<I, F>(
2828 ...fetchOptions
2929 } = options ;
3030
31- const { preferredLocale} = fetchOptions ;
31+ const preferredLocale = normalizePreferredLocale ( fetchOptions . preferredLocale ) ;
3232 const defaultContent = useMemo (
3333 ( ) => getSlotContent ( id , preferredLocale ) as SlotContent | null ?? undefined ,
3434 [ id , preferredLocale ] ,
@@ -47,7 +47,11 @@ function useCsrContent<I, F>(
4747 + `:${ preferredLocale ?? '' } `
4848 + `:${ JSON . stringify ( fetchOptions . attributes ?? { } ) } ` ,
4949 ) ,
50- loader : ( ) => croct . fetch ( id , { ...fetchOptions , fallback : fallback } ) . then ( ( { content} ) => content ) ,
50+ loader : ( ) => croct . fetch ( id , {
51+ ...fetchOptions ,
52+ preferredLocale : preferredLocale ,
53+ fallback : fallback ,
54+ } ) . then ( ( { content} ) => content ) ,
5155 initial : initial ,
5256 expiration : expiration ,
5357 } ) ;
@@ -75,7 +79,7 @@ function useSsrContent<I, F>(
7579 { initial, preferredLocale} : UseContentOptions < I , F > = { } ,
7680) : SlotContent | I | F {
7781 const resolvedInitialContent = initial === undefined
78- ? getSlotContent ( slotId , preferredLocale ) as I | null ?? undefined
82+ ? getSlotContent ( slotId , normalizePreferredLocale ( preferredLocale ) ) as I | null ?? undefined
7983 : initial ;
8084
8185 if ( resolvedInitialContent === undefined ) {
@@ -88,6 +92,10 @@ function useSsrContent<I, F>(
8892 return resolvedInitialContent ;
8993}
9094
95+ function normalizePreferredLocale ( preferredLocale : string | undefined ) : string | undefined {
96+ return preferredLocale !== undefined && preferredLocale !== '' ? preferredLocale : undefined ;
97+ }
98+
9199type UseContentHook = {
92100 < P extends JsonObject , I = P , F = P > (
93101 id : keyof VersionedSlotMap extends never ? string : never ,
0 commit comments