From c758cc41e15351d124b6a898be8df153094af0da Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Fri, 1 Aug 2025 20:30:24 +0200 Subject: [PATCH] Prevent white screen on page load Bug introduced with ff58dcc4803e23207234e7832f27bbb950a76c74. With 18ddf46f17d7d88276349d21208bbaad076127ce the "appearance" settings got moved from the local storage to the server metadata. However, the old settings still remained in the local storage, which includes a value with they key "appTheme". This was the id of the selected app theme. With ff58dcc4803e23207234e7832f27bbb950a76c74 this key got resued for the app theme object, which leads to a type error in case the old setting is still present in the local storage. --- src/modules/theme/services/AppThemes.ts | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/modules/theme/services/AppThemes.ts b/src/modules/theme/services/AppThemes.ts index 638e8887..d860fbb5 100644 --- a/src/modules/theme/services/AppThemes.ts +++ b/src/modules/theme/services/AppThemes.ts @@ -21,22 +21,22 @@ export const appThemes = (Object.entries(themes) as [AppThemes, TBaseTheme][]).m ...theme, })) satisfies AppTheme[]; -export const getTheme = (id: AppThemes, customThemes: Record = {}): AppTheme => { - try { - const allThemes = { ...themes, ...customThemes }; - const theme = (allThemes[id as keyof typeof themes] as AppTheme) ?? themes.default; +export const getTheme = (id: AppThemes | undefined, customThemes: Record = {}): AppTheme => { + // TODO - This is a workaround to fix a type error which causes a white screen. + // It should be removed and replaced with a proper migration logic, which would then e.g., add a migration to + // remove deprecated/outdated settings from the local storage + const actualId = id === undefined ? 'default' : id; - return { - // @ts-ignore - custom themes do not have a "getName" function - getName: () => id, - // @ts-ignore - app themes do not have the "id" prop by default - id, - ...theme, - }; - } catch (e) { - defaultPromiseErrorHandler('getTheme')(e); - } - return { id, ...themes[id as keyof typeof themes] }; + const allThemes = { ...themes, ...customThemes }; + const theme = (allThemes[actualId as keyof typeof themes] as AppTheme) ?? themes.default; + + return { + // @ts-ignore - custom themes do not have a "getName" function + getName: () => id, + // @ts-ignore - app themes do not have the "id" prop by default + id, + ...theme, + }; }; export const isThemeNameUnique = (id: string, customThemes: Record): boolean =>