## Summary - defer locale and overlay loading work away from the first critical render path - seed locale state from the bootstrap preload so the first render can use the preloaded language immediately - keep bootstrap cache and locale fallback behavior consistent on subsequent launches ## Testing - npm run build --workspace @codenomad/ui
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { render } from "solid-js/web"
|
|
import App from "./App"
|
|
import { ThemeProvider } from "./lib/theme"
|
|
import { ConfigProvider } from "./stores/preferences"
|
|
import { InstanceConfigProvider } from "./stores/instance-config"
|
|
import { runtimeEnv } from "./lib/runtime-env"
|
|
import { I18nProvider, preloadLocaleMessages } from "./lib/i18n"
|
|
import { storage } from "./lib/storage"
|
|
import "./index.css"
|
|
import "@git-diff-view/solid/styles/diff-view-pure.css"
|
|
|
|
const root = document.getElementById("root")
|
|
|
|
if (!root) {
|
|
throw new Error("Root element not found")
|
|
}
|
|
|
|
const mount = root
|
|
|
|
if (typeof document !== "undefined") {
|
|
document.documentElement.dataset.runtimeHost = runtimeEnv.host
|
|
document.documentElement.dataset.runtimePlatform = runtimeEnv.platform
|
|
}
|
|
|
|
async function bootstrap() {
|
|
if (typeof document !== "undefined") {
|
|
// renderer/index.html currently seeds a dark theme to avoid a white flash.
|
|
// Reset to CSS defaults immediately so the first render matches system
|
|
// (and then refine once persisted config loads).
|
|
document.documentElement.removeAttribute("data-theme")
|
|
|
|
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 === "light" || theme === "dark") {
|
|
document.documentElement.setAttribute("data-theme", theme)
|
|
} else {
|
|
document.documentElement.removeAttribute("data-theme")
|
|
}
|
|
|
|
await preloadLocaleMessages(locale)
|
|
} catch {
|
|
// If config fails to load, fall back to CSS defaults.
|
|
await preloadLocaleMessages()
|
|
}
|
|
}
|
|
|
|
render(
|
|
() => (
|
|
<ConfigProvider>
|
|
<InstanceConfigProvider>
|
|
<I18nProvider>
|
|
<ThemeProvider>
|
|
<App />
|
|
</ThemeProvider>
|
|
</I18nProvider>
|
|
</InstanceConfigProvider>
|
|
</ConfigProvider>
|
|
),
|
|
mount,
|
|
)
|
|
}
|
|
|
|
void bootstrap()
|