Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review: fix runtime races and contract gaps in theme system

Adam Eivy4f3a9ecd1327
diff --git a/client/src/components/ThemeSwitcher.jsx b/client/src/components/ThemeSwitcher.jsx
index 6f83c41f20..6406936073 100644
--- a/client/src/components/ThemeSwitcher.jsx
+++ b/client/src/components/ThemeSwitcher.jsx
@@ -21,11 +21,17 @@ export default function ThemeSwitcher({ position = 'above', className = '' }) {
const menu = menuRef.current;
if (!trigger || !menu) return;
- const triggerRect = trigger.getBoundingClientRect();
- const menuRect = menu.getBoundingClientRect();
const viewportWidth = window.innerWidth;
const viewportHeight = window.innerHeight;
const width = Math.min(MENU_WIDTH, Math.max(180, viewportWidth - VIEWPORT_PADDING * 2));
+
+ // Apply width before measuring height — narrow viewports may wrap content
+ // and grow the menu's height. Measuring at the wrong width produces a
+ // top value that under-clamps and lets the portal overflow.
+ menu.style.width = `${width}px`;
+
+ const triggerRect = trigger.getBoundingClientRect();
+ const menuRect = menu.getBoundingClientRect();
const maxLeft = viewportWidth - width - VIEWPORT_PADDING;
const left = Math.min(
Math.max(triggerRect.right - width, VIEWPORT_PADDING),
diff --git a/client/src/hooks/useTheme.js b/client/src/hooks/useTheme.js
index d621e7e03a..b35dec51c9 100644
--- a/client/src/hooks/useTheme.js
+++ b/client/src/hooks/useTheme.js
@@ -1,4 +1,4 @@
-import { useState, useCallback, useEffect } from 'react';
+import { useState, useCallback, useEffect, useRef } from 'react';
import {
THEMES,
THEME_LIST,
@@ -35,22 +35,26 @@ export default function useTheme() {
applyTheme(id);
return id;
});
+ const userPickedRef = useRef(false);
useEffect(() => {
fetch('/api/settings')
.then(r => r.ok ? r.json() : null)
.then(settings => {
+ if (userPickedRef.current) return;
const serverTheme = settings?.theme ? normalizeThemeId(settings.theme) : null;
- if (serverTheme && serverTheme !== themeId) {
+ const currentSaved = normalizeThemeId(localStorage.getItem(STORAGE_KEY));
+ if (serverTheme && serverTheme !== currentSaved) {
localStorage.setItem(STORAGE_KEY, serverTheme);
applyTheme(serverTheme);
setThemeId(serverTheme);
}
})
.catch(() => console.log('Theme fetch failed, using localStorage fallback'));
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
+ }, []);
const setTheme = useCallback((id) => {
+ userPickedRef.current = true;
const normalized = normalizeThemeId(id);
localStorage.setItem(STORAGE_KEY, normalized);
applyTheme(normalized);
diff --git a/client/src/index.css b/client/src/index.css
index 9083672a60..4ec15e9611 100644
--- a/client/src/index.css
+++ b/client/src/index.css
@@ -239,8 +239,7 @@ html[data-port-theme] header button {
}
html[data-port-theme] aside nav :is(a, button):hover,
-html[data-port-theme] header :is(a, button):hover,
-html[data-port-theme] [class*="hover:bg-port-border"]:hover {
+html[data-port-theme] header :is(a, button):hover {
background: var(--port-hover-bg) !important;
}
diff --git a/scripts/check-themes.js b/scripts/check-themes.js
index 6c3d186356..6cb8eb481f 100644
--- a/scripts/check-themes.js
+++ b/scripts/check-themes.js
@@ -47,6 +47,7 @@ const REQUIRED_TOKEN_VARS = [
'--port-backdrop-filter',
'--port-body-gradient',
'--port-body-texture',
+ '--port-body-overlay-opacity',
'--port-app-backdrop',
'--port-sidebar-bg',
'--port-input-bg',
@@ -62,6 +63,13 @@ const REQUIRED_TOKEN_VARS = [
'--port-chart-3',
'--port-chart-4',
'--port-chart-grid',
+ '--port-bg-alpha',
+ '--port-card-alpha',
+ '--port-border-alpha',
+ '--port-border-style',
+ '--port-motion-fast',
+ '--port-motion-medium',
+ '--port-motion-slow',
];
const REQUIRED_DOC_SECTIONS = [