@liveblocks/react 2.7.1 → 2.7.2

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.
@@ -1,6 +1,6 @@
1
1
  // src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "2.7.1";
3
+ var PKG_VERSION = "2.7.2";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -196,8 +196,18 @@ import {
196
196
  console as console2,
197
197
  createStore,
198
198
  mapValues,
199
- nanoid
199
+ nanoid,
200
+ nn
200
201
  } from "@liveblocks/core";
202
+ var QUERY_STATE_LOADING = Object.freeze({ isLoading: true });
203
+ var QUERY_STATE_OK = Object.freeze({ isLoading: false, data: void 0 });
204
+ var INBOX_NOTIFICATIONS_QUERY = "INBOX_NOTIFICATIONS";
205
+ function makeNotificationSettingsQueryKey(roomId) {
206
+ return `${roomId}:NOTIFICATION_SETTINGS`;
207
+ }
208
+ function makeVersionsQueryKey(roomId) {
209
+ return `${roomId}-VERSIONS`;
210
+ }
201
211
  var UmbrellaStore = class {
202
212
  constructor() {
203
213
  this._prevState = null;
@@ -212,8 +222,7 @@ var UmbrellaStore = class {
212
222
  });
213
223
  this.getThreads = this.getThreads.bind(this);
214
224
  this.getInboxNotifications = this.getInboxNotifications.bind(this);
215
- this.getNotificationSettings = this.getNotificationSettings.bind(this);
216
- this.getVersions = this.getVersions.bind(this);
225
+ this.getInboxNotificationsAsync = this.getInboxNotificationsAsync.bind(this);
217
226
  this.subscribeThreads = this.subscribeThreads.bind(this);
218
227
  this.subscribeInboxNotifications = this.subscribeInboxNotifications.bind(this);
219
228
  this.subscribeNotificationSettings = this.subscribeNotificationSettings.bind(this);
@@ -225,7 +234,7 @@ var UmbrellaStore = class {
225
234
  const rawState = this._store.get();
226
235
  if (this._prevState !== rawState || this._stateCached === null) {
227
236
  this._prevState = rawState;
228
- this._stateCached = applyOptimisticUpdates(rawState);
237
+ this._stateCached = internalToExternalState(rawState);
229
238
  }
230
239
  return this._stateCached;
231
240
  }
@@ -235,11 +244,47 @@ var UmbrellaStore = class {
235
244
  getInboxNotifications() {
236
245
  return this.get();
237
246
  }
238
- getNotificationSettings() {
239
- return this.get();
247
+ // NOTE: This will read the async result, but WILL NOT start loading at the moment!
248
+ getInboxNotificationsAsync() {
249
+ const internalState = this._store.get();
250
+ const query = internalState.queries[INBOX_NOTIFICATIONS_QUERY];
251
+ if (query === void 0 || query.isLoading) {
252
+ return QUERY_STATE_LOADING;
253
+ }
254
+ if (query.error !== void 0) {
255
+ return query;
256
+ }
257
+ const inboxNotifications = this.get().inboxNotifications;
258
+ return { isLoading: false, inboxNotifications };
259
+ }
260
+ // NOTE: This will read the async result, but WILL NOT start loading at the moment!
261
+ getNotificationSettingsAsync(roomId) {
262
+ const state = this.get();
263
+ const query = state.queries[makeNotificationSettingsQueryKey(roomId)];
264
+ if (query === void 0 || query.isLoading) {
265
+ return QUERY_STATE_LOADING;
266
+ }
267
+ if (query.error !== void 0) {
268
+ return query;
269
+ }
270
+ return {
271
+ isLoading: false,
272
+ settings: nn(state.notificationSettingsByRoomId[roomId])
273
+ };
240
274
  }
241
- getVersions() {
242
- return this.get();
275
+ getVersionsAsync(roomId) {
276
+ const state = this.get();
277
+ const query = state.queries[makeVersionsQueryKey(roomId)];
278
+ if (query === void 0 || query.isLoading) {
279
+ return QUERY_STATE_LOADING;
280
+ }
281
+ if (query.error !== void 0) {
282
+ return query;
283
+ }
284
+ return {
285
+ isLoading: false,
286
+ versions: nn(state.versionsByRoomId[roomId])
287
+ };
243
288
  }
244
289
  /**
245
290
  * @private Only used by the E2E test suite.
@@ -574,29 +619,29 @@ var UmbrellaStore = class {
574
619
  // Query State APIs
575
620
  //
576
621
  setQueryLoading(queryKey) {
577
- this.setQueryState(queryKey, { isLoading: true });
622
+ this.setQueryState(queryKey, QUERY_STATE_LOADING);
578
623
  }
579
624
  setQueryOK(queryKey) {
580
- this.setQueryState(queryKey, { isLoading: false, data: void 0 });
625
+ this.setQueryState(queryKey, QUERY_STATE_OK);
581
626
  }
582
627
  setQueryError(queryKey, error) {
583
628
  this.setQueryState(queryKey, { isLoading: false, error });
584
629
  }
585
630
  };
586
- function applyOptimisticUpdates(state) {
587
- const output = {
588
- threads: { ...state.rawThreadsById },
589
- inboxNotifications: { ...state.inboxNotificationsById },
590
- notificationSettings: { ...state.notificationSettingsByRoomId }
631
+ function internalToExternalState(state) {
632
+ const computed = {
633
+ threadsById: { ...state.rawThreadsById },
634
+ inboxNotificationsById: { ...state.inboxNotificationsById },
635
+ notificationSettingsByRoomId: { ...state.notificationSettingsByRoomId }
591
636
  };
592
637
  for (const optimisticUpdate of state.optimisticUpdates) {
593
638
  switch (optimisticUpdate.type) {
594
639
  case "create-thread": {
595
- output.threads[optimisticUpdate.thread.id] = optimisticUpdate.thread;
640
+ computed.threadsById[optimisticUpdate.thread.id] = optimisticUpdate.thread;
596
641
  break;
597
642
  }
598
643
  case "edit-thread-metadata": {
599
- const thread = output.threads[optimisticUpdate.threadId];
644
+ const thread = computed.threadsById[optimisticUpdate.threadId];
600
645
  if (thread === void 0) {
601
646
  break;
602
647
  }
@@ -606,7 +651,7 @@ function applyOptimisticUpdates(state) {
606
651
  if (thread.updatedAt !== void 0 && thread.updatedAt > optimisticUpdate.updatedAt) {
607
652
  break;
608
653
  }
609
- output.threads[thread.id] = {
654
+ computed.threadsById[thread.id] = {
610
655
  ...thread,
611
656
  updatedAt: optimisticUpdate.updatedAt,
612
657
  metadata: {
@@ -617,49 +662,51 @@ function applyOptimisticUpdates(state) {
617
662
  break;
618
663
  }
619
664
  case "mark-thread-as-resolved": {
620
- const thread = output.threads[optimisticUpdate.threadId];
665
+ const thread = computed.threadsById[optimisticUpdate.threadId];
621
666
  if (thread === void 0) {
622
667
  break;
623
668
  }
624
669
  if (thread.deletedAt !== void 0) {
625
670
  break;
626
671
  }
627
- output.threads[thread.id] = {
672
+ computed.threadsById[thread.id] = {
628
673
  ...thread,
629
674
  resolved: true
630
675
  };
631
676
  break;
632
677
  }
633
678
  case "mark-thread-as-unresolved": {
634
- const thread = output.threads[optimisticUpdate.threadId];
679
+ const thread = computed.threadsById[optimisticUpdate.threadId];
635
680
  if (thread === void 0) {
636
681
  break;
637
682
  }
638
683
  if (thread.deletedAt !== void 0) {
639
684
  break;
640
685
  }
641
- output.threads[thread.id] = {
686
+ computed.threadsById[thread.id] = {
642
687
  ...thread,
643
688
  resolved: false
644
689
  };
645
690
  break;
646
691
  }
647
692
  case "create-comment": {
648
- const thread = output.threads[optimisticUpdate.comment.threadId];
693
+ const thread = computed.threadsById[optimisticUpdate.comment.threadId];
649
694
  if (thread === void 0) {
650
695
  break;
651
696
  }
652
- output.threads[thread.id] = applyUpsertComment(
697
+ computed.threadsById[thread.id] = applyUpsertComment(
653
698
  thread,
654
699
  optimisticUpdate.comment
655
700
  );
656
- const inboxNotification = Object.values(output.inboxNotifications).find(
701
+ const inboxNotification = Object.values(
702
+ computed.inboxNotificationsById
703
+ ).find(
657
704
  (notification) => notification.kind === "thread" && notification.threadId === thread.id
658
705
  );
659
706
  if (inboxNotification === void 0) {
660
707
  break;
661
708
  }
662
- output.inboxNotifications[inboxNotification.id] = {
709
+ computed.inboxNotificationsById[inboxNotification.id] = {
663
710
  ...inboxNotification,
664
711
  notifiedAt: optimisticUpdate.comment.createdAt,
665
712
  readAt: optimisticUpdate.comment.createdAt
@@ -667,22 +714,22 @@ function applyOptimisticUpdates(state) {
667
714
  break;
668
715
  }
669
716
  case "edit-comment": {
670
- const thread = output.threads[optimisticUpdate.comment.threadId];
717
+ const thread = computed.threadsById[optimisticUpdate.comment.threadId];
671
718
  if (thread === void 0) {
672
719
  break;
673
720
  }
674
- output.threads[thread.id] = applyUpsertComment(
721
+ computed.threadsById[thread.id] = applyUpsertComment(
675
722
  thread,
676
723
  optimisticUpdate.comment
677
724
  );
678
725
  break;
679
726
  }
680
727
  case "delete-comment": {
681
- const thread = output.threads[optimisticUpdate.threadId];
728
+ const thread = computed.threadsById[optimisticUpdate.threadId];
682
729
  if (thread === void 0) {
683
730
  break;
684
731
  }
685
- output.threads[thread.id] = applyDeleteComment(
732
+ computed.threadsById[thread.id] = applyDeleteComment(
686
733
  thread,
687
734
  optimisticUpdate.commentId,
688
735
  optimisticUpdate.deletedAt
@@ -690,12 +737,12 @@ function applyOptimisticUpdates(state) {
690
737
  break;
691
738
  }
692
739
  case "delete-thread": {
693
- const thread = output.threads[optimisticUpdate.threadId];
740
+ const thread = computed.threadsById[optimisticUpdate.threadId];
694
741
  if (thread === void 0) {
695
742
  break;
696
743
  }
697
- output.threads[optimisticUpdate.threadId] = {
698
- ...output.threads[optimisticUpdate.threadId],
744
+ computed.threadsById[optimisticUpdate.threadId] = {
745
+ ...thread,
699
746
  deletedAt: optimisticUpdate.deletedAt,
700
747
  updatedAt: optimisticUpdate.deletedAt,
701
748
  comments: []
@@ -703,11 +750,11 @@ function applyOptimisticUpdates(state) {
703
750
  break;
704
751
  }
705
752
  case "add-reaction": {
706
- const thread = output.threads[optimisticUpdate.threadId];
753
+ const thread = computed.threadsById[optimisticUpdate.threadId];
707
754
  if (thread === void 0) {
708
755
  break;
709
756
  }
710
- output.threads[thread.id] = applyAddReaction(
757
+ computed.threadsById[thread.id] = applyAddReaction(
711
758
  thread,
712
759
  optimisticUpdate.commentId,
713
760
  optimisticUpdate.reaction
@@ -715,11 +762,11 @@ function applyOptimisticUpdates(state) {
715
762
  break;
716
763
  }
717
764
  case "remove-reaction": {
718
- const thread = output.threads[optimisticUpdate.threadId];
765
+ const thread = computed.threadsById[optimisticUpdate.threadId];
719
766
  if (thread === void 0) {
720
767
  break;
721
768
  }
722
- output.threads[thread.id] = applyRemoveReaction(
769
+ computed.threadsById[thread.id] = applyRemoveReaction(
723
770
  thread,
724
771
  optimisticUpdate.commentId,
725
772
  optimisticUpdate.emoji,
@@ -729,36 +776,41 @@ function applyOptimisticUpdates(state) {
729
776
  break;
730
777
  }
731
778
  case "mark-inbox-notification-as-read": {
732
- output.inboxNotifications[optimisticUpdate.inboxNotificationId] = {
733
- ...state.inboxNotificationsById[optimisticUpdate.inboxNotificationId],
734
- readAt: optimisticUpdate.readAt
735
- };
779
+ const ibn = computed.inboxNotificationsById[optimisticUpdate.inboxNotificationId];
780
+ if (ibn === void 0) {
781
+ break;
782
+ }
783
+ computed.inboxNotificationsById[optimisticUpdate.inboxNotificationId] = { ...ibn, readAt: optimisticUpdate.readAt };
736
784
  break;
737
785
  }
738
786
  case "mark-all-inbox-notifications-as-read": {
739
- for (const id in output.inboxNotifications) {
740
- output.inboxNotifications[id] = {
741
- ...output.inboxNotifications[id],
787
+ for (const id in computed.inboxNotificationsById) {
788
+ const ibn = computed.inboxNotificationsById[id];
789
+ if (ibn === void 0) {
790
+ break;
791
+ }
792
+ computed.inboxNotificationsById[id] = {
793
+ ...ibn,
742
794
  readAt: optimisticUpdate.readAt
743
795
  };
744
796
  }
745
797
  break;
746
798
  }
747
799
  case "delete-inbox-notification": {
748
- const {
749
- [optimisticUpdate.inboxNotificationId]: _,
750
- ...inboxNotifications
751
- } = output.inboxNotifications;
752
- output.inboxNotifications = inboxNotifications;
800
+ delete computed.inboxNotificationsById[optimisticUpdate.inboxNotificationId];
753
801
  break;
754
802
  }
755
803
  case "delete-all-inbox-notifications": {
756
- output.inboxNotifications = {};
804
+ computed.inboxNotificationsById = {};
757
805
  break;
758
806
  }
759
807
  case "update-notification-settings": {
760
- output.notificationSettings[optimisticUpdate.roomId] = {
761
- ...output.notificationSettings[optimisticUpdate.roomId],
808
+ const settings = computed.notificationSettingsByRoomId[optimisticUpdate.roomId];
809
+ if (settings === void 0) {
810
+ break;
811
+ }
812
+ computed.notificationSettingsByRoomId[optimisticUpdate.roomId] = {
813
+ ...settings,
762
814
  ...optimisticUpdate.settings
763
815
  };
764
816
  }
@@ -766,23 +818,26 @@ function applyOptimisticUpdates(state) {
766
818
  }
767
819
  const cleanedThreads = (
768
820
  // Don't expose any soft-deleted threads
769
- Object.values(output.threads).filter(
770
- (thread) => !thread.deletedAt
821
+ Object.values(computed.threadsById).filter((thread) => !thread.deletedAt).filter(
822
+ (thread) => (
823
+ // Only keep a thread if there is at least one non-deleted comment
824
+ thread.comments.some((c) => c.deletedAt === void 0)
825
+ )
771
826
  )
772
827
  );
773
828
  const cleanedNotifications = (
774
829
  // Sort so that the most recent notifications are first
775
- Object.values(output.inboxNotifications).sort(
776
- (a, b) => b.notifiedAt.getTime() - a.notifiedAt.getTime()
777
- )
830
+ Object.values(computed.inboxNotificationsById).filter(
831
+ (ibn) => ibn.kind === "thread" ? computed.threadsById[ibn.threadId] && computed.threadsById[ibn.threadId]?.deletedAt === void 0 : true
832
+ ).sort((a, b) => b.notifiedAt.getTime() - a.notifiedAt.getTime())
778
833
  );
779
834
  return {
780
835
  inboxNotifications: cleanedNotifications,
781
- inboxNotificationsById: output.inboxNotifications,
782
- notificationSettingsByRoomId: output.notificationSettings,
836
+ inboxNotificationsById: computed.inboxNotificationsById,
837
+ notificationSettingsByRoomId: computed.notificationSettingsByRoomId,
783
838
  queries: state.queries,
784
839
  threads: cleanedThreads,
785
- threadsById: output.threads,
840
+ threadsById: computed.threadsById,
786
841
  versionsByRoomId: state.versionsByRoomId
787
842
  };
788
843
  }
@@ -902,12 +957,11 @@ function applyDeleteComment(thread, commentId, deletedAt) {
902
957
  body: void 0
903
958
  } : comment
904
959
  );
905
- if (!updatedComments.some((comment) => comment.deletedAt === void 0)) {
960
+ if (updatedComments.every((comment) => comment.deletedAt !== void 0)) {
906
961
  return {
907
962
  ...thread,
908
963
  deletedAt,
909
- updatedAt: deletedAt,
910
- comments: []
964
+ updatedAt: deletedAt
911
965
  };
912
966
  }
913
967
  return {
@@ -1011,55 +1065,30 @@ function missingRoomInfoError(roomId) {
1011
1065
  `resolveRoomsInfo didn't return anything for room '${roomId}'`
1012
1066
  );
1013
1067
  }
1068
+ function identity(x) {
1069
+ return x;
1070
+ }
1014
1071
  var _umbrellaStores = /* @__PURE__ */ new WeakMap();
1015
1072
  var _extras = /* @__PURE__ */ new WeakMap();
1016
1073
  var _bundles = /* @__PURE__ */ new WeakMap();
1017
1074
  var POLLING_INTERVAL = 60 * 1e3;
1018
- var INBOX_NOTIFICATIONS_QUERY = "INBOX_NOTIFICATIONS";
1019
1075
  var USER_THREADS_QUERY = "USER_THREADS";
1020
- function selectorFor_useInboxNotifications(state) {
1021
- const query = state.queries[INBOX_NOTIFICATIONS_QUERY];
1022
- if (query === void 0 || query.isLoading) {
1023
- return {
1024
- isLoading: true
1025
- };
1026
- }
1027
- if (query.error !== void 0) {
1028
- return {
1029
- error: query.error,
1030
- isLoading: false
1031
- };
1032
- }
1033
- return {
1034
- inboxNotifications: state.inboxNotifications,
1035
- isLoading: false
1036
- };
1037
- }
1038
- function selectUnreadInboxNotificationsCount(state) {
1076
+ function selectUnreadInboxNotificationsCount(inboxNotifications) {
1039
1077
  let count = 0;
1040
- for (const notification of state.inboxNotifications) {
1078
+ for (const notification of inboxNotifications) {
1041
1079
  if (notification.readAt === null || notification.readAt < notification.notifiedAt) {
1042
1080
  count++;
1043
1081
  }
1044
1082
  }
1045
1083
  return count;
1046
1084
  }
1047
- function selectorFor_useUnreadInboxNotificationsCount(state) {
1048
- const query = state.queries[INBOX_NOTIFICATIONS_QUERY];
1049
- if (query === void 0 || query.isLoading) {
1050
- return {
1051
- isLoading: true
1052
- };
1053
- }
1054
- if (query.error !== void 0) {
1055
- return {
1056
- error: query.error,
1057
- isLoading: false
1058
- };
1085
+ function selectorFor_useUnreadInboxNotificationsCount(result) {
1086
+ if (!result.inboxNotifications) {
1087
+ return result;
1059
1088
  }
1060
1089
  return {
1061
1090
  isLoading: false,
1062
- count: selectUnreadInboxNotificationsCount(state)
1091
+ count: selectUnreadInboxNotificationsCount(result.inboxNotifications)
1063
1092
  };
1064
1093
  }
1065
1094
  function selectorFor_useUser(state, userId) {
@@ -1191,23 +1220,21 @@ function makeExtrasForClient(client) {
1191
1220
  void waitUntilInboxNotificationsLoaded().catch(() => {
1192
1221
  });
1193
1222
  }
1194
- function useEnableInboxNotificationsPolling() {
1195
- useEffect3(() => {
1196
- pollerSubscribers++;
1197
- poller.start(POLLING_INTERVAL);
1198
- return () => {
1199
- if (pollerSubscribers <= 0) {
1200
- console.warn(
1201
- `Internal unexpected behavior. Cannot decrease subscriber count for query "${INBOX_NOTIFICATIONS_QUERY}"`
1202
- );
1203
- return;
1204
- }
1205
- pollerSubscribers--;
1206
- if (pollerSubscribers <= 0) {
1207
- poller.stop();
1208
- }
1209
- };
1210
- }, []);
1223
+ function startPolling() {
1224
+ pollerSubscribers++;
1225
+ poller.start(POLLING_INTERVAL);
1226
+ return () => {
1227
+ if (pollerSubscribers <= 0) {
1228
+ console.warn(
1229
+ `Internal unexpected behavior. Cannot decrease subscriber count for query "${INBOX_NOTIFICATIONS_QUERY}"`
1230
+ );
1231
+ return;
1232
+ }
1233
+ pollerSubscribers--;
1234
+ if (pollerSubscribers <= 0) {
1235
+ poller.stop();
1236
+ }
1237
+ };
1211
1238
  }
1212
1239
  const userThreadsPoller = makePoller(refreshUserThreads);
1213
1240
  let isFetchingUserThreadsUpdates = false;
@@ -1292,7 +1319,7 @@ function makeExtrasForClient(client) {
1292
1319
  }
1293
1320
  return {
1294
1321
  store,
1295
- useEnableInboxNotificationsPolling,
1322
+ startPolling,
1296
1323
  waitUntilInboxNotificationsLoaded,
1297
1324
  loadInboxNotifications,
1298
1325
  incrementUserThreadsQuerySubscribers,
@@ -1337,16 +1364,14 @@ function makeLiveblocksContextBundle(client) {
1337
1364
  return bundle;
1338
1365
  }
1339
1366
  function useInboxNotifications_withClient(client) {
1340
- const { loadInboxNotifications, store, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
1341
- useEffect3(() => {
1342
- loadInboxNotifications();
1343
- }, [loadInboxNotifications]);
1344
- useEnableInboxNotificationsPolling();
1367
+ const { loadInboxNotifications, store, startPolling } = getExtrasForClient(client);
1368
+ useEffect3(loadInboxNotifications, [loadInboxNotifications]);
1369
+ useEffect3(startPolling, [startPolling]);
1345
1370
  return useSyncExternalStoreWithSelector(
1346
1371
  store.subscribeInboxNotifications,
1347
- store.getInboxNotifications,
1348
- store.getInboxNotifications,
1349
- selectorFor_useInboxNotifications,
1372
+ store.getInboxNotificationsAsync,
1373
+ store.getInboxNotificationsAsync,
1374
+ identity,
1350
1375
  shallow3
1351
1376
  );
1352
1377
  }
@@ -1359,15 +1384,13 @@ function useInboxNotificationsSuspense_withClient(client) {
1359
1384
  return result;
1360
1385
  }
1361
1386
  function useUnreadInboxNotificationsCount_withClient(client) {
1362
- const { store, loadInboxNotifications, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
1363
- useEffect3(() => {
1364
- loadInboxNotifications();
1365
- }, [loadInboxNotifications]);
1366
- useEnableInboxNotificationsPolling();
1387
+ const { store, loadInboxNotifications, startPolling } = getExtrasForClient(client);
1388
+ useEffect3(loadInboxNotifications, [loadInboxNotifications]);
1389
+ useEffect3(startPolling, [startPolling]);
1367
1390
  return useSyncExternalStoreWithSelector(
1368
1391
  store.subscribeInboxNotifications,
1369
- store.getInboxNotifications,
1370
- store.getInboxNotifications,
1392
+ store.getInboxNotificationsAsync,
1393
+ store.getInboxNotificationsAsync,
1371
1394
  selectorFor_useUnreadInboxNotificationsCount,
1372
1395
  shallow3
1373
1396
  );
@@ -1920,7 +1943,6 @@ import {
1920
1943
  kInternal as kInternal2,
1921
1944
  makeEventSource,
1922
1945
  makePoller as makePoller2,
1923
- nn,
1924
1946
  NotificationsApiError,
1925
1947
  ServerMsgCode,
1926
1948
  stringify as stringify2
@@ -1961,7 +1983,7 @@ function useScrollToCommentOnLoadEffect(shouldScrollOnLoad, state) {
1961
1983
  var SMOOTH_DELAY = 1e3;
1962
1984
  var noop2 = () => {
1963
1985
  };
1964
- var identity = (x) => x;
1986
+ var identity2 = (x) => x;
1965
1987
  var missing_unstable_batchedUpdates = (reactVersion, roomId) => `We noticed you\u2019re using React ${reactVersion}. Please pass unstable_batchedUpdates at the RoomProvider level until you\u2019re ready to upgrade to React 18:
1966
1988
 
1967
1989
  import { unstable_batchedUpdates } from "react-dom"; // or "react-native"
@@ -1975,13 +1997,10 @@ var missing_unstable_batchedUpdates = (reactVersion, roomId) => `We noticed you\
1975
1997
  Why? Please see https://liveblocks.io/docs/platform/troubleshooting#stale-props-zombie-child for more information`;
1976
1998
  var superfluous_unstable_batchedUpdates = "You don\u2019t need to pass unstable_batchedUpdates to RoomProvider anymore, since you\u2019re on React 18+ already.";
1977
1999
  function useSyncExternalStore2(s, gs, gss) {
1978
- return useSyncExternalStoreWithSelector2(s, gs, gss, identity);
2000
+ return useSyncExternalStoreWithSelector2(s, gs, gss, identity2);
1979
2001
  }
1980
2002
  var STABLE_EMPTY_LIST = Object.freeze([]);
1981
2003
  var POLLING_INTERVAL2 = 5 * 60 * 1e3;
1982
- function makeNotificationSettingsQueryKey(roomId) {
1983
- return `${roomId}:NOTIFICATION_SETTINGS`;
1984
- }
1985
2004
  function alwaysEmptyList() {
1986
2005
  return STABLE_EMPTY_LIST;
1987
2006
  }
@@ -1991,10 +2010,6 @@ function alwaysNull() {
1991
2010
  function selectorFor_useOthersConnectionIds(others) {
1992
2011
  return others.map((user) => user.connectionId);
1993
2012
  }
1994
- function selectNotificationSettings(roomId, state) {
1995
- const notificationSettings = state.notificationSettingsByRoomId;
1996
- return nn(notificationSettings[roomId]);
1997
- }
1998
2013
  function makeMutationContext(room) {
1999
2014
  const cannotUseUntil = "This mutation cannot be used until";
2000
2015
  const needsPresence = `${cannotUseUntil} connected to the Liveblocks room`;
@@ -2123,7 +2138,7 @@ function makeExtrasForClient2(client) {
2123
2138
  }
2124
2139
  }
2125
2140
  async function getRoomVersions(room, { retryCount } = { retryCount: 0 }) {
2126
- const queryKey = getVersionsQueryKey(room.id);
2141
+ const queryKey = makeVersionsQueryKey(room.id);
2127
2142
  const existingRequest = requestsByQuery.get(queryKey);
2128
2143
  if (existingRequest !== void 0) return existingRequest;
2129
2144
  const request = room[kInternal2].listTextVersions();
@@ -2183,7 +2198,8 @@ function makeExtrasForClient2(client) {
2183
2198
  }
2184
2199
  return;
2185
2200
  }
2186
- async function getInboxNotificationSettings(room, queryKey, { retryCount } = { retryCount: 0 }) {
2201
+ async function getInboxNotificationSettings(room, { retryCount } = { retryCount: 0 }) {
2202
+ const queryKey = makeNotificationSettingsQueryKey(room.id);
2187
2203
  const existingRequest = requestsByQuery.get(queryKey);
2188
2204
  if (existingRequest !== void 0) return existingRequest;
2189
2205
  try {
@@ -2195,7 +2211,7 @@ function makeExtrasForClient2(client) {
2195
2211
  } catch (err) {
2196
2212
  requestsByQuery.delete(queryKey);
2197
2213
  retryError(() => {
2198
- void getInboxNotificationSettings(room, queryKey, {
2214
+ void getInboxNotificationSettings(room, {
2199
2215
  retryCount: retryCount + 1
2200
2216
  });
2201
2217
  }, retryCount);
@@ -2579,7 +2595,7 @@ function useSelf(maybeSelector, isEqual) {
2579
2595
  const room = useRoom();
2580
2596
  const subscribe = room.events.self.subscribe;
2581
2597
  const getSnapshot = room.getSelf;
2582
- const selector = maybeSelector ?? identity;
2598
+ const selector = maybeSelector ?? identity2;
2583
2599
  const wrappedSelector = React5.useCallback(
2584
2600
  (me) => me !== null ? selector(me) : null,
2585
2601
  [selector]
@@ -2613,7 +2629,7 @@ function useOthers(selector, isEqual) {
2613
2629
  subscribe,
2614
2630
  getSnapshot,
2615
2631
  getServerSnapshot,
2616
- selector ?? identity,
2632
+ selector ?? identity2,
2617
2633
  isEqual
2618
2634
  );
2619
2635
  }
@@ -3259,37 +3275,51 @@ function useThreadSubscription(threadId) {
3259
3275
  );
3260
3276
  }
3261
3277
  function useRoomNotificationSettings() {
3278
+ const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
3262
3279
  const client = useClient();
3263
3280
  const room = useRoom();
3264
3281
  const { store } = getExtrasForClient2(client);
3282
+ const getter = React5.useCallback(
3283
+ () => store.getNotificationSettingsAsync(room.id),
3284
+ [store, room.id]
3285
+ );
3265
3286
  React5.useEffect(() => {
3266
3287
  const { getInboxNotificationSettings } = getExtrasForClient2(client);
3267
- const queryKey = makeNotificationSettingsQueryKey(room.id);
3268
- void getInboxNotificationSettings(room, queryKey);
3288
+ void getInboxNotificationSettings(room);
3269
3289
  }, [client, room]);
3290
+ const settings = useSyncExternalStoreWithSelector2(
3291
+ store.subscribeNotificationSettings,
3292
+ getter,
3293
+ getter,
3294
+ identity2,
3295
+ shallow4
3296
+ );
3297
+ return React5.useMemo(() => {
3298
+ return [settings, updateRoomNotificationSettings];
3299
+ }, [settings, updateRoomNotificationSettings]);
3300
+ }
3301
+ function useRoomNotificationSettingsSuspense() {
3270
3302
  const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
3271
- const selector = React5.useCallback(
3272
- (state) => {
3273
- const query = state.queries[makeNotificationSettingsQueryKey(room.id)];
3274
- if (query === void 0 || query.isLoading) {
3275
- return { isLoading: true };
3276
- }
3277
- if (query.error !== void 0) {
3278
- return { isLoading: false, error: query.error };
3279
- }
3280
- return {
3281
- isLoading: false,
3282
- settings: selectNotificationSettings(room.id, state)
3283
- };
3284
- },
3285
- [room]
3303
+ const client = useClient();
3304
+ const room = useRoom();
3305
+ const { store } = getExtrasForClient2(client);
3306
+ const getter = React5.useCallback(
3307
+ () => store.getNotificationSettingsAsync(room.id),
3308
+ [store, room.id]
3286
3309
  );
3287
3310
  const settings = useSyncExternalStoreWithSelector2(
3288
3311
  store.subscribeNotificationSettings,
3289
- store.getThreads,
3290
- store.getThreads,
3291
- selector
3312
+ getter,
3313
+ getter,
3314
+ identity2,
3315
+ shallow4
3292
3316
  );
3317
+ if (settings.isLoading) {
3318
+ const { getInboxNotificationSettings } = getExtrasForClient2(client);
3319
+ throw getInboxNotificationSettings(room);
3320
+ } else if (settings.error) {
3321
+ throw settings.error;
3322
+ }
3293
3323
  return React5.useMemo(() => {
3294
3324
  return [settings, updateRoomNotificationSettings];
3295
3325
  }, [settings, updateRoomNotificationSettings]);
@@ -3326,34 +3356,44 @@ function useHistoryVersionData(versionId) {
3326
3356
  function useHistoryVersions() {
3327
3357
  const client = useClient();
3328
3358
  const room = useRoom();
3329
- const queryKey = getVersionsQueryKey(room.id);
3330
3359
  const { store, getRoomVersions } = getExtrasForClient2(client);
3360
+ const getter = React5.useCallback(
3361
+ () => store.getVersionsAsync(room.id),
3362
+ [store, room.id]
3363
+ );
3331
3364
  React5.useEffect(() => {
3332
3365
  void getRoomVersions(room);
3333
3366
  }, [room]);
3334
- const selector = React5.useCallback(
3335
- (state2) => {
3336
- const query = state2.queries[queryKey];
3337
- if (query === void 0 || query.isLoading) {
3338
- return {
3339
- isLoading: true
3340
- };
3341
- }
3342
- return {
3343
- versions: state2.versionsByRoomId[room.id],
3344
- isLoading: false,
3345
- error: query.error
3346
- };
3347
- },
3348
- [room, queryKey]
3349
- // eslint-disable-line react-hooks/exhaustive-deps
3367
+ const state = useSyncExternalStoreWithSelector2(
3368
+ store.subscribeVersions,
3369
+ getter,
3370
+ getter,
3371
+ identity2,
3372
+ shallow4
3373
+ );
3374
+ return state;
3375
+ }
3376
+ function useHistoryVersionsSuspense() {
3377
+ const client = useClient();
3378
+ const room = useRoom();
3379
+ const { store } = getExtrasForClient2(client);
3380
+ const getter = React5.useCallback(
3381
+ () => store.getVersionsAsync(room.id),
3382
+ [store, room.id]
3350
3383
  );
3351
3384
  const state = useSyncExternalStoreWithSelector2(
3352
3385
  store.subscribeVersions,
3353
- store.getVersions,
3354
- store.getVersions,
3355
- selector
3386
+ getter,
3387
+ getter,
3388
+ identity2,
3389
+ shallow4
3356
3390
  );
3391
+ if (state.isLoading) {
3392
+ const { getRoomVersions } = getExtrasForClient2(client);
3393
+ throw getRoomVersions(room);
3394
+ } else if (state.error) {
3395
+ throw state.error;
3396
+ }
3357
3397
  return state;
3358
3398
  }
3359
3399
  function useUpdateRoomNotificationSettings() {
@@ -3486,77 +3526,12 @@ function useThreadsSuspense(options = {
3486
3526
  useScrollToCommentOnLoadEffect(scrollOnLoad, state);
3487
3527
  return state;
3488
3528
  }
3489
- function useHistoryVersionsSuspense() {
3490
- const client = useClient();
3491
- const room = useRoom();
3492
- const queryKey = getVersionsQueryKey(room.id);
3493
- const { store, getRoomVersions } = getExtrasForClient2(client);
3494
- const query = store.getVersions().queries[queryKey];
3495
- if (query === void 0 || query.isLoading) {
3496
- throw getRoomVersions(room);
3497
- }
3498
- if (query.error) {
3499
- throw query.error;
3500
- }
3501
- const selector = React5.useCallback(
3502
- (state2) => {
3503
- return {
3504
- versions: state2.versionsByRoomId[room.id],
3505
- isLoading: false
3506
- };
3507
- },
3508
- [room, queryKey]
3509
- // eslint-disable-line react-hooks/exhaustive-deps
3510
- );
3511
- const state = useSyncExternalStoreWithSelector2(
3512
- store.subscribeVersions,
3513
- store.getVersions,
3514
- store.getVersions,
3515
- selector
3516
- );
3517
- return state;
3518
- }
3519
- function useRoomNotificationSettingsSuspense() {
3520
- const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
3521
- const client = useClient();
3522
- const room = useRoom();
3523
- const queryKey = makeNotificationSettingsQueryKey(room.id);
3524
- const { store, getInboxNotificationSettings } = getExtrasForClient2(client);
3525
- const query = store.getNotificationSettings().queries[queryKey];
3526
- if (query === void 0 || query.isLoading) {
3527
- throw getInboxNotificationSettings(room, queryKey);
3528
- }
3529
- if (query.error) {
3530
- throw query.error;
3531
- }
3532
- const selector = React5.useCallback(
3533
- (state) => {
3534
- return {
3535
- isLoading: false,
3536
- settings: selectNotificationSettings(room.id, state)
3537
- };
3538
- },
3539
- [room]
3540
- );
3541
- const settings = useSyncExternalStoreWithSelector2(
3542
- store.subscribeNotificationSettings,
3543
- store.getNotificationSettings,
3544
- store.getNotificationSettings,
3545
- selector
3546
- );
3547
- return React5.useMemo(() => {
3548
- return [settings, updateRoomNotificationSettings];
3549
- }, [settings, updateRoomNotificationSettings]);
3550
- }
3551
3529
  function createRoomContext(client) {
3552
3530
  return getOrCreateRoomContextBundle(client);
3553
3531
  }
3554
3532
  function generateQueryKey(roomId, options) {
3555
3533
  return `${roomId}-${stringify2(options ?? {})}`;
3556
3534
  }
3557
- function getVersionsQueryKey(roomId) {
3558
- return `${roomId}-VERSIONS`;
3559
- }
3560
3535
  var _RoomProvider = RoomProvider;
3561
3536
  var _useBroadcastEvent = useBroadcastEvent;
3562
3537
  var _useOthersListener = useOthersListener;
@@ -3677,4 +3652,4 @@ export {
3677
3652
  _useStorageRoot,
3678
3653
  _useUpdateMyPresence
3679
3654
  };
3680
- //# sourceMappingURL=chunk-XK5NTOJJ.mjs.map
3655
+ //# sourceMappingURL=chunk-QC6HYSYS.mjs.map