From ed4c9ebd8c0c8091b71bdfd0af170262d75556dd Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 29 Mar 2026 12:30:28 -0700 Subject: [PATCH] Fix theme token overrides and mount appearance early - Write theme CSS variables at the intermediate token level so Tailwind picks them up - Call `useAppearance()` before the root route can return early to satisfy Hooks rules --- apps/web/src/lib/themes.ts | 4 +++- apps/web/src/routes/__root.tsx | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/web/src/lib/themes.ts b/apps/web/src/lib/themes.ts index 6ba4bb7792..08208a191e 100644 --- a/apps/web/src/lib/themes.ts +++ b/apps/web/src/lib/themes.ts @@ -164,7 +164,9 @@ const STYLE_ELEMENT_ID = "t3code-theme-tokens"; function buildCssBlock(selector: string, tokens: ThemeTokenMap): string { const entries = Object.entries(tokens) as [ThemeToken, string][]; if (entries.length === 0) return ""; - const declarations = entries.map(([token, value]) => ` --color-${token}: ${value};`).join("\n"); + // Override the intermediate CSS variables (--primary, --ring, etc.) + // which feed into Tailwind's --color-* via @theme inline { --color-primary: var(--primary) }. + const declarations = entries.map(([token, value]) => ` --${token}: ${value};`).join("\n"); return `${selector} {\n${declarations}\n}`; } diff --git a/apps/web/src/routes/__root.tsx b/apps/web/src/routes/__root.tsx index 92ab8adf55..4a7778409c 100644 --- a/apps/web/src/routes/__root.tsx +++ b/apps/web/src/routes/__root.tsx @@ -39,6 +39,11 @@ export const Route = createRootRouteWithContext<{ }); function RootRouteView() { + // Mount appearance system — drives .dark class, theme tokens, and Electron sync. + // Must be called before any early returns to satisfy React's Rules of Hooks. + // The import also triggers module-scope FOUC prevention. + useAppearance(); + if (!readNativeApi()) { return (
@@ -51,10 +56,6 @@ function RootRouteView() { ); } - // Mount appearance system — drives .dark class, theme tokens, and Electron sync. - // The import also triggers module-scope FOUC prevention. - useAppearance(); - return (