@@ -19,8 +19,9 @@ export const LocaleLoadingContext = createContext({
19
19
20
20
const fetchPreferences = async < T extends Record < string , unknown > | string > (
21
21
key : string ,
22
+ baseURL : string ,
22
23
) : Promise < { id : string ; value : T } > =>
23
- await fetch ( `/api /payload-preferences/${ key } ` , {
24
+ await fetch ( `${ baseURL } /payload-preferences/${ key } ` , {
24
25
credentials : 'include' ,
25
26
headers : {
26
27
'Content-Type' : 'application/json' ,
@@ -38,7 +39,11 @@ export const LocaleProvider: React.FC<{ children?: React.ReactNode; locale?: Loc
38
39
locale : initialLocaleFromPrefs ,
39
40
} ) => {
40
41
const {
41
- config : { localization = false } ,
42
+ config : {
43
+ localization = false ,
44
+ routes : { api : apiRoute } ,
45
+ serverURL,
46
+ } ,
42
47
} = useConfig ( )
43
48
44
49
const { user } = useAuth ( )
@@ -80,6 +85,8 @@ export const LocaleProvider: React.FC<{ children?: React.ReactNode; locale?: Loc
80
85
prevLocale . current = locale
81
86
} , [ locale ] )
82
87
88
+ const fetchURL = `${ serverURL } ${ apiRoute } `
89
+
83
90
useEffect ( ( ) => {
84
91
/**
85
92
* This effect should only run when `localeFromParams` changes, i.e. when the user clicks an anchor link
@@ -90,7 +97,7 @@ export const LocaleProvider: React.FC<{ children?: React.ReactNode; locale?: Loc
90
97
if ( localization && user ?. id ) {
91
98
const localeToUse =
92
99
localeFromParams ||
93
- ( await fetchPreferences < Locale [ 'code' ] > ( 'locale' ) ?. then ( ( res ) => res . value ) ) ||
100
+ ( await fetchPreferences < Locale [ 'code' ] > ( 'locale' , fetchURL ) ?. then ( ( res ) => res . value ) ) ||
94
101
defaultLocale
95
102
96
103
const newLocale =
@@ -102,7 +109,7 @@ export const LocaleProvider: React.FC<{ children?: React.ReactNode; locale?: Loc
102
109
}
103
110
104
111
void resetLocale ( )
105
- } , [ defaultLocale , getPreference , localization , localeFromParams , user ?. id ] )
112
+ } , [ defaultLocale , getPreference , localization , fetchURL , localeFromParams , user ?. id ] )
106
113
107
114
return (
108
115
< LocaleContext . Provider value = { locale } >
0 commit comments