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

fix: re-flow the dashboard grid when LayoutEditor's Move up/down reorders widgets (#4132)

[._.]/ Adam Eivy5d7ee572e88f
diff --git a/.changelog/next/fixed-issue-4132.md b/.changelog/next/fixed-issue-4132.md
new file mode 100644
index 0000000000..fef657aa7b
--- /dev/null
+++ b/.changelog/next/fixed-issue-4132.md
@@ -0,0 +1 @@
+- Dashboard: LayoutEditor's Move up/down buttons now actually reorder widgets on the dashboard — the reorder is re-flowed into the layout's grid, which is what the renderer reads
diff --git a/client/src/components/dashboard/CLAUDE.md b/client/src/components/dashboard/CLAUDE.md
index c5802dcbec..9b3ab55101 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. Note that `reconcileGrid` iterates the *grid* and uses `widgets` only for membership, so LayoutEditor's own Move up/down buttons currently do not move anything once a layout has a grid — tracked in #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` (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).
**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/DashboardGrid.jsx b/client/src/components/dashboard/DashboardGrid.jsx
index e3d43911b5..122d624a6e 100644
--- a/client/src/components/dashboard/DashboardGrid.jsx
+++ b/client/src/components/dashboard/DashboardGrid.jsx
@@ -309,7 +309,15 @@ export function synthesizeGrid(widgetIds) {
// any widgets missing from the grid (auto-placed at the bottom) and drops
// grid entries whose widget is no longer in the layout (gated off, deleted,
// etc.). Keeps the renderer's input always coherent with what should display.
-export function reconcileGrid(grid, visibleIds) {
+//
+// `reorder` makes `visibleIds` authoritative for order as well as membership:
+// the reconciled grid is re-flowed to that order. Only pass it when the caller
+// KNOWS the list order is the edit (LayoutEditor's Move up/down — #4132).
+// Inferring it by comparing `visibleIds` against `readingOrderIds(grid)` would
+// be wrong: layouts arranged before `saveGridEdit` started syncing `widgets` to
+// reading order can already disagree, so a rename or a widget toggle would
+// silently re-pack a carefully arranged desktop layout.
+export function reconcileGrid(grid, visibleIds, { reorder = false } = {}) {
const visible = new Set(visibleIds);
const present = new Set();
let kept = [];
@@ -323,7 +331,7 @@ export function reconcileGrid(grid, visibleIds) {
if (present.has(id)) continue;
kept = placeNewWidget(kept, id);
}
- return kept;
+ return reorder ? reflowToOrder(kept, visibleIds) : kept;
}
// Reading order of a grid — what the mobile stack shows, and what a layout's
diff --git a/client/src/components/dashboard/DashboardGrid.test.jsx b/client/src/components/dashboard/DashboardGrid.test.jsx
index 0ab3f2e389..22f50bd5e0 100644
--- a/client/src/components/dashboard/DashboardGrid.test.jsx
+++ b/client/src/components/dashboard/DashboardGrid.test.jsx
@@ -246,6 +246,31 @@ describe('reconcileGrid', () => {
it('drops hidden widgets and appends newly visible ones', () => {
expect(reconcileGrid(THREE, ['a', 'c']).map((it) => it.id)).toEqual(['a', 'c']);
});
+
+ // The arranged layout below deliberately disagrees with its widget list: `b`
+ // sits above `a` in the grid while the list still says `['a','b','c']`, which
+ // is exactly the pre-`saveGridEdit` state #4132 warns about.
+ const ARRANGED = [
+ { id: 'b', x: 0, y: 0, w: 6, h: 3 },
+ { id: 'a', x: 6, y: 0, w: 6, h: 2 },
+ { id: 'c', x: 0, y: 3, w: 12, h: 2 },
+ ];
+
+ it('leaves an arranged grid alone when the save is not a reorder', () => {
+ expect(reconcileGrid(ARRANGED, ['a', 'b', 'c'])).toEqual(ARRANGED);
+ expect(reconcileGrid(ARRANGED, ['a', 'b', 'c'], { reorder: false })).toEqual(ARRANGED);
+ });
+
+ it('re-flows to the widget order when the caller says the save IS a reorder', () => {
+ const next = reconcileGrid(THREE, ['b', 'a', 'c'], { reorder: true });
+ expect(readingOrderIds(next)).toEqual(['b', 'a', 'c']);
+ expect(next.map((it) => it.h)).toEqual([2, 2, 2]);
+ });
+
+ it('re-flows a widget added in the same reorder save', () => {
+ const next = reconcileGrid(THREE, ['c', 'a', 'apps', 'b'], { reorder: true });
+ expect(readingOrderIds(next)).toEqual(['c', 'a', 'apps', 'b']);
+ });
});
describe('DashboardGrid mobile reorder', () => {
diff --git a/client/src/components/dashboard/LayoutEditor.jsx b/client/src/components/dashboard/LayoutEditor.jsx
index ab5933f9f6..7a21493145 100644
--- a/client/src/components/dashboard/LayoutEditor.jsx
+++ b/client/src/components/dashboard/LayoutEditor.jsx
@@ -105,6 +105,21 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,
setDirty(true);
};
+ // 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". `add` appends and `remove` filters, both of
+ // which preserve relative order, so comparing the two lists restricted to the
+ // widgets they share isolates exactly what `move` did.
+ const isReordered = () => {
+ const stored = editing?.widgets ?? [];
+ const storedIds = new Set(stored);
+ const draftIds = new Set(widgets);
+ const shared = stored.filter((id) => draftIds.has(id));
+ return widgets.filter((id) => storedIds.has(id)).some((id, i) => id !== shared[i]);
+ };
+
const remove = (id) => {
setWidgets((prev) => prev.filter((w) => w !== id));
setDirty(true);
@@ -133,7 +148,7 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,
toast.error('Time window: start and end must be HH:MM and differ');
return;
}
- const ok = await onSave({ id: editingId, name: trimmed, widgets, activateWindow }).then(() => true, () => false);
+ const ok = await onSave({ id: editingId, name: trimmed, widgets, activateWindow, reordered: isReordered() }).then(() => true, () => false);
if (!ok) return;
setDirty(false);
toast.success('Layout saved');
@@ -170,7 +185,7 @@ export default function LayoutEditor({ layouts, activeLayoutId, limits, onClose,
let id = fitId(n);
while (existingIds.has(id)) { n += 1; id = fitId(n); }
// Duplicate inherits the source's activateWindow — easier to clear post-duplicate than to re-enter.
- const ok = await onDuplicate({ id, name: trimmed, widgets, activateWindow }).then(() => true, () => false);
+ const ok = await onDuplicate({ id, name: trimmed, widgets, activateWindow, reordered: isReordered() }).then(() => true, () => false);
if (!ok) return;
// The duplicate IS saved — clear dirty so the rehydrate effect runs
// when the new layout lands in `layouts` props; otherwise the editor
diff --git a/client/src/components/dashboard/LayoutEditor.test.jsx b/client/src/components/dashboard/LayoutEditor.test.jsx
new file mode 100644
index 0000000000..e49050671f
--- /dev/null
+++ b/client/src/components/dashboard/LayoutEditor.test.jsx
@@ -0,0 +1,130 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { act, fireEvent, render, screen, within } from '@testing-library/react';
+
+vi.mock('../ui/Toast', () => ({
+ default: { success: vi.fn(), error: vi.fn(), info: vi.fn() },
+}));
+
+import LayoutEditor from './LayoutEditor.jsx';
+
+// Registered widget ids so the editor renders real labels rather than the
+// "(unknown — skipped)" fallback.
+const WIDGET_IDS = ['quick-task', 'apps', 'backup'];
+
+const LAYOUT = {
+ id: 'demo',
+ name: 'Demo',
+ widgets: WIDGET_IDS,
+ grid: [
+ { id: 'quick-task', x: 0, y: 0, w: 6, h: 5 },
+ { id: 'apps', x: 6, y: 0, w: 6, h: 5 },
+ { id: 'backup', x: 0, y: 5, w: 12, h: 5 },
+ ],
+};
+
+async function renderEditor() {
+ const onSave = vi.fn().mockResolvedValue(undefined);
+ const onDuplicate = vi.fn().mockResolvedValue(undefined);
+ render(
+ <LayoutEditor
+ layouts={[LAYOUT]}
+ activeLayoutId={LAYOUT.id}
+ limits={null}
+ onClose={vi.fn()}
+ onSave={onSave}
+ onDelete={vi.fn()}
+ onDuplicate={onDuplicate}
+ />
+ );
+ await act(async () => {});
+ return { onSave, onDuplicate };
+}
+
+// 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 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
+// post-save state updates it schedules land inside act as well.
+const settle = async (fire) => {
+ await act(async () => { fire(); });
+ await act(async () => {});
+};
+const save = () => settle(() => clickButton(/^Save$/));
+
+describe('LayoutEditor reorder signal', () => {
+ beforeEach(() => { vi.clearAllMocks(); });
+
+ it('moves a widget up in the list and flags the save as a reorder', async () => {
+ const { onSave } = await renderEditor();
+ moveUp(1);
+
+ expect(widgetRows().map((li) => li.textContent)).toEqual([
+ 'Apps Grid', 'Quick Task', 'Backup',
+ ]);
+
+ await save();
+ expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
+ id: 'demo',
+ widgets: ['apps', 'quick-task', 'backup'],
+ reordered: true,
+ }));
+ });
+
+ it('flags a Move down the same way', async () => {
+ const { onSave } = await renderEditor();
+ moveDown(0);
+ await save();
+ expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
+ widgets: ['apps', 'quick-task', 'backup'],
+ reordered: true,
+ }));
+ });
+
+ // The whole point of the explicit signal: an unrelated save must leave the
+ // stored grid coordinates alone (#4132).
+ it('does not flag a rename as a reorder', async () => {
+ const { onSave } = await renderEditor();
+ fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Renamed' } });
+ await save();
+ expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
+ name: 'Renamed',
+ widgets: WIDGET_IDS,
+ reordered: false,
+ }));
+ });
+
+ 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/);
+ await save();
+ expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
+ widgets: ['quick-task', 'backup', 'death-clock'],
+ reordered: false,
+ }));
+ });
+
+ it('nets out a move up followed by a move back down', async () => {
+ const { onSave } = await renderEditor();
+ moveUp(1);
+ moveDown(0);
+ await save();
+ expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
+ widgets: WIDGET_IDS,
+ reordered: false,
+ }));
+ });
+
+ it('carries the reorder signal through "Save as new…"', async () => {
+ const { onDuplicate } = await renderEditor();
+ moveUp(2);
+ clickButton(/Save as new/);
+ await settle(() => clickButton(/^Create$/));
+ expect(onDuplicate).toHaveBeenCalledWith(expect.objectContaining({
+ widgets: ['quick-task', 'backup', 'apps'],
+ reordered: true,
+ }));
+ });
+});
diff --git a/client/src/pages/Dashboard.jsx b/client/src/pages/Dashboard.jsx
index 08dac0eb8c..e23a4706f8 100644
--- a/client/src/pages/Dashboard.jsx
+++ b/client/src/pages/Dashboard.jsx
@@ -328,21 +328,26 @@ export default function Dashboard() {
// don't get wiped when the user toggles a widget in the LayoutEditor.
// reconcileGrid drops removed widgets and appends any new ones at the
// bottom, mirroring what the renderer does at view time.
- const saveLayout = async ({ id, name, widgets, activateWindow }) => {
+ //
+ // The renderer reads the grid, not `widgets` — so a Move up/down in the
+ // editor is invisible unless the grid is re-flowed to the new order. The
+ // editor tells us when that's what the save is (`reordered`) rather than us
+ // inferring it from the two orders disagreeing; see reconcileGrid (#4132).
+ const saveLayout = async ({ id, name, widgets, activateWindow, reordered }) => {
const existing = layouts.find((l) => l.id === id);
const baseGrid = (existing?.grid && existing.grid.length > 0)
? existing.grid
: synthesizeGrid(existing?.widgets ?? widgets);
- const nextGrid = reconcileGrid(baseGrid, widgets);
+ const nextGrid = reconcileGrid(baseGrid, widgets, { reorder: reordered });
const result = await api.saveDashboardLayout(id, { name, widgets, grid: nextGrid, activateWindow });
setLayouts(result.layouts);
};
- const duplicateLayout = async ({ id, name, widgets, activateWindow }) => {
+ const duplicateLayout = async ({ id, name, widgets, activateWindow, reordered }) => {
// New layouts inherit the current renderGrid so "Save as new…" from a
// visually-arranged dashboard captures what the user actually sees.
const sourceGrid = renderGrid && renderGrid.length > 0 ? renderGrid : synthesizeGrid(widgets);
- const grid = reconcileGrid(sourceGrid, widgets);
+ const grid = reconcileGrid(sourceGrid, widgets, { reorder: reordered });
const result = await api.saveDashboardLayout(id, { name, widgets, grid, activateWindow });
setLayouts(result.layouts);
// Bump the switch generation only now — AFTER the save resolved and right