Testing concurrent remote updates (wip)

This commit is contained in:
Marcel Mraz 2025-01-22 22:16:33 +01:00
parent 7e0f5b6369
commit cdd7f6158b
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
3 changed files with 17 additions and 4 deletions

View file

@ -17,6 +17,7 @@ import type { ExcalidrawElement, SceneElementsMap } from "../element/types";
import type { CLIENT_MESSAGE_RAW, SERVER_DELTA, CHANGE } from "./protocol";
import { debounce } from "../utils";
import { randomId } from "../random";
import { orderByFractionalIndex } from "../fractionalIndex";
class SocketMessage implements CLIENT_MESSAGE_RAW {
constructor(
@ -388,13 +389,18 @@ export class SyncClient {
!existingElement || // new element
existingElement.version < relayedElement.version // updated element
) {
// CFDO: in theory could make the yet unsynced element (due to a bug) to move to the top
nextElements.set(id, relayedElement);
this.relayedElementsVersionsCache.set(id, relayedElement.version);
}
}
const orderedElements = orderByFractionalIndex(
Array.from(nextElements.values()),
);
this.api.updateScene({
elements: Array.from(nextElements.values()),
elements: orderedElements,
storeAction: StoreAction.UPDATE,
});
} catch (e) {
@ -468,9 +474,13 @@ export class SyncClient {
prevSnapshot = this.api.store.snapshot;
}
const orderedElements = orderByFractionalIndex(
Array.from(nextElements.values()),
);
// CFDO: might need to restore first due to potentially stale delta versions
this.api.updateScene({
elements: Array.from(nextElements.values()),
elements: orderedElements,
// even though the snapshot should be up-to-date already,
// still some more updates might be triggered,
// i.e. as a result from syncing invalid indices