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.d.cts
CHANGED
|
@@ -44,6 +44,7 @@ type RealtimeDocumentSnapshot = {
|
|
|
44
44
|
readonly items: VectorSceneItem[];
|
|
45
45
|
readonly updatedAt: number;
|
|
46
46
|
readonly updatedByClientId?: string;
|
|
47
|
+
readonly persistedRevision?: number;
|
|
47
48
|
};
|
|
48
49
|
type RealtimeConnectionInfo = {
|
|
49
50
|
readonly state: RealtimeConnectionState;
|
package/dist/realtime.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ type RealtimeDocumentSnapshot = {
|
|
|
44
44
|
readonly items: VectorSceneItem[];
|
|
45
45
|
readonly updatedAt: number;
|
|
46
46
|
readonly updatedByClientId?: string;
|
|
47
|
+
readonly persistedRevision?: number;
|
|
47
48
|
};
|
|
48
49
|
type RealtimeConnectionInfo = {
|
|
49
50
|
readonly state: RealtimeConnectionState;
|
package/dist/realtime.js
CHANGED
|
@@ -503,7 +503,8 @@ function parseDocumentSnapshot(value) {
|
|
|
503
503
|
revision,
|
|
504
504
|
updatedAt,
|
|
505
505
|
items,
|
|
506
|
-
...getString(value.updatedByClientId) ? { updatedByClientId: getString(value.updatedByClientId) } : {}
|
|
506
|
+
...getString(value.updatedByClientId) ? { updatedByClientId: getString(value.updatedByClientId) } : {},
|
|
507
|
+
...getNumber(value.persistedRevision) != null ? { persistedRevision: getNumber(value.persistedRevision) } : {}
|
|
507
508
|
};
|
|
508
509
|
}
|
|
509
510
|
function parseRealtimeSessionPeer(value) {
|
|
@@ -2296,6 +2297,9 @@ function sameSerializedItems(left, right) {
|
|
|
2296
2297
|
function nowMs() {
|
|
2297
2298
|
return Date.now();
|
|
2298
2299
|
}
|
|
2300
|
+
function hasDurableDocumentPersistence(snapshot) {
|
|
2301
|
+
return snapshot.persistedRevision == null || snapshot.persistedRevision >= snapshot.revision;
|
|
2302
|
+
}
|
|
2299
2303
|
function draftStorageKey(roomId) {
|
|
2300
2304
|
return `${DRAFT_STORAGE_PREFIX}${roomId}`;
|
|
2301
2305
|
}
|
|
@@ -2521,7 +2525,7 @@ function useRealtimeSession(options) {
|
|
|
2521
2525
|
const applyDocument = useCallback(
|
|
2522
2526
|
(snapshot, options2) => {
|
|
2523
2527
|
const currentSnapshot = latestDocumentRef.current;
|
|
2524
|
-
if (currentSnapshot && currentSnapshot.revision === snapshot.revision && currentSnapshot.updatedByClientId === snapshot.updatedByClientId && sameSerializedItems(currentSnapshot.items, snapshot.items)) {
|
|
2528
|
+
if (currentSnapshot && currentSnapshot.revision === snapshot.revision && currentSnapshot.updatedByClientId === snapshot.updatedByClientId && currentSnapshot.persistedRevision === snapshot.persistedRevision && sameSerializedItems(currentSnapshot.items, snapshot.items)) {
|
|
2525
2529
|
return;
|
|
2526
2530
|
}
|
|
2527
2531
|
const board = boardRef.current;
|
|
@@ -2826,11 +2830,23 @@ function useRealtimeSession(options) {
|
|
|
2826
2830
|
}
|
|
2827
2831
|
const pendingIds = getLocallyPendingItemIds(board);
|
|
2828
2832
|
if (pendingIds.size === 0) {
|
|
2829
|
-
clearLocalDraftRef.current();
|
|
2830
|
-
setHasPendingDocumentSync(false);
|
|
2831
2833
|
outboundInFlightRef.current = null;
|
|
2832
2834
|
queuedDirtyRef.current = false;
|
|
2833
|
-
|
|
2835
|
+
if (hasDurableDocumentPersistence(serverDocument)) {
|
|
2836
|
+
clearLocalDraftRef.current();
|
|
2837
|
+
setHasPendingDocumentSync(false);
|
|
2838
|
+
return false;
|
|
2839
|
+
}
|
|
2840
|
+
const mergedItems2 = readVectorItems(board.yItems);
|
|
2841
|
+
setLocalDraft({
|
|
2842
|
+
roomId,
|
|
2843
|
+
baseRevision: serverDocument.revision,
|
|
2844
|
+
items: mergedItems2,
|
|
2845
|
+
updatedAt: nowMs(),
|
|
2846
|
+
pendingIds: []
|
|
2847
|
+
});
|
|
2848
|
+
setHasPendingDocumentSync(true);
|
|
2849
|
+
return true;
|
|
2834
2850
|
}
|
|
2835
2851
|
const mergedItems = readVectorItems(board.yItems);
|
|
2836
2852
|
setLocalDraft({
|
|
@@ -3178,8 +3194,20 @@ function useRealtimeSession(options) {
|
|
|
3178
3194
|
scheduleDocumentFlushRef.current();
|
|
3179
3195
|
} else {
|
|
3180
3196
|
queuedDirtyRef.current = false;
|
|
3181
|
-
|
|
3182
|
-
|
|
3197
|
+
if (hasDurableDocumentPersistence(parsed.document)) {
|
|
3198
|
+
clearLocalDraftRef.current();
|
|
3199
|
+
setHasPendingDocumentSync(false);
|
|
3200
|
+
} else {
|
|
3201
|
+
const mergedItems = board ? readVectorItems(board.yItems) : [];
|
|
3202
|
+
setLocalDraftRef.current({
|
|
3203
|
+
roomId,
|
|
3204
|
+
baseRevision: currentRevisionRef.current,
|
|
3205
|
+
items: mergedItems,
|
|
3206
|
+
updatedAt: nowMs(),
|
|
3207
|
+
pendingIds: []
|
|
3208
|
+
});
|
|
3209
|
+
setHasPendingDocumentSync(true);
|
|
3210
|
+
}
|
|
3183
3211
|
}
|
|
3184
3212
|
setConflictStateRef.current(null);
|
|
3185
3213
|
return;
|
|
@@ -3646,7 +3674,7 @@ function useRealtimeCanvasDocument(options) {
|
|
|
3646
3674
|
}
|
|
3647
3675
|
return;
|
|
3648
3676
|
}
|
|
3649
|
-
if (
|
|
3677
|
+
if (hasLocalItems && hasMissingLocalItems(items, resolvedItems)) {
|
|
3650
3678
|
const normalizedLocalItems = normalizeItems ? normalizeItems(items) : [...items];
|
|
3651
3679
|
session.remoteAdapter.send?.(normalizedLocalItems);
|
|
3652
3680
|
return;
|