refactor(ui): move bootstrap cache sync out of preferences

This commit is contained in:
Pascal André
2026-03-23 09:29:29 +01:00
parent 8c0a82d3a8
commit a442d53efa
3 changed files with 23 additions and 17 deletions

View File

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

View File

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

View File

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