From a442d53efa4c4697131dd4f4c3844846a5ccd582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Andr=C3=A9?= Date: Mon, 23 Mar 2026 09:29:29 +0100 Subject: [PATCH] refactor(ui): move bootstrap cache sync out of preferences --- .../ui/src/lib/ui-bootstrap-cache-sync.tsx | 20 +++++++++++++++++++ packages/ui/src/main.tsx | 2 ++ packages/ui/src/stores/preferences.tsx | 18 +---------------- 3 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 packages/ui/src/lib/ui-bootstrap-cache-sync.tsx diff --git a/packages/ui/src/lib/ui-bootstrap-cache-sync.tsx b/packages/ui/src/lib/ui-bootstrap-cache-sync.tsx new file mode 100644 index 00000000..00abf91b --- /dev/null +++ b/packages/ui/src/lib/ui-bootstrap-cache-sync.tsx @@ -0,0 +1,20 @@ +import { createEffect } from "solid-js" +import { useConfig } from "../stores/preferences" +import { writeUiBootstrapCache } from "./ui-bootstrap-cache" + +export function UiBootstrapCacheSync() { + const { isLoaded, preferences, themePreference } = useConfig() + + createEffect(() => { + if (!isLoaded()) { + return + } + + writeUiBootstrapCache({ + theme: themePreference(), + locale: preferences().locale ?? null, + }) + }) + + return null +} diff --git a/packages/ui/src/main.tsx b/packages/ui/src/main.tsx index 6ddc40e1..648ff782 100644 --- a/packages/ui/src/main.tsx +++ b/packages/ui/src/main.tsx @@ -6,6 +6,7 @@ import { InstanceConfigProvider } from "./stores/instance-config" import { runtimeEnv } from "./lib/runtime-env" import { I18nProvider, preloadLocaleMessages } from "./lib/i18n" import { readUiBootstrapCache } from "./lib/ui-bootstrap-cache" +import { UiBootstrapCacheSync } from "./lib/ui-bootstrap-cache-sync" import "./index.css" import "@git-diff-view/solid/styles/diff-view-pure.css" @@ -44,6 +45,7 @@ async function bootstrap() { render( () => ( + diff --git a/packages/ui/src/stores/preferences.tsx b/packages/ui/src/stores/preferences.tsx index ddc0a718..8ac2ead0 100644 --- a/packages/ui/src/stores/preferences.tsx +++ b/packages/ui/src/stores/preferences.tsx @@ -1,7 +1,6 @@ -import { createContext, createEffect, createMemo, createSignal, onMount, useContext } from "solid-js" +import { createContext, createMemo, createSignal, onMount, useContext } from "solid-js" import type { Accessor, ParentComponent } from "solid-js" import { storage, type OwnerBucket } from "../lib/storage" -import { writeUiBootstrapCache } from "../lib/ui-bootstrap-cache" import { ensureInstanceConfigLoaded, getInstanceConfig, @@ -599,21 +598,6 @@ const configContextValue: ConfigContextValue = { } export const ConfigProvider: ParentComponent = (props) => { - createEffect(() => { - if (!isLoaded()) { - return - } - - const bucket = uiConfigBucket() - const theme = bucket.theme - const locale = bucket.settings?.locale - - writeUiBootstrapCache({ - theme: theme ?? null, - locale: locale ?? null, - }) - }) - onMount(() => { ensureLoaded().catch((error: unknown) => { log.error("Failed to initialize settings", error)