canvu-react 0.4.1 → 0.4.3

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.js CHANGED
@@ -2482,6 +2482,17 @@ function useRealtimeSession(options) {
2482
2482
  }
2483
2483
  const board = boardRef.current;
2484
2484
  if (board) {
2485
+ if (!options2?.replace) {
2486
+ const pendingLocal = pendingLocalItemsRef.current;
2487
+ if (pendingLocal) {
2488
+ pendingLocalItemsRef.current = null;
2489
+ applyLocalItemsToYDoc(board, {
2490
+ items: pendingLocal,
2491
+ origin: ORIGIN_LOCAL
2492
+ });
2493
+ queuedDirtyRef.current = true;
2494
+ }
2495
+ }
2485
2496
  if (options2?.replace) {
2486
2497
  replaceYDocWithSnapshot(board, {
2487
2498
  items: snapshot.items,
@@ -2530,7 +2541,10 @@ function useRealtimeSession(options) {
2530
2541
  removeRealtimeOfflineDraft(roomId);
2531
2542
  return;
2532
2543
  }
2533
- writeRealtimeOfflineDraft(localDraftRef.current);
2544
+ const board = boardRef.current;
2545
+ const draft = localDraftRef.current;
2546
+ const draftToWrite = board && draft.yDocState == null ? { ...draft, yDocState: encodeYDocState(board) } : draft;
2547
+ writeRealtimeOfflineDraft(draftToWrite);
2534
2548
  }, [clearDraftPersistSchedule, roomId]);
2535
2549
  const scheduleDraftPersistence = useCallback(() => {
2536
2550
  clearDraftPersistSchedule();
@@ -2649,7 +2663,6 @@ function useRealtimeSession(options) {
2649
2663
  baseRevision,
2650
2664
  items: mergedItems,
2651
2665
  updatedAt: nowMs(),
2652
- yDocState: encodeYDocState(board),
2653
2666
  pendingIds: Array.from(pendingIds)
2654
2667
  });
2655
2668
  scheduleDraftPersistenceRef.current?.();
@@ -2757,7 +2770,6 @@ function useRealtimeSession(options) {
2757
2770
  baseRevision: serverDocument.revision,
2758
2771
  items: mergedItems,
2759
2772
  updatedAt: nowMs(),
2760
- yDocState: encodeYDocState(board),
2761
2773
  pendingIds: Array.from(pendingIds)
2762
2774
  });
2763
2775
  outboundInFlightRef.current = null;
@@ -3072,7 +3084,6 @@ function useRealtimeSession(options) {
3072
3084
  baseRevision: currentRevisionRef.current,
3073
3085
  items: mergedItems,
3074
3086
  updatedAt: nowMs(),
3075
- yDocState: board ? encodeYDocState(board) : void 0,
3076
3087
  pendingIds: board ? Array.from(getLocallyPendingItemIds(board)) : void 0
3077
3088
  });
3078
3089
  queuedDirtyRef.current = true;
@@ -3188,7 +3199,6 @@ function useRealtimeSession(options) {
3188
3199
  baseRevision: currentRevisionRef.current,
3189
3200
  items: mergedItems,
3190
3201
  updatedAt: nowMs(),
3191
- yDocState: encodeYDocState(board),
3192
3202
  pendingIds: Array.from(pendingIds)
3193
3203
  });
3194
3204
  }