@liveblocks/react 2.0.5 → 2.1.0

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.0.5";
3
+ var PKG_VERSION = "2.1.0";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -79,12 +79,14 @@ function useInitialUnlessFunction(latestValue) {
79
79
 
80
80
  // src/liveblocks.tsx
81
81
  var ClientContext = createContext(null);
82
- var missingUserError = new Error(
83
- "resolveUsers didn't return anything for this user ID."
84
- );
85
- var missingRoomInfoError = new Error(
86
- "resolveRoomsInfo didn't return anything for this room ID."
87
- );
82
+ function missingUserError(userId) {
83
+ return new Error(`resolveUsers didn't return anything for user '${userId}'`);
84
+ }
85
+ function missingRoomInfoError(roomId) {
86
+ return new Error(
87
+ `resolveRoomsInfo didn't return anything for room '${roomId}'`
88
+ );
89
+ }
88
90
  var _extras = /* @__PURE__ */ new WeakMap();
89
91
  var _bundles = /* @__PURE__ */ new WeakMap();
90
92
  var POLLING_INTERVAL = 60 * 1e3;
@@ -166,7 +168,7 @@ function makeExtrasForClient(client) {
166
168
  const internals = client[kInternal];
167
169
  const store = internals.cacheStore;
168
170
  const notifications = internals.notifications;
169
- let fetchInboxNotificationsRequest = null;
171
+ let fetchInboxNotifications$ = null;
170
172
  let lastRequestedAt;
171
173
  const poller = makePoller(
172
174
  () => notifications.getInboxNotifications({ since: lastRequestedAt }).then(
@@ -185,15 +187,15 @@ function makeExtrasForClient(client) {
185
187
  )
186
188
  );
187
189
  async function fetchInboxNotifications({ retryCount } = { retryCount: 0 }) {
188
- if (fetchInboxNotificationsRequest !== null) {
189
- return fetchInboxNotificationsRequest;
190
+ if (fetchInboxNotifications$ !== null) {
191
+ return fetchInboxNotifications$;
190
192
  }
191
193
  store.setQueryState(INBOX_NOTIFICATIONS_QUERY, {
192
194
  isLoading: true
193
195
  });
194
196
  try {
195
- fetchInboxNotificationsRequest = notifications.getInboxNotifications();
196
- const result = await fetchInboxNotificationsRequest;
197
+ fetchInboxNotifications$ = notifications.getInboxNotifications();
198
+ const result = await fetchInboxNotifications$;
197
199
  store.updateThreadsAndNotifications(
198
200
  result.threads,
199
201
  result.inboxNotifications,
@@ -206,7 +208,7 @@ function makeExtrasForClient(client) {
206
208
  }
207
209
  poller.start(POLLING_INTERVAL);
208
210
  } catch (er) {
209
- fetchInboxNotificationsRequest = null;
211
+ fetchInboxNotifications$ = null;
210
212
  retryError(() => {
211
213
  void fetchInboxNotifications({
212
214
  retryCount: retryCount + 1
@@ -469,7 +471,7 @@ function useUser_withClient(client, userId) {
469
471
  isLoading: state.isLoading,
470
472
  user: state.data,
471
473
  // Return an error if `undefined` was returned by `resolveUsers` for this user ID
472
- error: !state.isLoading && !state.data && !state.error ? missingUserError : state.error
474
+ error: !state.isLoading && !state.data && !state.error ? missingUserError(userId) : state.error
473
475
  } : { isLoading: true };
474
476
  }
475
477
  function useUserSuspense_withClient(client, userId) {
@@ -486,7 +488,7 @@ function useUserSuspense_withClient(client, userId) {
486
488
  throw userState.error;
487
489
  }
488
490
  if (!userState.data) {
489
- throw missingUserError;
491
+ throw missingUserError(userId);
490
492
  }
491
493
  const state = useSyncExternalStore(
492
494
  usersStore.subscribe,
@@ -517,7 +519,7 @@ function useRoomInfo_withClient(client, roomId) {
517
519
  isLoading: state.isLoading,
518
520
  info: state.data,
519
521
  // Return an error if `undefined` was returned by `resolveRoomsInfo` for this room ID
520
- error: !state.isLoading && !state.data && !state.error ? missingRoomInfoError : state.error
522
+ error: !state.isLoading && !state.data && !state.error ? missingRoomInfoError(roomId) : state.error
521
523
  } : { isLoading: true };
522
524
  }
523
525
  function useRoomInfoSuspense_withClient(client, roomId) {
@@ -534,7 +536,7 @@ function useRoomInfoSuspense_withClient(client, roomId) {
534
536
  throw roomInfoState.error;
535
537
  }
536
538
  if (!roomInfoState.data) {
537
- throw missingRoomInfoError;
539
+ throw missingRoomInfoError(roomId);
538
540
  }
539
541
  const state = useSyncExternalStore(
540
542
  roomsInfoStore.subscribe,
@@ -646,9 +648,9 @@ function useRoomInfo(roomId) {
646
648
  function useRoomInfoSuspense(roomId) {
647
649
  return useRoomInfoSuspense_withClient(useClient(), roomId);
648
650
  }
649
- var __1 = useInboxNotificationThread;
650
- var __2 = useUser;
651
- var __3 = useUserSuspense;
651
+ var _useInboxNotificationThread = useInboxNotificationThread;
652
+ var _useUser = useUser;
653
+ var _useUserSuspense = useUserSuspense;
652
654
 
653
655
  // src/comments/errors.ts
654
656
  var CreateThreadError = class extends Error {
@@ -820,6 +822,33 @@ function selectNotificationSettings(roomId, state) {
820
822
  return nn(notificationSettings[roomId]);
821
823
  }
822
824
 
825
+ // src/lib/use-polyfill.ts
826
+ var use = (
827
+ // React.use ||
828
+ (promise) => {
829
+ if (promise.status === "pending") {
830
+ throw promise;
831
+ } else if (promise.status === "fulfilled") {
832
+ return promise.value;
833
+ } else if (promise.status === "rejected") {
834
+ throw promise.reason;
835
+ } else {
836
+ promise.status = "pending";
837
+ promise.then(
838
+ (v) => {
839
+ promise.status = "fulfilled";
840
+ promise.value = v;
841
+ },
842
+ (e) => {
843
+ promise.status = "rejected";
844
+ promise.reason = e;
845
+ }
846
+ );
847
+ throw promise;
848
+ }
849
+ }
850
+ );
851
+
823
852
  // src/use-scroll-to-comment-on-load-effect.ts
824
853
  import * as React3 from "react";
825
854
  function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
@@ -1112,6 +1141,7 @@ function makeRoomContextBundle(client) {
1112
1141
  RoomProvider: RoomProvider_withImplicitLiveblocksProvider,
1113
1142
  useRoom,
1114
1143
  useStatus,
1144
+ useStorageStatus,
1115
1145
  useBatch,
1116
1146
  useBroadcastEvent,
1117
1147
  useOthersListener,
@@ -1152,6 +1182,7 @@ function makeRoomContextBundle(client) {
1152
1182
  RoomProvider: RoomProvider_withImplicitLiveblocksProvider,
1153
1183
  useRoom,
1154
1184
  useStatus,
1185
+ useStorageStatus: useStorageStatusSuspense,
1155
1186
  useBatch,
1156
1187
  useBroadcastEvent,
1157
1188
  useOthersListener,
@@ -1335,6 +1366,13 @@ function useStatus() {
1335
1366
  const getServerSnapshot = room.getStatus;
1336
1367
  return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
1337
1368
  }
1369
+ function useStorageStatus() {
1370
+ const room = useRoom();
1371
+ const subscribe = room.events.storageStatus.subscribe;
1372
+ const getSnapshot = room.getStorageStatus;
1373
+ const getServerSnapshot = room.getStorageStatus;
1374
+ return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
1375
+ }
1338
1376
  function useBatch() {
1339
1377
  return useRoom().batch;
1340
1378
  }
@@ -2282,60 +2320,57 @@ function ensureNotServerSide() {
2282
2320
  );
2283
2321
  }
2284
2322
  }
2285
- function useSuspendUntilPresenceLoaded() {
2286
- const room = useRoom();
2287
- if (room.getSelf() !== null) {
2288
- return;
2289
- }
2323
+ function useSuspendUntilPresenceReady() {
2290
2324
  ensureNotServerSide();
2291
- throw new Promise((res) => {
2292
- room.events.self.subscribeOnce(() => res());
2293
- room.events.status.subscribeOnce(() => res());
2294
- });
2325
+ const room = useRoom();
2326
+ use(room.waitUntilPresenceReady());
2295
2327
  }
2296
2328
  function useSelfSuspense(selector, isEqual) {
2297
- useSuspendUntilPresenceLoaded();
2329
+ useSuspendUntilPresenceReady();
2298
2330
  return useSelf(
2299
2331
  selector,
2300
2332
  isEqual
2301
2333
  );
2302
2334
  }
2303
2335
  function useOthersSuspense(selector, isEqual) {
2304
- useSuspendUntilPresenceLoaded();
2336
+ useSuspendUntilPresenceReady();
2305
2337
  return useOthers(
2306
2338
  selector,
2307
2339
  isEqual
2308
2340
  );
2309
2341
  }
2310
2342
  function useOthersConnectionIdsSuspense() {
2311
- useSuspendUntilPresenceLoaded();
2343
+ useSuspendUntilPresenceReady();
2312
2344
  return useOthersConnectionIds();
2313
2345
  }
2314
2346
  function useOthersMappedSuspense(itemSelector, itemIsEqual) {
2315
- useSuspendUntilPresenceLoaded();
2347
+ useSuspendUntilPresenceReady();
2316
2348
  return useOthersMapped(itemSelector, itemIsEqual);
2317
2349
  }
2318
2350
  function useOtherSuspense(connectionId, selector, isEqual) {
2319
- useSuspendUntilPresenceLoaded();
2351
+ useSuspendUntilPresenceReady();
2320
2352
  return useOther(connectionId, selector, isEqual);
2321
2353
  }
2322
- function useSuspendUntilStorageLoaded() {
2323
- const room = useRoom();
2324
- if (room.getStorageSnapshot() !== null) {
2325
- return;
2326
- }
2354
+ function useSuspendUntilStorageReady() {
2327
2355
  ensureNotServerSide();
2328
- throw new Promise((res) => {
2329
- room.events.storageDidLoad.subscribeOnce(() => res());
2330
- });
2356
+ const room = useRoom();
2357
+ use(room.waitUntilStorageReady());
2331
2358
  }
2332
2359
  function useStorageSuspense(selector, isEqual) {
2333
- useSuspendUntilStorageLoaded();
2360
+ useSuspendUntilStorageReady();
2334
2361
  return useStorage(
2335
2362
  selector,
2336
2363
  isEqual
2337
2364
  );
2338
2365
  }
2366
+ function useStorageStatusSuspense() {
2367
+ useSuspendUntilStorageReady();
2368
+ const room = useRoom();
2369
+ const subscribe = room.events.storageStatus.subscribe;
2370
+ const getSnapshot = room.getStorageStatus;
2371
+ const getServerSnapshot = room.getStorageStatus;
2372
+ return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
2373
+ }
2339
2374
  function useThreadsSuspense(options = {
2340
2375
  query: { metadata: {} }
2341
2376
  }) {
@@ -2434,13 +2469,21 @@ var _useOthersMappedSuspense = useOthersMappedSuspense;
2434
2469
  var _useThreads = useThreads;
2435
2470
  var _useThreadsSuspense = useThreadsSuspense;
2436
2471
  var _useOther = useOther;
2437
- var _useOthers = useOthers;
2472
+ function _useOthers(...args) {
2473
+ return useOthers(...args);
2474
+ }
2438
2475
  var _useOtherSuspense = useOtherSuspense;
2439
- var _useOthersSuspense = useOthersSuspense;
2476
+ function _useOthersSuspense(...args) {
2477
+ return useOthersSuspense(...args);
2478
+ }
2440
2479
  var _useStorage = useStorage;
2441
2480
  var _useStorageSuspense = useStorageSuspense;
2442
- var _useSelf = useSelf;
2443
- var _useSelfSuspense = useSelfSuspense;
2481
+ function _useSelf(...args) {
2482
+ return useSelf(...args);
2483
+ }
2484
+ function _useSelfSuspense(...args) {
2485
+ return useSelfSuspense(...args);
2486
+ }
2444
2487
  var _useStorageRoot = useStorageRoot;
2445
2488
  var _useUpdateMyPresence = useUpdateMyPresence;
2446
2489
 
@@ -2461,13 +2504,14 @@ export {
2461
2504
  useUnreadInboxNotificationsCountSuspense,
2462
2505
  useRoomInfo,
2463
2506
  useRoomInfoSuspense,
2464
- __1,
2465
- __2,
2466
- __3,
2507
+ _useInboxNotificationThread,
2508
+ _useUser,
2509
+ _useUserSuspense,
2467
2510
  CreateThreadError,
2468
2511
  selectedThreads,
2469
2512
  RoomContext,
2470
2513
  useStatus,
2514
+ useStorageStatus,
2471
2515
  useBatch,
2472
2516
  useLostConnectionListener,
2473
2517
  useErrorListener,
@@ -2487,6 +2531,7 @@ export {
2487
2531
  useRoomNotificationSettings,
2488
2532
  useUpdateRoomNotificationSettings,
2489
2533
  useOthersConnectionIdsSuspense,
2534
+ useStorageStatusSuspense,
2490
2535
  createRoomContext,
2491
2536
  _RoomProvider,
2492
2537
  _useBroadcastEvent,
@@ -2514,4 +2559,4 @@ export {
2514
2559
  _useStorageRoot,
2515
2560
  _useUpdateMyPresence
2516
2561
  };
2517
- //# sourceMappingURL=chunk-RJICDM5G.mjs.map
2562
+ //# sourceMappingURL=chunk-D4UC2JLP.mjs.map