Stable 0.5.12 still loses distinct rows on hash collisions; fixed in 1.0 RC #2324
Affected published versions#
The highest published non-prerelease version @tanstack/react-db@0.5.12 (with @tanstack/db@0.15.2) still loses a distinct row in the reproduction below. 1.0.0-rc.1 is also affected. The same reproduction passes on 1.0.0-rc.1.1.
Reproduction#
In an empty directory run npm install @tanstack/react-db@0.5.12, save this as repro.mjs, and run node repro.mjs. Setting Math.random before the dynamic import makes the hash-collision case deterministic.
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((n) => !actual.has(n)) }));
retain.unsubscribe();
await query.cleanup();
await collection.cleanup();
Actual output on 0.5.12 and 1.0.0-rc.1:
{"expected":2,"actual":1,"missing":[51277]}
Expected output, also observed on 1.0.0-rc.1.1:
{"expected":2,"actual":2,"missing":[]}
Impact#
Two distinct selected objects should both remain in the query result. A hash collision currently drops a row in the published stable line, making the query result incomplete.
Related closed report and released fix#
#2306 is closed, and #2309 fixes the reproduction in the 1.0 release candidate. This is a follow-up for the continuing failure in the published stable line; it does not claim that 1.0.0-rc.1.1 is broken. Is a stable release containing the collision fix planned, or is adopting the 1.0 release candidate the supported upgrade path?
KyleAMathews closed this
Sign in to join this conversation.
Yeah we're not going to backport anything.