Prevent white screen on page load

Bug introduced with ff58dcc480.
With 18ddf46f17 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 ff58dcc480 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.
This commit is contained in:
schroda
2025-08-01 20:30:24 +02:00
parent cd04be7f52
commit c758cc41e1

View File

@@ -21,10 +21,14 @@ export const appThemes = (Object.entries(themes) as [AppThemes, TBaseTheme][]).m
...theme,
})) satisfies AppTheme[];
export const getTheme = (id: AppThemes, customThemes: Record<string, AppTheme> = {}): AppTheme => {
try {
export const getTheme = (id: AppThemes | undefined, customThemes: Record<string, AppTheme> = {}): 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;
const allThemes = { ...themes, ...customThemes };
const theme = (allThemes[id as keyof typeof themes] as AppTheme) ?? themes.default;
const theme = (allThemes[actualId as keyof typeof themes] as AppTheme) ?? themes.default;
return {
// @ts-ignore - custom themes do not have a "getName" function
@@ -33,10 +37,6 @@ export const getTheme = (id: AppThemes, customThemes: Record<string, AppTheme> =
id,
...theme,
};
} catch (e) {
defaultPromiseErrorHandler('getTheme')(e);
}
return { id, ...themes[id as keyof typeof themes] };
};
export const isThemeNameUnique = (id: string, customThemes: Record<string, AppTheme>): boolean =>