@liveblocks/react 1.9.3 → 1.9.5

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/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { detectDupes } from "@liveblocks/core";
5
5
 
6
6
  // src/version.ts
7
7
  var PKG_NAME = "@liveblocks/react";
8
- var PKG_VERSION = "1.9.3";
8
+ var PKG_VERSION = "1.9.5";
9
9
  var PKG_FORMAT = "esm";
10
10
 
11
11
  // src/ClientSideSuspense.tsx
@@ -36,11 +36,12 @@ import { CommentsApiError, makeEventSource, stringify } from "@liveblocks/core";
36
36
  import { nanoid } from "nanoid";
37
37
  import React2, {
38
38
  createContext,
39
- useCallback as useCallback2,
39
+ useCallback as useCallback3,
40
40
  useContext,
41
41
  useEffect as useEffect3,
42
42
  useMemo
43
43
  } from "react";
44
+ import { useSyncExternalStore as useSyncExternalStore3 } from "use-sync-external-store/shim";
44
45
  import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
45
46
 
46
47
  // src/comments/errors.ts
@@ -102,19 +103,66 @@ var RemoveReactionError = class extends Error {
102
103
  };
103
104
 
104
105
  // src/comments/lib/revalidation.ts
105
- import { useCallback, useEffect as useEffect2, useRef } from "react";
106
+ import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2 } from "react";
107
+
108
+ // src/comments/lib/use-is-document-visible.ts
109
+ import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
110
+ function useIsDocumentVisible() {
111
+ const isVisible = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
112
+ return isVisible;
113
+ }
114
+ function subscribe(onStoreChange) {
115
+ document.addEventListener("visibilitychange", onStoreChange);
116
+ return () => {
117
+ document.removeEventListener("visibilitychange", onStoreChange);
118
+ };
119
+ }
120
+ function getSnapshot() {
121
+ const isDocumentDefined = typeof document !== "undefined";
122
+ return isDocumentDefined ? document.visibilityState === "visible" : true;
123
+ }
124
+
125
+ // src/comments/lib/use-is-online.ts
126
+ import { useCallback, useRef } from "react";
127
+ import { useSyncExternalStore as useSyncExternalStore2 } from "use-sync-external-store/shim/index.js";
128
+ function useIsOnline() {
129
+ const isOnlineRef = useRef(true);
130
+ const subscribe2 = useCallback((onStoreChange) => {
131
+ function handleIsOnline() {
132
+ isOnlineRef.current = true;
133
+ onStoreChange();
134
+ }
135
+ function handleIsOffline() {
136
+ isOnlineRef.current = false;
137
+ onStoreChange();
138
+ }
139
+ window.addEventListener("online", handleIsOnline);
140
+ window.addEventListener("offline", handleIsOffline);
141
+ return () => {
142
+ window.removeEventListener("online", handleIsOnline);
143
+ window.removeEventListener("offline", handleIsOffline);
144
+ };
145
+ }, []);
146
+ const getSnapshot2 = useCallback(() => {
147
+ return isOnlineRef.current;
148
+ }, []);
149
+ const isOnline = useSyncExternalStore2(subscribe2, getSnapshot2, getSnapshot2);
150
+ return isOnline;
151
+ }
152
+
153
+ // src/comments/lib/revalidation.ts
106
154
  var DEFAULT_ERROR_RETRY_INTERVAL = 5e3;
107
155
  var DEFAULT_MAX_ERROR_RETRY_COUNT = 5;
108
156
  var DEFAULT_DEDUPING_INTERVAL = 2e3;
109
157
  var timestamp = 0;
110
158
  function useRevalidateCache(manager, fetcher, options = {}) {
111
- const isOnlineRef = useRef(true);
159
+ const isOnlineRef = useRef2(true);
112
160
  const {
113
161
  dedupingInterval = DEFAULT_DEDUPING_INTERVAL,
114
162
  errorRetryInterval = DEFAULT_ERROR_RETRY_INTERVAL,
115
163
  errorRetryCount = DEFAULT_MAX_ERROR_RETRY_COUNT
116
164
  } = options;
117
- const _revalidateCache = useCallback(
165
+ const _revalidateCache = useCallback2(
118
166
  async ({
119
167
  shouldDedupe,
120
168
  retryCount = 0
@@ -189,7 +237,7 @@ function useRevalidateCache(manager, fetcher, options = {}) {
189
237
  window.removeEventListener("offline", handleIsOffline);
190
238
  };
191
239
  }, []);
192
- const revalidateCache = useCallback(
240
+ const revalidateCache = useCallback2(
193
241
  ({ shouldDedupe }) => {
194
242
  return _revalidateCache({ shouldDedupe, retryCount: 0 });
195
243
  },
@@ -198,7 +246,7 @@ function useRevalidateCache(manager, fetcher, options = {}) {
198
246
  return revalidateCache;
199
247
  }
200
248
  function useMutate(manager, revalidateCache) {
201
- const mutate = useCallback(
249
+ const mutate = useCallback2(
202
250
  async (data, options) => {
203
251
  const beforeMutationTimestamp = ++timestamp;
204
252
  manager.setMutation({
@@ -239,6 +287,8 @@ function useMutate(manager, revalidateCache) {
239
287
  // src/comments/CommentsRoom.tsx
240
288
  var THREAD_ID_PREFIX = "th";
241
289
  var COMMENT_ID_PREFIX = "cm";
290
+ var POLLING_INTERVAL_REALTIME = 3e4;
291
+ var POLLING_INTERVAL = 5e3;
242
292
  function createCommentsRoom(errorEventSource) {
243
293
  const store = createClientCacheStore();
244
294
  const FetcherContext = createContext(null);
@@ -275,6 +325,70 @@ function createCommentsRoom(errorEventSource) {
275
325
  return threads;
276
326
  }, [room, manager]);
277
327
  const revalidateCache = useRevalidateCache(manager, fetcher);
328
+ const status = useSyncExternalStore3(
329
+ room.events.status.subscribe,
330
+ room.getStatus,
331
+ room.getStatus
332
+ );
333
+ const isOnline = useIsOnline();
334
+ const isDocumentVisible = useIsDocumentVisible();
335
+ const refreshInterval = getPollingInterval(
336
+ isOnline,
337
+ isDocumentVisible,
338
+ status === "connected"
339
+ );
340
+ useEffect3(() => {
341
+ let revalidationTimerId;
342
+ function scheduleRevalidation() {
343
+ if (refreshInterval === 0)
344
+ return;
345
+ revalidationTimerId = window.setTimeout(() => {
346
+ if (isOnline && isDocumentVisible && !manager.getError() && manager.getTotalReferenceCount() > 0) {
347
+ void revalidateCache({ shouldDedupe: true }).then(
348
+ scheduleRevalidation
349
+ );
350
+ return;
351
+ }
352
+ scheduleRevalidation();
353
+ }, refreshInterval);
354
+ }
355
+ scheduleRevalidation();
356
+ return () => {
357
+ window.clearTimeout(revalidationTimerId);
358
+ };
359
+ }, [
360
+ revalidateCache,
361
+ refreshInterval,
362
+ isOnline,
363
+ isDocumentVisible,
364
+ manager
365
+ ]);
366
+ useEffect3(() => {
367
+ function handleIsOnline() {
368
+ if (isDocumentVisible) {
369
+ void revalidateCache({ shouldDedupe: true });
370
+ }
371
+ }
372
+ window.addEventListener("online", handleIsOnline);
373
+ return () => {
374
+ window.removeEventListener("online", handleIsOnline);
375
+ };
376
+ }, [revalidateCache, isDocumentVisible]);
377
+ useEffect3(() => {
378
+ function handleVisibilityChange() {
379
+ const isVisible = document.visibilityState === "visible";
380
+ if (isVisible && isOnline) {
381
+ void revalidateCache({ shouldDedupe: true });
382
+ }
383
+ }
384
+ document.addEventListener("visibilitychange", handleVisibilityChange);
385
+ return () => {
386
+ document.removeEventListener(
387
+ "visibilitychange",
388
+ handleVisibilityChange
389
+ );
390
+ };
391
+ }, [revalidateCache, isOnline]);
278
392
  useEffect3(() => {
279
393
  const unsubscribe = room.events.comments.subscribe(() => {
280
394
  void revalidateCache({ shouldDedupe: false });
@@ -338,38 +452,9 @@ function createCommentsRoom(errorEventSource) {
338
452
  return () => {
339
453
  manager.decrementReferenceCount(key);
340
454
  };
341
- });
342
- return useSyncExternalStoreWithSelector(
343
- store.subscribe,
344
- () => store.getThreads(),
345
- () => store.getThreads(),
346
- (state) => {
347
- const isLoading = useThreadsRevalidationManager.getIsLoading();
348
- if (isLoading) {
349
- return {
350
- isLoading: true
351
- };
352
- }
353
- const options2 = useThreadsRevalidationManager.getOptions();
354
- const error = useThreadsRevalidationManager.getError();
355
- const filtered = state.filter((thread) => {
356
- if (thread.roomId !== room.id)
357
- return false;
358
- const query = options2.query ?? {};
359
- for (const key2 in query.metadata) {
360
- if (thread.metadata[key2] !== query.metadata[key2]) {
361
- return false;
362
- }
363
- }
364
- return true;
365
- });
366
- return {
367
- isLoading: false,
368
- threads: filtered,
369
- error
370
- };
371
- }
372
- );
455
+ }, [manager, key]);
456
+ const cache = _useThreads(room, options);
457
+ return cache;
373
458
  }
374
459
  function useThreadsSuspense(room, options = { query: { metadata: {} } }) {
375
460
  const key = useMemo(() => stringify(options), [options]);
@@ -397,8 +482,29 @@ function createCommentsRoom(errorEventSource) {
397
482
  return () => {
398
483
  manager.decrementReferenceCount(key);
399
484
  };
400
- });
401
- const cache = useSyncExternalStoreWithSelector(
485
+ }, [manager, key]);
486
+ const cache = _useThreads(room, options);
487
+ if (cache.error) {
488
+ throw cache.error;
489
+ }
490
+ if (cache.isLoading || !cache.threads) {
491
+ throw revalidateCache({
492
+ shouldDedupe: true
493
+ });
494
+ }
495
+ return {
496
+ isLoading: false,
497
+ threads: cache.threads,
498
+ error: cache.error
499
+ };
500
+ }
501
+ function _useThreads(room, options) {
502
+ const manager = useRoomManager();
503
+ const useThreadsRevalidationManager = getUseThreadsRevalidationManager(
504
+ options,
505
+ manager
506
+ );
507
+ return useSyncExternalStoreWithSelector(
402
508
  store.subscribe,
403
509
  () => store.getThreads(),
404
510
  () => store.getThreads(),
@@ -415,8 +521,8 @@ function createCommentsRoom(errorEventSource) {
415
521
  if (thread.roomId !== room.id)
416
522
  return false;
417
523
  const query = options2.query ?? {};
418
- for (const key2 in query.metadata) {
419
- if (thread.metadata[key2] !== query.metadata[key2]) {
524
+ for (const key in query.metadata) {
525
+ if (thread.metadata[key] !== query.metadata[key]) {
420
526
  return false;
421
527
  }
422
528
  }
@@ -429,26 +535,13 @@ function createCommentsRoom(errorEventSource) {
429
535
  };
430
536
  }
431
537
  );
432
- if (cache.error) {
433
- throw cache.error;
434
- }
435
- if (cache.isLoading || !cache.threads) {
436
- throw revalidateCache({
437
- shouldDedupe: true
438
- });
439
- }
440
- return {
441
- isLoading: false,
442
- threads: cache.threads,
443
- error: cache.error
444
- };
445
538
  }
446
539
  function useEditThreadMetadata(room) {
447
540
  const manager = useRoomManager();
448
541
  const fetcher = useThreadsFetcher();
449
542
  const revalidate = useRevalidateCache(manager, fetcher);
450
543
  const mutate = useMutate(manager, revalidate);
451
- const editThreadMetadata = useCallback2(
544
+ const editThreadMetadata = useCallback3(
452
545
  (options) => {
453
546
  const threadId = options.threadId;
454
547
  const metadata = "metadata" in options ? options.metadata : {};
@@ -487,13 +580,13 @@ function createCommentsRoom(errorEventSource) {
487
580
  const fetcher = useThreadsFetcher();
488
581
  const revalidate = useRevalidateCache(manager, fetcher);
489
582
  const mutate = useMutate(manager, revalidate);
490
- const createThread = useCallback2(
583
+ const createThread = useCallback3(
491
584
  (options) => {
492
585
  const body = options.body;
493
586
  const metadata = "metadata" in options ? options.metadata : {};
494
587
  const threads = getThreads(manager);
495
- const threadId = createOptimisticId(THREAD_ID_PREFIX);
496
- const commentId = createOptimisticId(COMMENT_ID_PREFIX);
588
+ const threadId = createThreadId();
589
+ const commentId = createCommentId();
497
590
  const now = /* @__PURE__ */ new Date();
498
591
  const newComment = {
499
592
  id: commentId,
@@ -541,10 +634,10 @@ function createCommentsRoom(errorEventSource) {
541
634
  const fetcher = useThreadsFetcher();
542
635
  const revalidate = useRevalidateCache(manager, fetcher);
543
636
  const mutate = useMutate(manager, revalidate);
544
- const createComment = useCallback2(
637
+ const createComment = useCallback3(
545
638
  ({ threadId, body }) => {
546
639
  const threads = getThreads(manager);
547
- const commentId = createOptimisticId(COMMENT_ID_PREFIX);
640
+ const commentId = createCommentId();
548
641
  const now = /* @__PURE__ */ new Date();
549
642
  const comment = {
550
643
  id: commentId,
@@ -589,7 +682,7 @@ function createCommentsRoom(errorEventSource) {
589
682
  const fetcher = useThreadsFetcher();
590
683
  const revalidate = useRevalidateCache(manager, fetcher);
591
684
  const mutate = useMutate(manager, revalidate);
592
- const editComment = useCallback2(
685
+ const editComment = useCallback3(
593
686
  ({ threadId, commentId, body }) => {
594
687
  const threads = getThreads(manager);
595
688
  const now = /* @__PURE__ */ new Date();
@@ -631,7 +724,7 @@ function createCommentsRoom(errorEventSource) {
631
724
  const fetcher = useThreadsFetcher();
632
725
  const revalidate = useRevalidateCache(manager, fetcher);
633
726
  const mutate = useMutate(manager, revalidate);
634
- const deleteComment = useCallback2(
727
+ const deleteComment = useCallback3(
635
728
  ({ threadId, commentId }) => {
636
729
  const threads = getThreads(manager);
637
730
  const now = /* @__PURE__ */ new Date();
@@ -682,7 +775,7 @@ function createCommentsRoom(errorEventSource) {
682
775
  const fetcher = useThreadsFetcher();
683
776
  const revalidate = useRevalidateCache(manager, fetcher);
684
777
  const mutate = useMutate(manager, revalidate);
685
- const createComment = useCallback2(
778
+ const createComment = useCallback3(
686
779
  ({ threadId, commentId, emoji }) => {
687
780
  const threads = getThreads(manager);
688
781
  const now = /* @__PURE__ */ new Date();
@@ -747,7 +840,7 @@ function createCommentsRoom(errorEventSource) {
747
840
  const fetcher = useThreadsFetcher();
748
841
  const revalidate = useRevalidateCache(manager, fetcher);
749
842
  const mutate = useMutate(manager, revalidate);
750
- const createComment = useCallback2(
843
+ const createComment = useCallback3(
751
844
  ({ threadId, commentId, emoji }) => {
752
845
  const threads = getThreads(manager);
753
846
  const userId = getCurrentUserId(room);
@@ -821,6 +914,12 @@ function createCommentsRoom(errorEventSource) {
821
914
  function createOptimisticId(prefix) {
822
915
  return `${prefix}_${nanoid()}`;
823
916
  }
917
+ function createThreadId() {
918
+ return createOptimisticId(THREAD_ID_PREFIX);
919
+ }
920
+ function createCommentId() {
921
+ return createOptimisticId(COMMENT_ID_PREFIX);
922
+ }
824
923
  function getCurrentUserId(room) {
825
924
  const self = room.getSelf();
826
925
  if (self === null || self.id === void 0) {
@@ -897,6 +996,12 @@ function createRoomRevalidationManager(roomId, {
897
996
  setRevalidationmanager(key, manager) {
898
997
  revalidationManagerByOptions.set(key, manager);
899
998
  },
999
+ getTotalReferenceCount() {
1000
+ return Array.from(referenceCountByOptions.values()).reduce(
1001
+ (acc, count) => acc + count,
1002
+ 0
1003
+ );
1004
+ },
900
1005
  incrementReferenceCount(key) {
901
1006
  const count = referenceCountByOptions.get(key) ?? 0;
902
1007
  referenceCountByOptions.set(key, count + 1);
@@ -930,7 +1035,6 @@ function createUseThreadsRevalidationManager(options, manager) {
930
1035
  let isLoading = true;
931
1036
  let request;
932
1037
  let error;
933
- const errorEventSource = makeEventSource();
934
1038
  return {
935
1039
  // Cache
936
1040
  getCache() {
@@ -959,7 +1063,9 @@ function createUseThreadsRevalidationManager(options, manager) {
959
1063
  },
960
1064
  setError(err) {
961
1065
  error = err;
962
- errorEventSource.notify(err);
1066
+ isLoading = false;
1067
+ const cache = manager.getCache();
1068
+ manager.setCache(cache);
963
1069
  },
964
1070
  // Mutation
965
1071
  getMutation() {
@@ -979,12 +1085,19 @@ function createUseThreadsRevalidationManager(options, manager) {
979
1085
  }
980
1086
  };
981
1087
  }
1088
+ function getPollingInterval(isBrowserOnline, isDocumentVisible, isRoomConnected) {
1089
+ if (!isBrowserOnline || !isDocumentVisible)
1090
+ return;
1091
+ if (isRoomConnected)
1092
+ return POLLING_INTERVAL_REALTIME;
1093
+ return POLLING_INTERVAL;
1094
+ }
982
1095
 
983
1096
  // src/comments/lib/use-debounce.ts
984
- import { useEffect as useEffect4, useRef as useRef2, useState as useState2 } from "react";
1097
+ import { useEffect as useEffect4, useRef as useRef3, useState as useState2 } from "react";
985
1098
  var DEFAULT_DELAY = 500;
986
1099
  function useDebounce(value, delay = DEFAULT_DELAY) {
987
- const timeout = useRef2();
1100
+ const timeout = useRef3();
988
1101
  const [debouncedValue, setDebouncedValue] = useState2(value);
989
1102
  useEffect4(() => {
990
1103
  if (delay === false) {
@@ -1005,8 +1118,8 @@ function useDebounce(value, delay = DEFAULT_DELAY) {
1005
1118
  }
1006
1119
 
1007
1120
  // src/lib/use-async-cache.ts
1008
- import { useCallback as useCallback3, useEffect as useEffect5, useMemo as useMemo2, useRef as useRef3 } from "react";
1009
- import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
1121
+ import { useCallback as useCallback4, useEffect as useEffect5, useMemo as useMemo2, useRef as useRef4 } from "react";
1122
+ import { useSyncExternalStore as useSyncExternalStore4 } from "use-sync-external-store/shim/index.js";
1010
1123
 
1011
1124
  // src/lib/use-initial.ts
1012
1125
  import { useState as useState3 } from "react";
@@ -1032,17 +1145,17 @@ function useAsyncCache(cache, key, options) {
1032
1145
  void cacheItem2.get();
1033
1146
  return cacheItem2;
1034
1147
  }, [cache, key]);
1035
- const subscribe = useCallback3(
1148
+ const subscribe2 = useCallback4(
1036
1149
  (callback) => cacheItem?.subscribe(callback) ?? noop,
1037
1150
  [cacheItem]
1038
1151
  );
1039
- const getState = useCallback3(
1152
+ const getState = useCallback4(
1040
1153
  () => cacheItem?.getState() ?? INITIAL_ASYNC_STATE,
1041
1154
  [cacheItem]
1042
1155
  );
1043
- const revalidate = useCallback3(() => cacheItem?.revalidate(), [cacheItem]);
1044
- const state = useSyncExternalStore(subscribe, getState, getState);
1045
- const previousData = useRef3();
1156
+ const revalidate = useCallback4(() => cacheItem?.revalidate(), [cacheItem]);
1157
+ const state = useSyncExternalStore4(subscribe2, getState, getState);
1158
+ const previousData = useRef4();
1046
1159
  let data = state.data;
1047
1160
  useEffect5(() => {
1048
1161
  previousData.current = { key, data: state.data };
@@ -1083,9 +1196,9 @@ function useAsyncCache(cache, key, options) {
1083
1196
  }
1084
1197
 
1085
1198
  // src/lib/use-latest.ts
1086
- import { useEffect as useEffect6, useRef as useRef4 } from "react";
1199
+ import { useEffect as useEffect6, useRef as useRef5 } from "react";
1087
1200
  function useLatest(value) {
1088
- const ref = useRef4(value);
1201
+ const ref = useRef5(value);
1089
1202
  useEffect6(() => {
1090
1203
  ref.current = value;
1091
1204
  }, [value]);
@@ -1121,7 +1234,7 @@ var missing_unstable_batchedUpdates = (reactVersion, roomId) => `We noticed you\
1121
1234
 
1122
1235
  Why? Please see https://liveblocks.io/docs/platform/troubleshooting#stale-props-zombie-child for more information`;
1123
1236
  var superfluous_unstable_batchedUpdates = "You don\u2019t need to pass unstable_batchedUpdates to RoomProvider anymore, since you\u2019re on React 18+ already.";
1124
- function useSyncExternalStore2(s, gs, gss) {
1237
+ function useSyncExternalStore5(s, gs, gss) {
1125
1238
  return useSyncExternalStoreWithSelector2(s, gs, gss, identity);
1126
1239
  }
1127
1240
  var STABLE_EMPTY_LIST = Object.freeze([]);
@@ -1270,16 +1383,16 @@ function createRoomContext(client, options) {
1270
1383
  }
1271
1384
  function useStatus() {
1272
1385
  const room = useRoom();
1273
- const subscribe = room.events.status.subscribe;
1274
- const getSnapshot = room.getStatus;
1386
+ const subscribe2 = room.events.status.subscribe;
1387
+ const getSnapshot2 = room.getStatus;
1275
1388
  const getServerSnapshot = room.getStatus;
1276
- return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
1389
+ return useSyncExternalStore5(subscribe2, getSnapshot2, getServerSnapshot);
1277
1390
  }
1278
1391
  function useMyPresence() {
1279
1392
  const room = useRoom();
1280
- const subscribe = room.events.myPresence.subscribe;
1281
- const getSnapshot = room.getPresence;
1282
- const presence = useSyncExternalStore2(subscribe, getSnapshot, getSnapshot);
1393
+ const subscribe2 = room.events.myPresence.subscribe;
1394
+ const getSnapshot2 = room.getPresence;
1395
+ const presence = useSyncExternalStore5(subscribe2, getSnapshot2, getSnapshot2);
1283
1396
  const setPresence = room.updatePresence;
1284
1397
  return [presence, setPresence];
1285
1398
  }
@@ -1288,12 +1401,12 @@ function createRoomContext(client, options) {
1288
1401
  }
1289
1402
  function useOthers(selector, isEqual) {
1290
1403
  const room = useRoom();
1291
- const subscribe = room.events.others.subscribe;
1292
- const getSnapshot = room.getOthers;
1404
+ const subscribe2 = room.events.others.subscribe;
1405
+ const getSnapshot2 = room.getOthers;
1293
1406
  const getServerSnapshot = alwaysEmptyList;
1294
1407
  return useSyncExternalStoreWithSelector2(
1295
- subscribe,
1296
- getSnapshot,
1408
+ subscribe2,
1409
+ getSnapshot2,
1297
1410
  getServerSnapshot,
1298
1411
  selector ?? identity,
1299
1412
  isEqual
@@ -1397,8 +1510,8 @@ function createRoomContext(client, options) {
1397
1510
  }
1398
1511
  function useSelf(maybeSelector, isEqual) {
1399
1512
  const room = useRoom();
1400
- const subscribe = room.events.self.subscribe;
1401
- const getSnapshot = room.getSelf;
1513
+ const subscribe2 = room.events.self.subscribe;
1514
+ const getSnapshot2 = room.getSelf;
1402
1515
  const selector = maybeSelector ?? identity;
1403
1516
  const wrappedSelector = React3.useCallback(
1404
1517
  (me) => me !== null ? selector(me) : null,
@@ -1406,8 +1519,8 @@ function createRoomContext(client, options) {
1406
1519
  );
1407
1520
  const getServerSnapshot = alwaysNull;
1408
1521
  return useSyncExternalStoreWithSelector2(
1409
- subscribe,
1410
- getSnapshot,
1522
+ subscribe2,
1523
+ getSnapshot2,
1411
1524
  getServerSnapshot,
1412
1525
  wrappedSelector,
1413
1526
  isEqual
@@ -1415,10 +1528,10 @@ function createRoomContext(client, options) {
1415
1528
  }
1416
1529
  function useMutableStorageRoot() {
1417
1530
  const room = useRoom();
1418
- const subscribe = room.events.storageDidLoad.subscribeOnce;
1419
- const getSnapshot = room.getStorageSnapshot;
1531
+ const subscribe2 = room.events.storageDidLoad.subscribeOnce;
1532
+ const getSnapshot2 = room.getStorageSnapshot;
1420
1533
  const getServerSnapshot = alwaysNull;
1421
- return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
1534
+ return useSyncExternalStore5(subscribe2, getSnapshot2, getServerSnapshot);
1422
1535
  }
1423
1536
  function useStorageRoot() {
1424
1537
  return [useMutableStorageRoot()];
@@ -1434,15 +1547,15 @@ function createRoomContext(client, options) {
1434
1547
  }
1435
1548
  function useCanUndo() {
1436
1549
  const room = useRoom();
1437
- const subscribe = room.events.history.subscribe;
1550
+ const subscribe2 = room.events.history.subscribe;
1438
1551
  const canUndo = room.history.canUndo;
1439
- return useSyncExternalStore2(subscribe, canUndo, canUndo);
1552
+ return useSyncExternalStore5(subscribe2, canUndo, canUndo);
1440
1553
  }
1441
1554
  function useCanRedo() {
1442
1555
  const room = useRoom();
1443
- const subscribe = room.events.history.subscribe;
1556
+ const subscribe2 = room.events.history.subscribe;
1444
1557
  const canRedo = room.history.canRedo;
1445
- return useSyncExternalStore2(subscribe, canRedo, canRedo);
1558
+ return useSyncExternalStore5(subscribe2, canRedo, canRedo);
1446
1559
  }
1447
1560
  function useBatch() {
1448
1561
  return useRoom().batch;
@@ -1491,11 +1604,11 @@ function createRoomContext(client, options) {
1491
1604
  (rootOrNull2) => rootOrNull2 !== null ? selector(rootOrNull2) : null,
1492
1605
  [selector]
1493
1606
  );
1494
- const subscribe = React3.useCallback(
1607
+ const subscribe2 = React3.useCallback(
1495
1608
  (onStoreChange) => rootOrNull !== null ? room.subscribe(rootOrNull, onStoreChange, { isDeep: true }) : noop2,
1496
1609
  [room, rootOrNull]
1497
1610
  );
1498
- const getSnapshot = React3.useCallback(() => {
1611
+ const getSnapshot2 = React3.useCallback(() => {
1499
1612
  if (rootOrNull === null) {
1500
1613
  return null;
1501
1614
  } else {
@@ -1506,8 +1619,8 @@ function createRoomContext(client, options) {
1506
1619
  }, [rootOrNull]);
1507
1620
  const getServerSnapshot = alwaysNull;
1508
1621
  return useSyncExternalStoreWithSelector2(
1509
- subscribe,
1510
- getSnapshot,
1622
+ subscribe2,
1623
+ getSnapshot2,
1511
1624
  getServerSnapshot,
1512
1625
  wrappedSelector,
1513
1626
  isEqual