From f1ba699f9f292c990596a6c554c8a455dcf5b59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Andr=C3=A9?= Date: Mon, 23 Mar 2026 11:10:33 +0100 Subject: [PATCH] refactor(ui): drop bootstrap config cache layer --- .../ui/src/lib/ui-config-bootstrap-sync.tsx | 28 -------------- packages/ui/src/lib/ui-config-bootstrap.ts | 20 ---------- packages/ui/src/main.tsx | 37 ++++++------------- 3 files changed, 12 insertions(+), 73 deletions(-) delete mode 100644 packages/ui/src/lib/ui-config-bootstrap-sync.tsx delete mode 100644 packages/ui/src/lib/ui-config-bootstrap.ts diff --git a/packages/ui/src/lib/ui-config-bootstrap-sync.tsx b/packages/ui/src/lib/ui-config-bootstrap-sync.tsx deleted file mode 100644 index 2df1f97e..00000000 --- a/packages/ui/src/lib/ui-config-bootstrap-sync.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { createEffect } from "solid-js" -import { useGlobalCache } from "./hooks/use-global-cache" -import { useConfig } from "../stores/preferences" -import type { UiBootstrapConfig } from "./ui-config-bootstrap" - -export function UiConfigBootstrapSync() { - const { isLoaded, preferences, themePreference } = useConfig() - const cache = useGlobalCache({ - scope: "ui-bootstrap", - cacheId: "ui-config", - version: "1", - }) - - createEffect(() => { - if (!isLoaded()) { - return - } - - const next: UiBootstrapConfig = { - theme: themePreference(), - locale: preferences().locale, - } - - cache.set(next) - }) - - return null -} diff --git a/packages/ui/src/lib/ui-config-bootstrap.ts b/packages/ui/src/lib/ui-config-bootstrap.ts deleted file mode 100644 index e8f483a8..00000000 --- a/packages/ui/src/lib/ui-config-bootstrap.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { getCacheEntry } from "./global-cache" - -export interface UiBootstrapConfig { - theme?: "light" | "dark" | "system" - locale?: string -} - -const UI_BOOTSTRAP_CACHE_ENTRY = { - scope: "ui-bootstrap", - cacheId: "ui-config", - version: "1", -} as const - -export function readUiBootstrapConfig(): UiBootstrapConfig { - return getCacheEntry(UI_BOOTSTRAP_CACHE_ENTRY) ?? {} -} - -export function getUiBootstrapCacheEntry() { - return UI_BOOTSTRAP_CACHE_ENTRY -} diff --git a/packages/ui/src/main.tsx b/packages/ui/src/main.tsx index 72da86dc..4be1fc57 100644 --- a/packages/ui/src/main.tsx +++ b/packages/ui/src/main.tsx @@ -6,8 +6,6 @@ import { InstanceConfigProvider } from "./stores/instance-config" import { runtimeEnv } from "./lib/runtime-env" import { I18nProvider, preloadLocaleMessages } from "./lib/i18n" import { storage } from "./lib/storage" -import { readUiBootstrapConfig } from "./lib/ui-config-bootstrap" -import { UiConfigBootstrapSync } from "./lib/ui-config-bootstrap-sync" import "./index.css" import "@git-diff-view/solid/styles/diff-view-pure.css" @@ -31,38 +29,27 @@ async function bootstrap() { // (and then refine once persisted config loads). document.documentElement.removeAttribute("data-theme") - const cachedUiConfig = readUiBootstrapConfig() - let theme = cachedUiConfig.theme - let locale = cachedUiConfig.locale + try { + const uiConfig = await storage.loadConfigOwner("ui") + const theme = (uiConfig as any)?.theme + const locale = typeof (uiConfig as any)?.settings?.locale === "string" ? (uiConfig as any).settings.locale : undefined - if (theme === undefined || locale === undefined) { - try { - const uiConfig = await storage.loadConfigOwner("ui") - if (theme === undefined) { - const nextTheme = (uiConfig as any)?.theme - theme = nextTheme === "light" || nextTheme === "dark" || nextTheme === "system" ? nextTheme : undefined - } - if (locale === undefined) { - locale = typeof (uiConfig as any)?.settings?.locale === "string" ? (uiConfig as any).settings.locale : undefined - } - } catch { - // If config fails to load, fall back to CSS defaults. + if (theme === "light" || theme === "dark") { + document.documentElement.setAttribute("data-theme", theme) + } else { + document.documentElement.removeAttribute("data-theme") } - } - if (!theme || theme === "system") { - document.documentElement.removeAttribute("data-theme") - } else { - document.documentElement.setAttribute("data-theme", theme) + await preloadLocaleMessages(locale) + } catch { + // If config fails to load, fall back to CSS defaults. + await preloadLocaleMessages() } - - await preloadLocaleMessages(locale) } render( () => ( -