Skip to content

Commit a647e46

Browse files
committed
fix(data): rekey send queue on server ID assignment and reject gates on retire
Bug 1: assignId rewrites entityId on pending operations but the per-entity send queue stayed keyed by the local operation UUID. After confirm, later edits using the server ID found no queue entry and dispatched immediately, racing with writes still queued behind the create gate. Fix: move the queue entry from the old key to the new key in assignId. Bug 2: retire() cleared operations and queues but never rejected create gates. Writes waiting on a gate promise hung forever since settle is also forbidden on a retired store. Fix: reject all pending gates with DataRetiredError before clearing.
1 parent b75eabf commit a647e46

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎packages/octane/src/data/store.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,17 @@ export function createDataStore(options: DataStoreOptions): DataStore {
509509
item.raw = rename(item.raw);
510510
item.draft = rename(item.draft);
511511
}
512+
const oldKey = `${entity.name}\n${local}`;
513+
const pending = queues.get(oldKey);
514+
if (pending !== undefined) {
515+
const newKey = `${entity.name}\n${serverId}`;
516+
queues.delete(oldKey);
517+
queues.set(newKey, pending);
518+
const release = () => {
519+
if (queues.get(newKey) === pending) queues.delete(newKey);
520+
};
521+
pending.then(release, release);
522+
}
512523
}
513524

514525
/** A confirmed write refreshes the reads it returned and marks the rest it affects stale. */
@@ -744,7 +755,10 @@ export function createDataStore(options: DataStoreOptions): DataStore {
744755
retire() {
745756
if (retired) return;
746757
retired = true;
758+
const pending = operations;
747759
operations = [];
760+
const retiredError = new DataRetiredError();
761+
for (const op of pending) op.gate?.reject(retiredError);
748762
queues.clear();
749763
seeds.clear();
750764
for (const entry of entries.values()) {

0 commit comments

Comments
 (0)