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
This commit is contained in:
1 parent
f4ab7ebe21
commit
ed4c9ebd8c
2 files changed
+8
-5
No files matched your search
@@ -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}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<div className="flex h-screen flex-col bg-background text-foreground">
|
||||
@@ -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 (
|
||||
<ToastProvider>
|
||||
<AnchoredToastProvider>
|
||||
|
||||
Reference in new issue
Block a user