refactor(ui): drop bootstrap config cache layer

This commit is contained in:
Pascal André
2026-03-23 11:10:33 +01:00
parent 0cb1c05903
commit f1ba699f9f
3 changed files with 12 additions and 73 deletions

View File

@@ -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
}

View File

@@ -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<UiBootstrapConfig>(UI_BOOTSTRAP_CACHE_ENTRY) ?? {}
}
export function getUiBootstrapCacheEntry() {
return UI_BOOTSTRAP_CACHE_ENTRY
}

View File

@@ -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(
() => (
<ConfigProvider>
<UiConfigBootstrapSync />
<InstanceConfigProvider>
<I18nProvider>
<ThemeProvider>