diff --git a/src/common/use-storage.ts b/src/common/use-storage.ts index 3cf8fd4dc..fe7ed6973 100644 --- a/src/common/use-storage.ts +++ b/src/common/use-storage.ts @@ -14,7 +14,8 @@ export function useStorage( storageType: storageType, key: string, defaultValue: T, - validate?: (x: unknown) => x is T + validate?: (x: unknown) => x is T, + overrides?: Partial ): [T, (value: T) => void] { const [state, setState] = useState(() => { const storage = @@ -29,6 +30,7 @@ export function useStorage( parsed = { ...defaultValue, ...parsed, + ...overrides, }; // Remove any top-level keys that aren't present in defaults. const unknownKeys = new Set(Object.keys(parsed)); diff --git a/src/settings/settings.tsx b/src/settings/settings.tsx index 9cb554a6e..c90bcfcd3 100644 --- a/src/settings/settings.tsx +++ b/src/settings/settings.tsx @@ -7,6 +7,7 @@ import { createContext, ReactNode, useContext } from "react"; import { useStorage } from "../common/use-storage"; import { defaultCodeFontSizePt } from "../deployment/misc"; import { stage } from "../environment"; +import { flags } from "../flags"; export interface Language { id: string; @@ -168,14 +169,15 @@ export const useSettings = (): SettingsContextValue => { }; const SettingsProvider = ({ children }: { children: ReactNode }) => { - const settings = useStorage( + const [settings, setSettings] = useStorage( "local", "settings", defaultSettings, - isValidSettingsObject + isValidSettingsObject, + flags.noLang ? { languageId: getLanguageFromQuery() } : {} ); return ( - + {children} );