mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(site): respect meta user appearance preference as theme fallback (#22152)
Use the server-rendered meta tag value as an intermediate fallback for theme preference, between the JS-fetched value and the default theme. This ensures the correct theme is applied before the API response loads. Fixes #20050
This commit is contained in:
@@ -58,9 +58,12 @@ export const ThemeProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||
}, [themeQuery]);
|
||||
|
||||
// We might not be logged in yet, or the `theme_preference` could be an empty string.
|
||||
// Prefer JS-fetched value, fall back to server-rendered meta tag, then default.
|
||||
const themePreference =
|
||||
appearanceSettingsQuery.data?.theme_preference || DEFAULT_THEME;
|
||||
// The janky casting here is find because of the much more type safe fallback
|
||||
appearanceSettingsQuery.data?.theme_preference ||
|
||||
metadata.userAppearance?.value?.theme_preference ||
|
||||
DEFAULT_THEME;
|
||||
// The janky casting here is fine because of the much more type safe fallback
|
||||
// We need to support `themePreference` being wrong anyway because the database
|
||||
// value could be anything, like an empty string.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user