Prevent white screen on page load
Bug introduced withff58dcc480. With18ddf46f17the "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. Withff58dcc480this 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:
@@ -21,22 +21,22 @@ export const appThemes = (Object.entries(themes) as [AppThemes, TBaseTheme][]).m
|
|||||||
...theme,
|
...theme,
|
||||||
})) satisfies AppTheme[];
|
})) satisfies AppTheme[];
|
||||||
|
|
||||||
export const getTheme = (id: AppThemes, customThemes: Record<string, AppTheme> = {}): AppTheme => {
|
export const getTheme = (id: AppThemes | undefined, customThemes: Record<string, AppTheme> = {}): AppTheme => {
|
||||||
try {
|
// TODO - This is a workaround to fix a type error which causes a white screen.
|
||||||
const allThemes = { ...themes, ...customThemes };
|
// It should be removed and replaced with a proper migration logic, which would then e.g., add a migration to
|
||||||
const theme = (allThemes[id as keyof typeof themes] as AppTheme) ?? themes.default;
|
// remove deprecated/outdated settings from the local storage
|
||||||
|
const actualId = id === undefined ? 'default' : id;
|
||||||
|
|
||||||
return {
|
const allThemes = { ...themes, ...customThemes };
|
||||||
// @ts-ignore - custom themes do not have a "getName" function
|
const theme = (allThemes[actualId as keyof typeof themes] as AppTheme) ?? themes.default;
|
||||||
getName: () => id,
|
|
||||||
// @ts-ignore - app themes do not have the "id" prop by default
|
return {
|
||||||
id,
|
// @ts-ignore - custom themes do not have a "getName" function
|
||||||
...theme,
|
getName: () => id,
|
||||||
};
|
// @ts-ignore - app themes do not have the "id" prop by default
|
||||||
} catch (e) {
|
id,
|
||||||
defaultPromiseErrorHandler('getTheme')(e);
|
...theme,
|
||||||
}
|
};
|
||||||
return { id, ...themes[id as keyof typeof themes] };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isThemeNameUnique = (id: string, customThemes: Record<string, AppTheme>): boolean =>
|
export const isThemeNameUnique = (id: string, customThemes: Record<string, AppTheme>): boolean =>
|
||||||
|
|||||||
Reference in New Issue
Block a user