Skip to content

Database diagrams editor that allows you to visualize and design your DB with a single query.

fix: fall back to system theme when stored theme is invalid (#1071) (#1173)

Jonathan Fishnera810b4180b0a
diff --git a/src/context/local-config-context/local-config-provider.tsx b/src/context/local-config-context/local-config-provider.tsx
index 97e7f885..c25eb317 100644
--- a/src/context/local-config-context/local-config-provider.tsx
+++ b/src/context/local-config-context/local-config-provider.tsx
@@ -12,12 +12,19 @@ const starUsDialogLastOpenKey = 'star_us_dialog_last_open';
const showMiniMapOnCanvasKey = 'show_minimap_on_canvas';
const showDBViewsKey = 'show_db_views';
+const validThemes: Theme[] = ['light', 'dark', 'system'];
+
+// Guard against stale/foreign localStorage values, which crash Monaco with
+// "illegal theme name" (#1071)
+const readStoredTheme = (): Theme => {
+ const stored = localStorage.getItem(themeKey) as Theme | null;
+ return stored && validThemes.includes(stored) ? stored : 'system';
+};
+
export const LocalConfigProvider: React.FC<React.PropsWithChildren> = ({
children,
}) => {
- const [theme, setTheme] = React.useState<Theme>(
- (localStorage.getItem(themeKey) as Theme) || 'system'
- );
+ const [theme, setTheme] = React.useState<Theme>(readStoredTheme);
const [scrollAction, setScrollAction] = React.useState<ScrollAction>(
(localStorage.getItem(scrollActionKey) as ScrollAction) || 'pan'