canvu-react 0.4.10 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/realtime.cjs +36 -8
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +1 -0
- package/dist/realtime.d.ts +1 -0
- package/dist/realtime.js +36 -8
- package/dist/realtime.js.map +1 -1
- package/package.json +1 -1
package/dist/realtime.cjs
CHANGED
|
@@ -528,7 +528,8 @@ function parseDocumentSnapshot(value) {
|
|
|
528
528
|
revision,
|
|
529
529
|
updatedAt,
|
|
530
530
|
items,
|
|
531
|
-
...getString(value.updatedByClientId) ? { updatedByClientId: getString(value.updatedByClientId) } : {}
|
|
531
|
+
...getString(value.updatedByClientId) ? { updatedByClientId: getString(value.updatedByClientId) } : {},
|
|
532
|
+
...getNumber(value.persistedRevision) != null ? { persistedRevision: getNumber(value.persistedRevision) } : {}
|
|
532
533
|
};
|
|
533
534
|
}
|
|
534
535
|
function parseRealtimeSessionPeer(value) {
|
|
@@ -2321,6 +2322,9 @@ function sameSerializedItems(left, right) {
|
|
|
2321
2322
|
function nowMs() {
|
|
2322
2323
|
return Date.now();
|
|
2323
2324
|
}
|
|
2325
|
+
function hasDurableDocumentPersistence(snapshot) {
|
|
2326
|
+
return snapshot.persistedRevision == null || snapshot.persistedRevision >= snapshot.revision;
|
|
2327
|
+
}
|
|
2324
2328
|
function draftStorageKey(roomId) {
|
|
2325
2329
|
return `${DRAFT_STORAGE_PREFIX}${roomId}`;
|
|
2326
2330
|
}
|
|
@@ -2546,7 +2550,7 @@ function useRealtimeSession(options) {
|
|
|
2546
2550
|
const applyDocument = react.useCallback(
|
|
2547
2551
|
(snapshot, options2) => {
|
|
2548
2552
|
const currentSnapshot = latestDocumentRef.current;
|
|
2549
|
-
if (currentSnapshot && currentSnapshot.revision === snapshot.revision && currentSnapshot.updatedByClientId === snapshot.updatedByClientId && sameSerializedItems(currentSnapshot.items, snapshot.items)) {
|
|
2553
|
+
if (currentSnapshot && currentSnapshot.revision === snapshot.revision && currentSnapshot.updatedByClientId === snapshot.updatedByClientId && currentSnapshot.persistedRevision === snapshot.persistedRevision && sameSerializedItems(currentSnapshot.items, snapshot.items)) {
|
|
2550
2554
|
return;
|
|
2551
2555
|
}
|
|
2552
2556
|
const board = boardRef.current;
|
|
@@ -2851,11 +2855,23 @@ function useRealtimeSession(options) {
|
|
|
2851
2855
|
}
|
|
2852
2856
|
const pendingIds = getLocallyPendingItemIds(board);
|
|
2853
2857
|
if (pendingIds.size === 0) {
|
|
2854
|
-
clearLocalDraftRef.current();
|
|
2855
|
-
setHasPendingDocumentSync(false);
|
|
2856
2858
|
outboundInFlightRef.current = null;
|
|
2857
2859
|
queuedDirtyRef.current = false;
|
|
2858
|
-
|
|
2860
|
+
if (hasDurableDocumentPersistence(serverDocument)) {
|
|
2861
|
+
clearLocalDraftRef.current();
|
|
2862
|
+
setHasPendingDocumentSync(false);
|
|
2863
|
+
return false;
|
|
2864
|
+
}
|
|
2865
|
+
const mergedItems2 = readVectorItems(board.yItems);
|
|
2866
|
+
setLocalDraft({
|
|
2867
|
+
roomId,
|
|
2868
|
+
baseRevision: serverDocument.revision,
|
|
2869
|
+
items: mergedItems2,
|
|
2870
|
+
updatedAt: nowMs(),
|
|
2871
|
+
pendingIds: []
|
|
2872
|
+
});
|
|
2873
|
+
setHasPendingDocumentSync(true);
|
|
2874
|
+
return true;
|
|
2859
2875
|
}
|
|
2860
2876
|
const mergedItems = readVectorItems(board.yItems);
|
|
2861
2877
|
setLocalDraft({
|
|
@@ -3203,8 +3219,20 @@ function useRealtimeSession(options) {
|
|
|
3203
3219
|
scheduleDocumentFlushRef.current();
|
|
3204
3220
|
} else {
|
|
3205
3221
|
queuedDirtyRef.current = false;
|
|
3206
|
-
|
|
3207
|
-
|
|
3222
|
+
if (hasDurableDocumentPersistence(parsed.document)) {
|
|
3223
|
+
clearLocalDraftRef.current();
|
|
3224
|
+
setHasPendingDocumentSync(false);
|
|
3225
|
+
} else {
|
|
3226
|
+
const mergedItems = board ? readVectorItems(board.yItems) : [];
|
|
3227
|
+
setLocalDraftRef.current({
|
|
3228
|
+
roomId,
|
|
3229
|
+
baseRevision: currentRevisionRef.current,
|
|
3230
|
+
items: mergedItems,
|
|
3231
|
+
updatedAt: nowMs(),
|
|
3232
|
+
pendingIds: []
|
|
3233
|
+
});
|
|
3234
|
+
setHasPendingDocumentSync(true);
|
|
3235
|
+
}
|
|
3208
3236
|
}
|
|
3209
3237
|
setConflictStateRef.current(null);
|
|
3210
3238
|
return;
|
|
@@ -3671,7 +3699,7 @@ function useRealtimeCanvasDocument(options) {
|
|
|
3671
3699
|
}
|
|
3672
3700
|
return;
|
|
3673
3701
|
}
|
|
3674
|
-
if (
|
|
3702
|
+
if (hasLocalItems && hasMissingLocalItems(items, resolvedItems)) {
|
|
3675
3703
|
const normalizedLocalItems = normalizeItems ? normalizeItems(items) : [...items];
|
|
3676
3704
|
session.remoteAdapter.send?.(normalizedLocalItems);
|
|
3677
3705
|
return;
|