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: rank a move gesture from where the card is drawn, and dedupe migration 269 in file order (#4133)

Adam Eivy30fb281fe2ff
diff --git a/client/src/components/dashboard/DashboardGrid.jsx b/client/src/components/dashboard/DashboardGrid.jsx
index a985cb1517..f4938962bc 100644
--- a/client/src/components/dashboard/DashboardGrid.jsx
+++ b/client/src/components/dashboard/DashboardGrid.jsx
@@ -565,12 +565,22 @@ export default function DashboardGrid({ items, editable, onChange, onLayoutModeC
// it, a cell measuring under MIN_H rows (a widget rendering little or
// nothing) has its height "changed" by the clamp alone — so a purely
// horizontal drag would silently pin it.
- const startItem = kind === 'resize' ? { ...found, h: Math.max(MIN_H, found.h) } : found;
+ //
+ // A move's start is expressed as the rank the cell ALREADY reads at, not
+ // its stored `order`. The two can differ: the pack places in sequence, but
+ // a cell sharing no column with any predecessor lands at the top anyway,
+ // so a later `order` can be DRAWN above an earlier one. Comparing a
+ // pixel-derived rank against a stored one there would "reorder" a card on
+ // a plain click of the handle — a write with nothing behind it.
+ const startTop = baseRects.get(item.id)?.top ?? 0;
+ const startItem = kind === 'resize'
+ ? { ...found, h: Math.max(MIN_H, found.h) }
+ : { ...found, order: rankAtPixel(baseline, baseRects, item.id, startTop, found.x) };
dragRef.current = {
id: item.id,
kind,
startPointer: { x: e.clientX, y: e.clientY },
- startTop: baseRects.get(item.id)?.top ?? 0,
+ startTop,
startItem,
ghost: { ...startItem },
};
diff --git a/client/src/components/dashboard/DashboardGrid.test.jsx b/client/src/components/dashboard/DashboardGrid.test.jsx
index bece22c293..a6879e4db4 100644
--- a/client/src/components/dashboard/DashboardGrid.test.jsx
+++ b/client/src/components/dashboard/DashboardGrid.test.jsx
@@ -461,6 +461,23 @@ describe('DashboardGrid move re-sequences', () => {
dragHandle('Move b', { dy: 4 });
expect(onChange).not.toHaveBeenCalled();
});
+
+ // The pack places in sequence, but a cell sharing no column with anything
+ // before it lands at the top regardless — so `c` (order 2) is DRAWN above
+ // `b` (order 1). A gesture that compared its pixel-derived rank against the
+ // stored order would commit a reorder for a card the user only clicked.
+ it('does not write when a card drawn above its stored order is only clicked', () => {
+ const onChange = renderGrid([
+ { id: 'a', x: 0, w: 6, order: 0, h: 2 },
+ { id: 'b', x: 0, w: 6, order: 1, h: 2 },
+ { id: 'c', x: 6, w: 6, order: 2, h: 2 },
+ ]);
+ expect(cellFor('c').style.top).toBe('0px');
+ expect(cellFor('b').style.top).toBe(`${MEASURED_PX + 16}px`);
+
+ dragHandle('Move c', { dy: 0 });
+ expect(onChange).not.toHaveBeenCalled();
+ });
});
describe('DashboardGrid scroll target', () => {
diff --git a/scripts/migrations/269-dashboard-grid-order.js b/scripts/migrations/269-dashboard-grid-order.js
index 6ddbd3aa67..33f9ca0cac 100644
--- a/scripts/migrations/269-dashboard-grid-order.js
+++ b/scripts/migrations/269-dashboard-grid-order.js
@@ -72,8 +72,18 @@ function applyToLayout(layout) {
if (!layout || typeof layout !== 'object') return false;
if (!Array.isArray(layout.grid) || layout.grid.length === 0) return false;
// A non-object entry is unusable to the renderer either way; drop it here
- // rather than carrying `undefined` ids into the converted shape.
- const grid = layout.grid.filter((g) => g && typeof g === 'object' && typeof g.id === 'string');
+ // rather than carrying `undefined` ids into the converted shape. Duplicates
+ // are dropped keeping the FIRST occurrence in FILE order, which is what the
+ // read path does — deduping after the sort would let conversion hand a
+ // different rectangle to a hand-edited duplicate than the server was
+ // already serving for it.
+ const seen = new Set();
+ const grid = layout.grid.filter((g) => {
+ if (!g || typeof g !== 'object' || typeof g.id !== 'string') return false;
+ if (seen.has(g.id)) return false;
+ seen.add(g.id);
+ return true;
+ });
if (grid.length === layout.grid.length && isConverted(grid)) return false;
layout.grid = toOrderedGrid(grid);
return true;
diff --git a/scripts/migrations/269-dashboard-grid-order.test.js b/scripts/migrations/269-dashboard-grid-order.test.js
index 8cc7263c6b..c982182b7d 100644
--- a/scripts/migrations/269-dashboard-grid-order.test.js
+++ b/scripts/migrations/269-dashboard-grid-order.test.js
@@ -130,6 +130,26 @@ describe('migration 269 — convert dashboard grids to the order-only shape', ()
expect(grid.map((g) => g.order)).toEqual([0, 1, 2]);
});
+ // The read path dedupes by id keeping the first entry in FILE order, so the
+ // conversion has to as well — deduping after the sort would hand the widget
+ // a different rectangle than the server was already serving for it.
+ it('keeps the first duplicate in file order, not the topmost one', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'default',
+ layouts: [{
+ id: 'default', name: 'Everything', builtIn: true, widgets: ['alpha'],
+ grid: [
+ { id: 'alpha', x: 2, y: 10, w: 4, h: 7 },
+ { id: 'alpha', x: 0, y: 0, w: 12, h: 1 },
+ ],
+ }],
+ });
+
+ expect((await migration.up({ rootDir })).updated).toBe(1);
+ expect(readJson(layoutsPath).layouts[0].grid)
+ .toEqual([{ id: 'alpha', x: 2, w: 4, order: 0, h: 7 }]);
+ });
+
it('converts every layout in the file, and leaves empty grids alone', async () => {
writeJson(layoutsPath, {
activeLayoutId: 'focus',