Non-prerelease 0.5.12 loses unequal selected rows on distinct hash collisions #2325
Problem#
@tanstack/react-db 0.5.12 (@tanstack/db 0.15.2), still the latest stable line as checked 2026-11-01, can drop one of two unequal selected rows when their structural hashes collide in distinct(). The npm latest tag points to @tanstack/react-db 1.0.0-rc.1.1, where this case passes; 0.5.12 is the highest published non-prerelease version.
This is a new report after #2324 was closed. I understand the maintainer response that the fix will not be backported. This report is limited to the continuing failure in the stable package; it does not claim that the 1.0 release candidate remains affected. Please clarify whether 0.5.x is unsupported for correctness fixes or whether consumers should move to the prerelease to avoid silent row loss.
Reproduce#
In an empty directory, run npm install @tanstack/react-db@0.5.12. Save the following as repro.mjs and run node repro.mjs:
Math.random = () => 0.5;
const { createCollection, createLiveQueryCollection } = await import('@tanstack/react-db');
let sync;
const collection = createCollection({
id: 'collision-repro',
getKey: (row) => row.id,
startSync: true,
sync: { sync(callbacks) { sync = callbacks; callbacks.markReady(); } },
});
const query = createLiveQueryCollection({
query: (q) => q.from({ row: collection })
.select(({ row }) => ({ id: row.id, value: row.value }))
.distinct(),
startSync: true,
});
const retain = query.subscribeChanges(() => {});
sync.begin();
for (const value of [51277, 90754]) {
sync.write({ type: 'insert', value: { id: `item-${value}`, value } });
}
sync.commit();
const actual = new Set(query.toArray.map(({ value }) => value));
console.log(JSON.stringify({
expected: 2,
actual: actual.size,
missing: [51277, 90754].filter((value) => !actual.has(value)),
}));
retain.unsubscribe();
await query.cleanup();
await collection.cleanup();
Actual / expected#
On 0.5.12, actual output is {"expected":2,"actual":1,"missing":[51277]}. Expected output is {"expected":2,"actual":2,"missing":[]}. The expected output was observed on 1.0.0-rc.1.1.
Impact#
Distinct should remove duplicate selected values without merging unequal rows. On the affected stable release, a collision makes query results incomplete.
Evidence and exposure#
This is a deterministic package-level reproduction, not a report of a production incident. It fixes the process-local hash seed and inserts two unequal rows whose hashes collide; both are emitted on 1.0.0-rc.1.1, while one is lost on stable 0.5.12.
TkDodo closed this
Sign in to join this conversation.