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
fix([codex5-dashboard-intent-layouts]): throttle widget-suggestion add to one in-flight save (codex iter-4)
[._.]/ Adam Eivy475f97a7ff96
diff --git a/client/src/components/dashboard/WidgetSuggestions.jsx b/client/src/components/dashboard/WidgetSuggestions.jsxindex 8cadf82226..c649f89b99 100644--- a/client/src/components/dashboard/WidgetSuggestions.jsx+++ b/client/src/components/dashboard/WidgetSuggestions.jsx@@ -8,6 +8,12 @@ import { WIDGETS } from './widgetRegistry.jsx';// catalog outgrows the 3 gated widgets we ship today.export default function WidgetSuggestions({ presentWidgetIds, dashboardState, onAdd }) {const [dismissed, setDismissed] = useState(() => new Set());+ // Only one in-flight save at a time. Without this, two rapid clicks each+ // compute their merge from the same stale `presentWidgetIds`, and the+ // second PUT's payload drops the first added widget. Gating on submission+ // forces the second click to wait for the parent's `presentWidgetIds` to+ // refresh after the first save resolves.+ const [submitting, setSubmitting] = useState(false);const suggestions = useMemo(() => {if (!Array.isArray(presentWidgetIds)) return [];@@ -29,7 +35,11 @@ export default function WidgetSuggestions({ presentWidgetIds, dashboardState, on});const add = (id) => {- Promise.resolve(onAdd(id)).catch(() => {});+ if (submitting) return;+ setSubmitting(true);+ Promise.resolve(onAdd(id))+ .catch(() => {})+ .finally(() => setSubmitting(false));};return (@@ -41,7 +51,8 @@ export default function WidgetSuggestions({ presentWidgetIds, dashboardState, on<buttontype="button"onClick={() => add(w.id)}- className="inline-flex items-center gap-1 text-port-accent hover:text-white"+ disabled={submitting}+ className="inline-flex items-center gap-1 text-port-accent hover:text-white disabled:opacity-50 disabled:cursor-wait"aria-label={`Add ${w.label} to layout`}><Plus size={12} aria-hidden="true" />@@ -50,7 +61,8 @@ export default function WidgetSuggestions({ presentWidgetIds, dashboardState, on<buttontype="button"onClick={() => dismiss(w.id)}- className="p-0.5 rounded text-gray-500 hover:text-gray-300"+ disabled={submitting}+ className="p-0.5 rounded text-gray-500 hover:text-gray-300 disabled:opacity-50"aria-label={`Dismiss ${w.label} suggestion`}title="Hide this suggestion">diff --git a/client/src/components/dashboard/WidgetSuggestions.test.jsx b/client/src/components/dashboard/WidgetSuggestions.test.jsxindex fb0be5e257..e00289ff6c 100644--- a/client/src/components/dashboard/WidgetSuggestions.test.jsx+++ b/client/src/components/dashboard/WidgetSuggestions.test.jsx@@ -51,4 +51,20 @@ describe('WidgetSuggestions', () => {fireEvent.click(screen.getByLabelText('Dismiss Quick Stats suggestion'));expect(screen.queryByText(/Quick Stats/)).toBeNull();});++ it('throttles to one in-flight add — rapid second click is dropped', async () => {+ let resolveFirst;+ const onAdd = vi.fn().mockImplementation(() => new Promise((resolve) => { resolveFirst = resolve; }));+ render(<WidgetSuggestions presentWidgetIds={[]} dashboardState={populatedState} onAdd={onAdd} />);+ // Both Quick Stats AND Activity Streak gate true on populatedState.+ fireEvent.click(screen.getByLabelText('Add Quick Stats to layout'));+ fireEvent.click(screen.getByLabelText('Add Activity Streak to layout'));+ // Only the first click fired onAdd; without the throttle, both would+ // fire with stale presentWidgetIds and the second PUT would drop the+ // first added widget.+ expect(onAdd).toHaveBeenCalledTimes(1);+ expect(onAdd).toHaveBeenCalledWith('quick-stats');+ resolveFirst();+ await Promise.resolve();+ });});