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 (round 2): palette effect loop, concurrent add, builtIn protection

Adam Eivy55b18d2032ba
diff --git a/client/src/components/CmdKSearch.jsx b/client/src/components/CmdKSearch.jsx
index 5ea6c0443a..a14ca32b3d 100644
--- a/client/src/components/CmdKSearch.jsx
+++ b/client/src/components/CmdKSearch.jsx
@@ -86,34 +86,52 @@ export default function CmdKSearch() {
}
}, [open]);
- // Manifest (nav + actions) is cached for the lifetime of the component —
- // static at module load on the server. Dashboard layouts change whenever
- // the user creates/renames one, so they're re-fetched on every open to
- // avoid a stale list on the same page mount.
+ // Split into two effects so setManifest never retriggers the fetch loop:
+ // 1. nav + actions are static server-side; fetched once, ever.
+ // 2. layouts change when the user creates/renames; re-fetched on open.
+ // Each updates `manifest` functionally without depending on its value.
useEffect(() => {
if (!open) return;
- const manifestPromise = manifest
- ? Promise.resolve({ nav: manifest.nav, actions: manifest.actions })
- : getPaletteManifest().then((data) => ({
- nav: (data?.nav || []).map(precompute),
- actions: (data?.actions || []).map(precompute),
- }));
- // Fetch layouts independently so a layouts-endpoint failure can't kill
- // nav + actions at the same time — each recovers with an empty list.
- const layoutsPromise = getDashboardLayouts().catch(() => ({ layouts: [] }));
- Promise.all([manifestPromise, layoutsPromise]).then(([m, dashboards]) => {
- const layouts = (dashboards?.layouts || []).map((l) => precompute({
- id: `layout.${l.id}`,
- layoutId: l.id,
- layoutName: l.name,
- label: `Dashboard: ${l.name}`,
- section: 'Layouts',
- aliases: ['layout', l.id, ...l.name.toLowerCase().split(/\s+/)],
- keywords: ['dashboard', 'layout', 'view'],
+ let cancelled = false;
+ getPaletteManifest().then((data) => {
+ if (cancelled) return;
+ const nav = (data?.nav || []).map(precompute);
+ const actions = (data?.actions || []).map(precompute);
+ setManifest((prev) => ({
+ nav,
+ actions,
+ layouts: prev?.layouts || [],
}));
- setManifest({ nav: m.nav, actions: m.actions, layouts });
});
- }, [open, manifest]);
+ return () => { cancelled = true; };
+ // Intentionally runs once per open-transition; `manifest` is not a dep.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [open]);
+
+ useEffect(() => {
+ if (!open) return;
+ let cancelled = false;
+ getDashboardLayouts()
+ .catch(() => ({ layouts: [] }))
+ .then((dashboards) => {
+ if (cancelled) return;
+ const layouts = (dashboards?.layouts || []).map((l) => precompute({
+ id: `layout.${l.id}`,
+ layoutId: l.id,
+ layoutName: l.name,
+ label: `Dashboard: ${l.name}`,
+ section: 'Layouts',
+ aliases: ['layout', l.id, ...l.name.toLowerCase().split(/\s+/)],
+ keywords: ['dashboard', 'layout', 'view'],
+ }));
+ setManifest((prev) => ({
+ nav: prev?.nav || [],
+ actions: prev?.actions || [],
+ layouts,
+ }));
+ });
+ return () => { cancelled = true; };
+ }, [open]);
useEffect(() => {
if (query.length < 2) {
diff --git a/client/src/components/dashboard/LayoutEditor.jsx b/client/src/components/dashboard/LayoutEditor.jsx
index 584c48ac2a..5fd519e54a 100644
--- a/client/src/components/dashboard/LayoutEditor.jsx
+++ b/client/src/components/dashboard/LayoutEditor.jsx
@@ -61,8 +61,7 @@ export default function LayoutEditor({ layouts, activeLayoutId, onClose, onSave,
};
const add = (id) => {
- if (widgets.includes(id)) return;
- setWidgets((prev) => [...prev, id]);
+ setWidgets((prev) => (prev.includes(id) ? prev : [...prev, id]));
setDirty(true);
};
diff --git a/server/services/dashboardLayouts.js b/server/services/dashboardLayouts.js
index 7b998700e5..3b0eccab9c 100644
--- a/server/services/dashboardLayouts.js
+++ b/server/services/dashboardLayouts.js
@@ -62,14 +62,18 @@ const DEFAULT_STATE = {
layouts: DEFAULT_LAYOUTS,
};
+const BUILTIN_IDS = new Set(DEFAULT_LAYOUTS.map((l) => l.id));
+
// Sanitize a single layout entry — protect against hand-edits that produce
-// non-object elements, missing fields, or non-array widget lists.
+// non-object elements, missing fields, or non-array widget lists. `builtIn`
+// is derived from the id, not the persisted flag, so a hand-edit flipping
+// the flag can't downgrade a built-in into a deletable user layout.
const sanitizeLayout = (l) => {
if (!l || typeof l !== 'object') return null;
if (typeof l.id !== 'string' || !l.id) return null;
if (typeof l.name !== 'string' || !l.name) return null;
const widgets = Array.isArray(l.widgets) ? l.widgets.filter((w) => typeof w === 'string') : [];
- return { id: l.id, name: l.name, builtIn: !!l.builtIn, widgets };
+ return { id: l.id, name: l.name, builtIn: BUILTIN_IDS.has(l.id), widgets };
};
export async function getState() {