File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -117,9 +117,15 @@ async function loadLocaleMessages(locale: Locale): Promise<Messages> {
117117
118118export async function preloadLocaleMessages ( preferredLocale ?: string | null ) : Promise < Locale > {
119119 const resolvedLocale = matchSupportedLocale ( preferredLocale ?? undefined ) ?? detectNavigatorLocale ( ) ?? "en"
120- globalMessages = await loadLocaleMessages ( resolvedLocale )
121- setGlobalRevision ( ( value ) => value + 1 )
122- return resolvedLocale
120+ try {
121+ globalMessages = await loadLocaleMessages ( resolvedLocale )
122+ setGlobalRevision ( ( value ) => value + 1 )
123+ return resolvedLocale
124+ } catch {
125+ globalMessages = enMessages
126+ setGlobalRevision ( ( value ) => value + 1 )
127+ return "en"
128+ }
123129}
124130
125131export function tGlobal ( key : string , params ?: TranslateParams ) : string {
Original file line number Diff line number Diff line change 11export type UiBootstrapTheme = "light" | "dark" | "system"
22
33export interface UiBootstrapCacheSnapshot {
4- theme ?: UiBootstrapTheme
5- locale ?: string
4+ theme ?: UiBootstrapTheme | null
5+ locale ?: string | null
66}
77
88const UI_BOOTSTRAP_CACHE_KEY = "codenomad:ui-bootstrap"
@@ -41,7 +41,18 @@ export function writeUiBootstrapCache(snapshot: UiBootstrapCacheSnapshot) {
4141 }
4242
4343 try {
44- window . localStorage . setItem ( UI_BOOTSTRAP_CACHE_KEY , JSON . stringify ( snapshot ) )
44+ const previous = readUiBootstrapCache ( )
45+ const next : UiBootstrapCacheSnapshot = {
46+ theme : snapshot . theme === undefined ? previous . theme : snapshot . theme ?? undefined ,
47+ locale : snapshot . locale === undefined ? previous . locale : snapshot . locale ?? undefined ,
48+ }
49+
50+ if ( ! next . theme && ! next . locale ) {
51+ window . localStorage . removeItem ( UI_BOOTSTRAP_CACHE_KEY )
52+ return
53+ }
54+
55+ window . localStorage . setItem ( UI_BOOTSTRAP_CACHE_KEY , JSON . stringify ( next ) )
4556 } catch {
4657 /* noop */
4758 }
Original file line number Diff line number Diff line change @@ -600,10 +600,17 @@ const configContextValue: ConfigContextValue = {
600600
601601export const ConfigProvider : ParentComponent = ( props ) => {
602602 createEffect ( ( ) => {
603+ if ( ! isLoaded ( ) ) {
604+ return
605+ }
606+
603607 const bucket = uiConfigBucket ( )
608+ const theme = bucket . theme
609+ const locale = bucket . settings ?. locale
610+
604611 writeUiBootstrapCache ( {
605- theme : bucket . theme ,
606- locale : bucket . settings ?. locale ,
612+ theme : theme ?? null ,
613+ locale : locale ?? null ,
607614 } )
608615 } )
609616
You can’t perform that action at this time.
0 commit comments