fix(core): preserve data integrity and bound shared UI and response work
Module Package Release / publish-packages (push) Successful in 13s

Release v0.1.46. Coordinated integrity review: GovOPlaN/govoplan-core#298.
This commit is contained in:
2026-09-08 12:30:38 +02:00
parent dc1f244f17
commit 6591aaa3fd
33 changed files with 1889 additions and 114 deletions
+38
View File
@@ -6,9 +6,47 @@ import { renderToStaticMarkup } from "react-dom/server";
import Button from "../src/components/Button";
import DataGrid, { DataGridEmptyAction, DataGridRowActions, type DataGridColumn } from "../src/components/table/DataGrid";
import TableActionGroup, { runTableAction } from "../src/components/table/TableActionGroup";
import { dataGridRowIndices } from "../src/components/table/dataGridRowIndices";
function noop() {}
const repeatedRow = { label: "same" };
const distinctRow = { label: "same" };
const identityRows = [repeatedRow, distinctRow, repeatedRow];
const identityIndex = dataGridRowIndices(identityRows);
assertEqual(identityIndex(repeatedRow), 0, "repeated object references retain their first original index");
assertEqual(identityIndex(distinctRow), 1, "equal-looking objects keep distinct identities");
assertEqual(identityIndex({ label: "same" }), -1, "absent objects retain indexOf semantics");
const primitiveRows = [NaN, -0, 2, 2, 0];
const primitiveIndex = dataGridRowIndices(primitiveRows);
for (const value of primitiveRows) {
assertEqual(primitiveIndex(value), primitiveRows.indexOf(value), "primitive indices preserve NaN, zero and duplicate behavior");
}
let linearVisits = 0;
const measuredRows = Array.from({ length: 4_000 }, (_, index) => ({ index }));
measuredRows.forEach = (callback) => Array.prototype.forEach.call(measuredRows, (row, index, array) => {
linearVisits += 1;
callback(row, index, array);
});
const measuredIndex = dataGridRowIndices(measuredRows);
for (let pass = 0; pass < 10; pass += 1) measuredRows.map(measuredIndex);
assertEqual(linearVisits, 4_000, "index construction traverses once, independent of lookup count");
const callbackIndices: number[] = [];
const stableRows = [{ id: "a", rank: 2 }, { id: "b", rank: 1 }, { id: "c", rank: 1 }];
const stableMarkup = renderToStaticMarkup(<DataGrid
id="stable-original-row-index" rows={stableRows}
columns={[{ id: "rank", header: "Rank", sortValue: (row, index) => {
assertEqual(stableRows[index], row, "sort callbacks receive original indices");
return row.rank;
}, render: (row, index) => { callbackIndices.push(index); return row.id; } }]}
getRowKey={(row, index) => { assertEqual(stableRows[index], row, "row keys receive original indices"); return row.id; }}
initialSort={{ columnId: "rank", direction: "asc" }}
/>);
assertEqual(stableMarkup.includes("stable-original-row-index"), true, "sorted grid renders");
assertEqual(callbackIndices.slice(-3).join(), "1,2,0", "equal sort values remain stable without mutating source order after the unchanged sizing pass");
assertEqual(stableRows.map((row) => row.id).join(), "a,b,c", "sorting never reorders input data");
function buttonCount(markup: string): number {
return markup.match(/<button\b/g)?.length ?? 0;
}