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: track an unmoved-order baseline so reorders of just-added widgets register (#4132)
[._.]/ Adam Eivy8fc1d88838bc
diff --git a/client/src/components/dashboard/CLAUDE.md b/client/src/components/dashboard/CLAUDE.mdindex 9b3ab55101..46758ceebc 100644--- a/client/src/components/dashboard/CLAUDE.md+++ b/client/src/components/dashboard/CLAUDE.md@@ -12,7 +12,7 @@ On drop, `onDragEnd` re-flows the whole grid through `reflowToOrder` so its read**One source of truth for the mobile/desktop seam.** `DashboardGrid` measures its own *container* (`useContainerWidth`), which page padding makes narrower than the viewport — so a Tailwind `sm:` breakpoint disagrees with it in a ~30px band. Anything outside the grid that needs to know which affordance is live (the Dashboard's edit-mode hint) reads it from the `onLayoutModeChange` callback, never from a CSS breakpoint.-**Widget order lives in the grid.** `saveGridEdit` rewrites the layout's `widgets` array into `readingOrderIds(grid)` so LayoutEditor lists widgets in the order the dashboard actually shows them. By default `reconcileGrid` iterates the *grid* and uses `widgets` only for membership — position edits survive a widget toggle or a rename. LayoutEditor's Move up/down buttons therefore have to say so explicitly: `save`/`commitDuplicate` pass `reordered` (derived by `isReordered()` from the draft list vs the stored one, so a move-up-then-back nets out to `false`), and `Dashboard.jsx` forwards it as `reconcileGrid(base, widgets, { reorder })`, which re-flows the reconciled grid to the list order. **Never infer that flag by comparing `widgets` to `readingOrderIds(grid)`** — layouts arranged before `saveGridEdit` started syncing the two can already disagree, so inferring would re-pack a carefully arranged desktop layout on the first unrelated save (#4132).+**Widget order lives in the grid.** `saveGridEdit` rewrites the layout's `widgets` array into `readingOrderIds(grid)` so LayoutEditor lists widgets in the order the dashboard actually shows them. By default `reconcileGrid` iterates the *grid* and uses `widgets` only for membership — position edits survive a widget toggle or a rename. LayoutEditor's Move up/down buttons therefore have to say so explicitly: `save`/`commitDuplicate` pass `reordered`, which `isReordered()` derives by comparing the draft list against the `unmovedOrder` ref — the order the draft would have had if the user had never pressed Move (`add` appends to it, `remove` filters it, `move` deliberately doesn't touch it). That baseline can't be reconstructed from the widget list after the fact, since nothing in it records which widgets were added this session or in what order; keeping it means a move-up-then-back nets out to `false` while a just-added widget being moved, or any reorder in a layout that started empty, still reads as `true`, and `Dashboard.jsx` forwards it as `reconcileGrid(base, widgets, { reorder })`, which re-flows the reconciled grid to the list order. **Never infer that flag by comparing `widgets` to `readingOrderIds(grid)`** — layouts arranged before `saveGridEdit` started syncing the two can already disagree, so inferring would re-pack a carefully arranged desktop layout on the first unrelated save (#4132).**When adding a new dashboard widget:**1. Add a `{ id, label, Component, width, defaultH?, gate? }` entry to `WIDGETS` in `widgetRegistry.jsx`. Use a stable `id` (kebab-case) — it's the contract stored in layouts. Pick `defaultH` from the widget's rough content height (default `4`); it only has to be close, since the cell measures itself once painted.diff --git a/client/src/components/dashboard/LayoutEditor.jsx b/client/src/components/dashboard/LayoutEditor.jsxindex b8b6ae032f..d501319f1f 100644--- a/client/src/components/dashboard/LayoutEditor.jsx+++ b/client/src/components/dashboard/LayoutEditor.jsx@@ -30,6 +30,14 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,const [dupName, setDupName] = useState('');const [pendingSwitchId, setPendingSwitchId] = useState(null);const closeRef = useRef(null);+ // The order this draft would have if the user had never pressed Move: the+ // stored order, with `add`'s appends and `remove`'s deletions applied but+ // `move` deliberately left out. Comparing it against `widgets` at save time+ // is what tells the dashboard whether the ORDER is part of this edit — see+ // isReordered below. It can't be derived from `widgets` after the fact,+ // because nothing in the list records which widgets were added in this+ // session or in what order. A ref, not state: no render depends on it.+ const unmovedOrder = useRef(editing?.widgets ?? []);useScrollLock(true);@@ -48,6 +56,7 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,if (!cur) return;if (dirty) return;setWidgets(cur.widgets);+ unmovedOrder.current = cur.widgets;setName(cur.name);setActivateWindow(cur.activateWindow ?? null);setMode('idle');@@ -108,24 +117,15 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,// The dashboard renders from the layout's `grid`, not from this list, so a// save has to say out loud when the widget order IS the edit — otherwise the// grid keeps its old reading order and Move up/down looks inert (#4132).- // Derived rather than a sticky flag so moving a widget up and back down again- // nets out to "not a reorder". `remove` filters and `add` appends, so the- // list the draft WOULD have without any `move` is reconstructible exactly:- // the surviving stored widgets in their stored order, then the newly added- // ones in the order they were added. Anything else is a reorder — including- // moving a widget that was added in this same editing session.- const isReordered = () => {- const stored = editing?.widgets ?? [];- const storedIds = new Set(stored);- const unmoved = [- ...stored.filter((id) => widgets.includes(id)),- ...widgets.filter((id) => !storedIds.has(id)),- ];- return widgets.length !== unmoved.length || widgets.some((id, i) => id !== unmoved[i]);- };+ // Both lists always hold the same widgets, so a positional compare is exact.+ // Because only `move` can make them differ, a move up followed by a move+ // back down correctly nets out to "not a reorder", and a widget added in+ // this session and then moved is caught like any other.+ const isReordered = () => widgets.some((id, i) => id !== unmovedOrder.current[i]);const remove = (id) => {setWidgets((prev) => prev.filter((w) => w !== id));+ unmovedOrder.current = unmovedOrder.current.filter((w) => w !== id);setDirty(true);};@@ -138,6 +138,7 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,return;}setWidgets([...widgets, id]);+ unmovedOrder.current = [...unmovedOrder.current, id];setDirty(true);};diff --git a/client/src/components/dashboard/LayoutEditor.test.jsx b/client/src/components/dashboard/LayoutEditor.test.jsxindex 7d52cf14d7..3d06d797ae 100644--- a/client/src/components/dashboard/LayoutEditor.test.jsx+++ b/client/src/components/dashboard/LayoutEditor.test.jsx@@ -22,13 +22,13 @@ const LAYOUT = {],};-async function renderEditor() {+async function renderEditor(layout = LAYOUT) {const onSave = vi.fn().mockResolvedValue(undefined);const onDuplicate = vi.fn().mockResolvedValue(undefined);render(<LayoutEditor- layouts={[LAYOUT]}- activeLayoutId={LAYOUT.id}+ layouts={[layout]}+ activeLayoutId={layout.id}limits={null}onClose={vi.fn()}onSave={onSave}@@ -40,9 +40,12 @@ async function renderEditor() {return { onSave, onDuplicate };}+// Queries go through text/label rather than `getByRole(…, { name })`: the+// editor renders a button per registered widget, and computing an accessible+// name for every one of them on each query costs seconds under load.// The widget rows are the only <li>s once a layout has widgets.-const widgetRows = () => screen.getAllByRole('listitem');-const clickButton = (name) => fireEvent.click(screen.getByRole('button', { name }));+const widgetRows = () => [...document.querySelectorAll('li')];+const clickButton = (label) => fireEvent.click(screen.getByText(label).closest('button'));const moveUp = (idx) => fireEvent.click(within(widgetRows()[idx]).getByLabelText('Move up'));const moveDown = (idx) => fireEvent.click(within(widgetRows()[idx]).getByLabelText('Move down'));// Two settles: one to run the click's own async handler, one to let the@@ -51,7 +54,7 @@ const settle = async (fire) => {await act(async () => { fire(); });await act(async () => {});};-const save = () => settle(() => clickButton(/^Save$/));+const save = () => settle(() => clickButton('Save'));describe('LayoutEditor reorder signal', () => {beforeEach(() => { vi.clearAllMocks(); });@@ -98,7 +101,7 @@ describe('LayoutEditor reorder signal', () => {it('does not flag a widget toggle as a reorder', async () => {const { onSave } = await renderEditor();fireEvent.click(within(widgetRows()[1]).getByLabelText('Remove widget'));- clickButton(/Death Clock/);+ clickButton('Death Clock');await save();expect(onSave).toHaveBeenCalledWith(expect.objectContaining({widgets: ['quick-task', 'backup', 'death-clock'],@@ -110,7 +113,7 @@ describe('LayoutEditor reorder signal', () => {// would otherwise auto-place it at the bottom, ignoring where it was put.it('flags a widget that was added and then moved up', async () => {const { onSave } = await renderEditor();- clickButton(/Death Clock/);+ clickButton('Death Clock');moveUp(3);await save();expect(onSave).toHaveBeenCalledWith(expect.objectContaining({@@ -119,6 +122,32 @@ describe('LayoutEditor reorder signal', () => {}));});+ it('flags a swap between two widgets added in the same session', async () => {+ const { onSave } = await renderEditor();+ clickButton('Death Clock');+ clickButton('Review Hub');+ moveUp(4);+ await save();+ expect(onSave).toHaveBeenCalledWith(expect.objectContaining({+ widgets: [...WIDGET_IDS, 'review-hub', 'death-clock'],+ reordered: true,+ }));+ });++ // A layout with nothing stored has no order to compare against — the+ // baseline has to come from the order the widgets were added in.+ it('flags a reorder in a layout that started empty', async () => {+ const { onSave } = await renderEditor({ id: 'blank', name: 'Blank', widgets: [], grid: [] });+ clickButton('Death Clock');+ clickButton('Review Hub');+ moveUp(1);+ await save();+ expect(onSave).toHaveBeenCalledWith(expect.objectContaining({+ widgets: ['review-hub', 'death-clock'],+ reordered: true,+ }));+ });+it('nets out a move up followed by a move back down', async () => {const { onSave } = await renderEditor();moveUp(1);@@ -133,8 +162,8 @@ describe('LayoutEditor reorder signal', () => {it('carries the reorder signal through "Save as new…"', async () => {const { onDuplicate } = await renderEditor();moveUp(2);- clickButton(/Save as new/);- await settle(() => clickButton(/^Create$/));+ clickButton(/^Save as new/);+ await settle(() => clickButton('Create'));expect(onDuplicate).toHaveBeenCalledWith(expect.objectContaining({widgets: ['quick-task', 'backup', 'apps'],reordered: true,