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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (round 20): pure add() + unmount guard on layouts fetch
Adam Eivyb2b9ae78079a
diff --git a/client/src/components/dashboard/LayoutEditor.jsx b/client/src/components/dashboard/LayoutEditor.jsxindex b461954fee..4feb65f049 100644--- a/client/src/components/dashboard/LayoutEditor.jsx+++ b/client/src/components/dashboard/LayoutEditor.jsx@@ -97,19 +97,15 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,};const add = (id) => {- let added = false;- setWidgets((prev) => {- if (prev.includes(id)) return prev;- // Match server's Zod cap so users don't hit a 400 on Save after- // silently accumulating past the limit.- if (prev.length >= widgetsMax) {- toast.error(`Layouts are capped at ${widgetsMax} widgets`);- return prev;- }- added = true;- return [...prev, id];- });- if (added) setDirty(true);+ if (widgets.includes(id)) return;+ // Match server's Zod cap so users don't hit a 400 on Save after+ // silently accumulating past the limit.+ if (widgets.length >= widgetsMax) {+ toast.error(`Layouts are capped at ${widgetsMax} widgets`);+ return;+ }+ setWidgets([...widgets, id]);+ setDirty(true);};// Each async handler awaits an API write through onSave/onDuplicate/diff --git a/client/src/pages/Dashboard.jsx b/client/src/pages/Dashboard.jsxindex 59bd88df27..c1627e827c 100644--- a/client/src/pages/Dashboard.jsx+++ b/client/src/pages/Dashboard.jsx@@ -45,15 +45,21 @@ export default function Dashboard() {}, [fetchData]);useEffect(() => {+ // `cancelled` guard prevents setState-on-unmounted warnings (and+ // accidental state writes) when the user navigates away before the+ // fetch resolves, or while a DASHBOARD_LAYOUT_CHANGED fetch is in+ // flight at unmount time.+ let cancelled = false;const fetchLayouts = () => api.getDashboardLayouts().then((data) => {+ if (cancelled) return;setLayouts(data.layouts);setActiveLayoutId(data.activeLayoutId);if (data.limits) setLayoutLimits(data.limits);setLayoutsError(null);})- .catch((err) => setLayoutsError(err.message))- .finally(() => setLayoutsLoading(false));+ .catch((err) => { if (!cancelled) setLayoutsError(err.message); })+ .finally(() => { if (!cancelled) setLayoutsLoading(false); });fetchLayouts();@@ -62,7 +68,10 @@ export default function Dashboard() {// (where navigate('/') would be a no-op and no remount happens).const handleLayoutChanged = () => fetchLayouts();window.addEventListener(DASHBOARD_LAYOUT_CHANGED, handleLayoutChanged);- return () => window.removeEventListener(DASHBOARD_LAYOUT_CHANGED, handleLayoutChanged);+ return () => {+ cancelled = true;+ window.removeEventListener(DASHBOARD_LAYOUT_CHANGED, handleLayoutChanged);+ };}, []);const sortedApps = useMemo(() =>