@liveblocks/react 2.2.3-alpha2 → 2.4.0-test1

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.2.3-alpha2";
3
+ var PKG_VERSION = "2.4.0-test1";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -15,13 +15,15 @@ function ClientSideSuspense(props) {
15
15
 
16
16
  // src/liveblocks.tsx
17
17
  import {
18
+ assert,
18
19
  createClient,
19
20
  kInternal,
20
21
  makePoller,
22
+ memoizeOnSuccess,
23
+ nanoid,
21
24
  raise,
22
25
  shallow
23
26
  } from "@liveblocks/core";
24
- import { nanoid } from "nanoid";
25
27
  import React2, {
26
28
  createContext,
27
29
  useCallback as useCallback2,
@@ -43,6 +45,7 @@ function selectedInboxNotifications(state) {
43
45
  }
44
46
 
45
47
  // src/lib/retry-error.ts
48
+ import { wait } from "@liveblocks/core";
46
49
  var MAX_ERROR_RETRY_COUNT = 5;
47
50
  var ERROR_RETRY_INTERVAL = 5e3;
48
51
  function retryError(action, retryCount) {
@@ -52,6 +55,23 @@ function retryError(action, retryCount) {
52
55
  void action();
53
56
  }, timeout);
54
57
  }
58
+ async function autoRetry(promiseFn, maxTries, backoff) {
59
+ const fallbackBackoff = backoff.length > 0 ? backoff[backoff.length - 1] : 0;
60
+ let attempt = 0;
61
+ while (true) {
62
+ attempt++;
63
+ const promise = promiseFn();
64
+ try {
65
+ return await promise;
66
+ } catch (err) {
67
+ if (attempt >= maxTries) {
68
+ throw new Error(`Failed after ${maxTries} attempts: ${String(err)}`);
69
+ }
70
+ }
71
+ const delay = backoff[attempt - 1] ?? fallbackBackoff;
72
+ await wait(delay);
73
+ }
74
+ }
55
75
 
56
76
  // src/lib/use-initial.ts
57
77
  import { useCallback, useReducer } from "react";
@@ -83,6 +103,33 @@ function useInitialUnlessFunction(latestValue) {
83
103
  }
84
104
  }
85
105
 
106
+ // src/lib/use-polyfill.ts
107
+ var use = (
108
+ // React.use ||
109
+ (promise) => {
110
+ if (promise.status === "pending") {
111
+ throw promise;
112
+ } else if (promise.status === "fulfilled") {
113
+ return promise.value;
114
+ } else if (promise.status === "rejected") {
115
+ throw promise.reason;
116
+ } else {
117
+ promise.status = "pending";
118
+ promise.then(
119
+ (v) => {
120
+ promise.status = "fulfilled";
121
+ promise.value = v;
122
+ },
123
+ (e) => {
124
+ promise.status = "rejected";
125
+ promise.reason = e;
126
+ }
127
+ );
128
+ throw promise;
129
+ }
130
+ }
131
+ );
132
+
86
133
  // src/liveblocks.tsx
87
134
  var ClientContext = createContext(null);
88
135
  function missingUserError(userId) {
@@ -115,12 +162,6 @@ function selectorFor_useInboxNotifications(state) {
115
162
  isLoading: false
116
163
  };
117
164
  }
118
- function selectorFor_useInboxNotificationsSuspense(state) {
119
- return {
120
- inboxNotifications: selectedInboxNotifications(state),
121
- isLoading: false
122
- };
123
- }
124
165
  function selectUnreadInboxNotificationsCount(state) {
125
166
  let count = 0;
126
167
  for (const notification of selectedInboxNotifications(state)) {
@@ -148,10 +189,40 @@ function selectorFor_useUnreadInboxNotificationsCount(state) {
148
189
  count: selectUnreadInboxNotificationsCount(state)
149
190
  };
150
191
  }
151
- function selectorFor_useUnreadInboxNotificationsCountSuspense(state) {
192
+ function selectorFor_useUser(state, userId) {
193
+ if (state === void 0 || state?.isLoading) {
194
+ return state ?? { isLoading: true };
195
+ }
196
+ if (state.error) {
197
+ return state;
198
+ }
199
+ if (!state.data) {
200
+ return {
201
+ isLoading: false,
202
+ error: missingUserError(userId)
203
+ };
204
+ }
152
205
  return {
153
206
  isLoading: false,
154
- count: selectUnreadInboxNotificationsCount(state)
207
+ user: state.data
208
+ };
209
+ }
210
+ function selectorFor_useRoomInfo(state, roomId) {
211
+ if (state === void 0 || state?.isLoading) {
212
+ return state ?? { isLoading: true };
213
+ }
214
+ if (state.error) {
215
+ return state;
216
+ }
217
+ if (!state.data) {
218
+ return {
219
+ isLoading: false,
220
+ error: missingRoomInfoError(roomId)
221
+ };
222
+ }
223
+ return {
224
+ isLoading: false,
225
+ info: state.data
155
226
  };
156
227
  }
157
228
  function getOrCreateContextBundle(client) {
@@ -173,94 +244,96 @@ function getExtrasForClient(client) {
173
244
  function makeExtrasForClient(client) {
174
245
  const internals = client[kInternal];
175
246
  const store = internals.cacheStore;
176
- const notifications = internals.notifications;
177
- let fetchInboxNotifications$ = null;
178
247
  let lastRequestedAt;
179
- const poller = makePoller(
180
- () => notifications.getInboxNotifications({ since: lastRequestedAt }).then(
181
- (result) => {
182
- lastRequestedAt = result.meta.requestedAt;
183
- store.updateThreadsAndNotifications(
184
- result.threads,
185
- result.inboxNotifications,
186
- result.deletedThreads,
187
- result.deletedInboxNotifications,
188
- INBOX_NOTIFICATIONS_QUERY
189
- );
190
- },
191
- () => {
248
+ async function fetchInboxNotifications() {
249
+ if (lastRequestedAt === void 0) {
250
+ const result = await client.getInboxNotifications();
251
+ store.updateThreadsAndNotifications(
252
+ result.threads,
253
+ result.inboxNotifications,
254
+ [],
255
+ [],
256
+ INBOX_NOTIFICATIONS_QUERY
257
+ );
258
+ lastRequestedAt = result.requestedAt;
259
+ } else {
260
+ const result = await client.getInboxNotificationsSince({
261
+ since: lastRequestedAt
262
+ });
263
+ store.updateThreadsAndNotifications(
264
+ result.threads.modified,
265
+ result.inboxNotifications.modified,
266
+ result.threads.deleted,
267
+ result.inboxNotifications.deleted,
268
+ INBOX_NOTIFICATIONS_QUERY
269
+ );
270
+ if (lastRequestedAt < result.requestedAt) {
271
+ lastRequestedAt = result.requestedAt;
192
272
  }
193
- )
194
- );
195
- async function fetchInboxNotifications({ retryCount } = { retryCount: 0 }) {
196
- if (fetchInboxNotifications$ !== null) {
197
- return fetchInboxNotifications$;
198
273
  }
274
+ }
275
+ let pollerSubscribers = 0;
276
+ const poller = makePoller(async () => {
277
+ try {
278
+ await waitUntilInboxNotificationsLoaded();
279
+ await fetchInboxNotifications();
280
+ } catch (err) {
281
+ console.warn(`Polling new inbox notifications failed: ${String(err)}`);
282
+ }
283
+ });
284
+ const waitUntilInboxNotificationsLoaded = memoizeOnSuccess(async () => {
199
285
  store.setQueryState(INBOX_NOTIFICATIONS_QUERY, {
200
286
  isLoading: true
201
287
  });
202
288
  try {
203
- fetchInboxNotifications$ = notifications.getInboxNotifications();
204
- const result = await fetchInboxNotifications$;
205
- store.updateThreadsAndNotifications(
206
- result.threads,
207
- result.inboxNotifications,
208
- result.deletedThreads,
209
- result.deletedInboxNotifications,
210
- INBOX_NOTIFICATIONS_QUERY
289
+ await autoRetry(
290
+ () => fetchInboxNotifications(),
291
+ 5,
292
+ [5e3, 5e3, 1e4, 15e3]
211
293
  );
212
- if (lastRequestedAt === void 0 || lastRequestedAt > result.meta.requestedAt) {
213
- lastRequestedAt = result.meta.requestedAt;
214
- }
215
- poller.start(POLLING_INTERVAL);
216
- } catch (er) {
217
- fetchInboxNotifications$ = null;
218
- retryError(() => {
219
- void fetchInboxNotifications({
220
- retryCount: retryCount + 1
221
- });
222
- }, retryCount);
294
+ } catch (err) {
223
295
  store.setQueryState(INBOX_NOTIFICATIONS_QUERY, {
224
296
  isLoading: false,
225
- error: er
297
+ error: err
226
298
  });
299
+ throw err;
227
300
  }
228
- return;
301
+ });
302
+ function loadInboxNotifications() {
303
+ void waitUntilInboxNotificationsLoaded().catch(() => {
304
+ });
229
305
  }
230
- let inboxNotificationsSubscribers = 0;
231
- function useSubscribeToInboxNotificationsEffect(options) {
232
- const autoFetch = useInitial(options?.autoFetch ?? true);
306
+ function useEnableInboxNotificationsPolling() {
233
307
  useEffect3(() => {
234
- if (autoFetch) {
235
- void fetchInboxNotifications();
236
- }
237
- inboxNotificationsSubscribers++;
308
+ pollerSubscribers++;
238
309
  poller.start(POLLING_INTERVAL);
239
310
  return () => {
240
- if (inboxNotificationsSubscribers <= 0) {
311
+ if (pollerSubscribers <= 0) {
241
312
  console.warn(
242
313
  `Internal unexpected behavior. Cannot decrease subscriber count for query "${INBOX_NOTIFICATIONS_QUERY}"`
243
314
  );
244
315
  return;
245
316
  }
246
- inboxNotificationsSubscribers--;
247
- if (inboxNotificationsSubscribers <= 0) {
317
+ pollerSubscribers--;
318
+ if (pollerSubscribers <= 0) {
248
319
  poller.stop();
249
320
  }
250
321
  };
251
- }, [autoFetch]);
322
+ }, []);
252
323
  }
253
324
  return {
254
325
  store,
255
- notifications,
256
- fetchInboxNotifications,
257
- useSubscribeToInboxNotificationsEffect
326
+ useEnableInboxNotificationsPolling,
327
+ waitUntilInboxNotificationsLoaded,
328
+ loadInboxNotifications
258
329
  };
259
330
  }
260
331
  function makeLiveblocksContextBundle(client) {
261
332
  const useInboxNotificationThread2 = (inboxNotificationId) => useInboxNotificationThread_withClient(client, inboxNotificationId);
262
333
  const useMarkInboxNotificationAsRead2 = () => useMarkInboxNotificationAsRead_withClient(client);
263
334
  const useMarkAllInboxNotificationsAsRead2 = () => useMarkAllInboxNotificationsAsRead_withClient(client);
335
+ const useDeleteInboxNotification2 = () => useDeleteInboxNotification_withClient(client);
336
+ const useDeleteAllInboxNotifications2 = () => useDeleteAllInboxNotifications_withClient(client);
264
337
  function LiveblocksProvider2(props) {
265
338
  useEnsureNoLiveblocksProvider();
266
339
  return /* @__PURE__ */ React2.createElement(ClientContext.Provider, { value: client }, props.children);
@@ -272,6 +345,8 @@ function makeLiveblocksContextBundle(client) {
272
345
  useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCount_withClient(client),
273
346
  useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
274
347
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
348
+ useDeleteInboxNotification: useDeleteInboxNotification2,
349
+ useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
275
350
  useInboxNotificationThread: useInboxNotificationThread2,
276
351
  ...shared.classic,
277
352
  suspense: {
@@ -280,6 +355,8 @@ function makeLiveblocksContextBundle(client) {
280
355
  useUnreadInboxNotificationsCount: () => useUnreadInboxNotificationsCountSuspense_withClient(client),
281
356
  useMarkInboxNotificationAsRead: useMarkInboxNotificationAsRead2,
282
357
  useMarkAllInboxNotificationsAsRead: useMarkAllInboxNotificationsAsRead2,
358
+ useDeleteInboxNotification: useDeleteInboxNotification2,
359
+ useDeleteAllInboxNotifications: useDeleteAllInboxNotifications2,
283
360
  useInboxNotificationThread: useInboxNotificationThread2,
284
361
  ...shared.suspense
285
362
  }
@@ -287,8 +364,11 @@ function makeLiveblocksContextBundle(client) {
287
364
  return bundle;
288
365
  }
289
366
  function useInboxNotifications_withClient(client) {
290
- const { store, useSubscribeToInboxNotificationsEffect } = getExtrasForClient(client);
291
- useSubscribeToInboxNotificationsEffect();
367
+ const { loadInboxNotifications, store, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
368
+ useEffect3(() => {
369
+ loadInboxNotifications();
370
+ }, [loadInboxNotifications]);
371
+ useEnableInboxNotificationsPolling();
292
372
  return useSyncExternalStoreWithSelector(
293
373
  store.subscribe,
294
374
  store.get,
@@ -298,30 +378,19 @@ function useInboxNotifications_withClient(client) {
298
378
  );
299
379
  }
300
380
  function useInboxNotificationsSuspense_withClient(client) {
301
- const {
302
- store,
303
- fetchInboxNotifications,
304
- useSubscribeToInboxNotificationsEffect
305
- } = getExtrasForClient(client);
306
- const query = store.get().queries[INBOX_NOTIFICATIONS_QUERY];
307
- if (query === void 0 || query.isLoading) {
308
- throw fetchInboxNotifications();
309
- }
310
- if (query.error !== void 0) {
311
- throw query.error;
312
- }
313
- useSubscribeToInboxNotificationsEffect({ autoFetch: false });
314
- return useSyncExternalStoreWithSelector(
315
- store.subscribe,
316
- store.get,
317
- store.get,
318
- selectorFor_useInboxNotificationsSuspense,
319
- shallow
320
- );
381
+ const { waitUntilInboxNotificationsLoaded } = getExtrasForClient(client);
382
+ use(waitUntilInboxNotificationsLoaded());
383
+ const result = useInboxNotifications_withClient(client);
384
+ assert(!result.error, "Did not expect error");
385
+ assert(!result.isLoading, "Did not expect loading");
386
+ return result;
321
387
  }
322
388
  function useUnreadInboxNotificationsCount_withClient(client) {
323
- const { store, useSubscribeToInboxNotificationsEffect } = getExtrasForClient(client);
324
- useSubscribeToInboxNotificationsEffect();
389
+ const { store, loadInboxNotifications, useEnableInboxNotificationsPolling } = getExtrasForClient(client);
390
+ useEffect3(() => {
391
+ loadInboxNotifications();
392
+ }, [loadInboxNotifications]);
393
+ useEnableInboxNotificationsPolling();
325
394
  return useSyncExternalStoreWithSelector(
326
395
  store.subscribe,
327
396
  store.get,
@@ -331,28 +400,17 @@ function useUnreadInboxNotificationsCount_withClient(client) {
331
400
  );
332
401
  }
333
402
  function useUnreadInboxNotificationsCountSuspense_withClient(client) {
334
- const {
335
- store,
336
- fetchInboxNotifications,
337
- useSubscribeToInboxNotificationsEffect
338
- } = getExtrasForClient(client);
339
- const query = store.get().queries[INBOX_NOTIFICATIONS_QUERY];
340
- if (query === void 0 || query.isLoading) {
341
- throw fetchInboxNotifications();
342
- }
343
- useSubscribeToInboxNotificationsEffect({ autoFetch: false });
344
- return useSyncExternalStoreWithSelector(
345
- store.subscribe,
346
- store.get,
347
- store.get,
348
- selectorFor_useUnreadInboxNotificationsCountSuspense,
349
- shallow
350
- );
403
+ const { waitUntilInboxNotificationsLoaded } = getExtrasForClient(client);
404
+ use(waitUntilInboxNotificationsLoaded());
405
+ const result = useUnreadInboxNotificationsCount_withClient(client);
406
+ assert(!result.isLoading, "Did not expect loading");
407
+ assert(!result.error, "Did not expect error");
408
+ return result;
351
409
  }
352
410
  function useMarkInboxNotificationAsRead_withClient(client) {
353
411
  return useCallback2(
354
412
  (inboxNotificationId) => {
355
- const { store, notifications } = getExtrasForClient(client);
413
+ const { store } = getExtrasForClient(client);
356
414
  const optimisticUpdateId = nanoid();
357
415
  const readAt = /* @__PURE__ */ new Date();
358
416
  store.pushOptimisticUpdate({
@@ -361,7 +419,7 @@ function useMarkInboxNotificationAsRead_withClient(client) {
361
419
  inboxNotificationId,
362
420
  readAt
363
421
  });
364
- notifications.markInboxNotificationAsRead(inboxNotificationId).then(
422
+ client.markInboxNotificationAsRead(inboxNotificationId).then(
365
423
  () => {
366
424
  store.set((state) => {
367
425
  const existingNotification = state.inboxNotifications[inboxNotificationId];
@@ -403,15 +461,15 @@ function useMarkInboxNotificationAsRead_withClient(client) {
403
461
  }
404
462
  function useMarkAllInboxNotificationsAsRead_withClient(client) {
405
463
  return useCallback2(() => {
406
- const { store, notifications } = getExtrasForClient(client);
464
+ const { store } = getExtrasForClient(client);
407
465
  const optimisticUpdateId = nanoid();
408
466
  const readAt = /* @__PURE__ */ new Date();
409
467
  store.pushOptimisticUpdate({
410
- type: "mark-inbox-notifications-as-read",
468
+ type: "mark-all-inbox-notifications-as-read",
411
469
  id: optimisticUpdateId,
412
470
  readAt
413
471
  });
414
- notifications.markAllInboxNotificationsAsRead().then(
472
+ client.markAllInboxNotificationsAsRead().then(
415
473
  () => {
416
474
  store.set((state) => ({
417
475
  ...state,
@@ -439,6 +497,84 @@ function useMarkAllInboxNotificationsAsRead_withClient(client) {
439
497
  );
440
498
  }, [client]);
441
499
  }
500
+ function useDeleteInboxNotification_withClient(client) {
501
+ return useCallback2(
502
+ (inboxNotificationId) => {
503
+ const { store } = getExtrasForClient(client);
504
+ const optimisticUpdateId = nanoid();
505
+ const deletedAt = /* @__PURE__ */ new Date();
506
+ store.pushOptimisticUpdate({
507
+ type: "delete-inbox-notification",
508
+ id: optimisticUpdateId,
509
+ inboxNotificationId,
510
+ deletedAt
511
+ });
512
+ client.deleteInboxNotification(inboxNotificationId).then(
513
+ () => {
514
+ store.set((state) => {
515
+ const existingNotification = state.inboxNotifications[inboxNotificationId];
516
+ if (existingNotification === void 0) {
517
+ return {
518
+ ...state,
519
+ optimisticUpdates: state.optimisticUpdates.filter(
520
+ (update) => update.id !== optimisticUpdateId
521
+ )
522
+ };
523
+ }
524
+ const { [inboxNotificationId]: _, ...inboxNotifications } = state.inboxNotifications;
525
+ return {
526
+ ...state,
527
+ inboxNotifications,
528
+ optimisticUpdates: state.optimisticUpdates.filter(
529
+ (update) => update.id !== optimisticUpdateId
530
+ )
531
+ };
532
+ });
533
+ },
534
+ () => {
535
+ store.set((state) => ({
536
+ ...state,
537
+ optimisticUpdates: state.optimisticUpdates.filter(
538
+ (update) => update.id !== optimisticUpdateId
539
+ )
540
+ }));
541
+ }
542
+ );
543
+ },
544
+ [client]
545
+ );
546
+ }
547
+ function useDeleteAllInboxNotifications_withClient(client) {
548
+ return useCallback2(() => {
549
+ const { store } = getExtrasForClient(client);
550
+ const optimisticUpdateId = nanoid();
551
+ const deletedAt = /* @__PURE__ */ new Date();
552
+ store.pushOptimisticUpdate({
553
+ type: "delete-all-inbox-notifications",
554
+ id: optimisticUpdateId,
555
+ deletedAt
556
+ });
557
+ client.deleteAllInboxNotifications().then(
558
+ () => {
559
+ store.set((state) => ({
560
+ ...state,
561
+ inboxNotifications: {},
562
+ optimisticUpdates: state.optimisticUpdates.filter(
563
+ (update) => update.id !== optimisticUpdateId
564
+ )
565
+ }));
566
+ },
567
+ () => {
568
+ store.set((state) => ({
569
+ ...state,
570
+ optimisticUpdates: state.optimisticUpdates.filter(
571
+ (update) => update.id !== optimisticUpdateId
572
+ )
573
+ }));
574
+ }
575
+ );
576
+ }, [client]);
577
+ }
442
578
  function useInboxNotificationThread_withClient(client, inboxNotificationId) {
443
579
  const { store } = getExtrasForClient(client);
444
580
  const selector = useCallback2(
@@ -472,17 +608,17 @@ function useUser_withClient(client, userId) {
472
608
  useEffect3(() => {
473
609
  void usersStore.get(userId);
474
610
  }, [usersStore, userId]);
475
- const state = useSyncExternalStore(
611
+ const selector = useCallback2(
612
+ (state) => selectorFor_useUser(state, userId),
613
+ [userId]
614
+ );
615
+ return useSyncExternalStoreWithSelector(
476
616
  usersStore.subscribe,
477
617
  getUserState,
478
- getUserState
618
+ getUserState,
619
+ selector,
620
+ shallow
479
621
  );
480
- return state ? {
481
- isLoading: state.isLoading,
482
- user: state.data,
483
- // Return an error if `undefined` was returned by `resolveUsers` for this user ID
484
- error: !state.isLoading && !state.data && !state.error ? missingUserError(userId) : state.error
485
- } : { isLoading: true };
486
622
  }
487
623
  function useUserSuspense_withClient(client, userId) {
488
624
  const usersStore = client[kInternal].usersStore;
@@ -505,10 +641,13 @@ function useUserSuspense_withClient(client, userId) {
505
641
  getUserState,
506
642
  getUserState
507
643
  );
644
+ assert(state !== void 0, "Unexpected missing state");
645
+ assert(!state.isLoading, "Unexpected loading state");
646
+ assert(!state.error, "Unexpected error state");
508
647
  return {
509
648
  isLoading: false,
510
- user: state?.data,
511
- error: state?.error
649
+ user: state.data,
650
+ error: void 0
512
651
  };
513
652
  }
514
653
  function useRoomInfo_withClient(client, roomId) {
@@ -517,20 +656,20 @@ function useRoomInfo_withClient(client, roomId) {
517
656
  () => roomsInfoStore.getState(roomId),
518
657
  [roomsInfoStore, roomId]
519
658
  );
659
+ const selector = useCallback2(
660
+ (state) => selectorFor_useRoomInfo(state, roomId),
661
+ [roomId]
662
+ );
520
663
  useEffect3(() => {
521
664
  void roomsInfoStore.get(roomId);
522
665
  }, [roomsInfoStore, roomId]);
523
- const state = useSyncExternalStore(
666
+ return useSyncExternalStoreWithSelector(
524
667
  roomsInfoStore.subscribe,
525
668
  getRoomInfoState,
526
- getRoomInfoState
669
+ getRoomInfoState,
670
+ selector,
671
+ shallow
527
672
  );
528
- return state ? {
529
- isLoading: state.isLoading,
530
- info: state.data,
531
- // Return an error if `undefined` was returned by `resolveRoomsInfo` for this room ID
532
- error: !state.isLoading && !state.data && !state.error ? missingRoomInfoError(roomId) : state.error
533
- } : { isLoading: true };
534
673
  }
535
674
  function useRoomInfoSuspense_withClient(client, roomId) {
536
675
  const roomsInfoStore = client[kInternal].roomsInfoStore;
@@ -553,10 +692,14 @@ function useRoomInfoSuspense_withClient(client, roomId) {
553
692
  getRoomInfoState,
554
693
  getRoomInfoState
555
694
  );
695
+ assert(state !== void 0, "Unexpected missing state");
696
+ assert(!state.isLoading, "Unexpected loading state");
697
+ assert(!state.error, "Unexpected error state");
698
+ assert(state.data !== void 0, "Unexpected missing room info data");
556
699
  return {
557
700
  isLoading: false,
558
- info: state?.data,
559
- error: state?.error
701
+ info: state.data,
702
+ error: void 0
560
703
  };
561
704
  }
562
705
  function createSharedContext(client) {
@@ -641,6 +784,12 @@ function useMarkAllInboxNotificationsAsRead() {
641
784
  function useMarkInboxNotificationAsRead() {
642
785
  return useMarkInboxNotificationAsRead_withClient(useClient());
643
786
  }
787
+ function useDeleteAllInboxNotifications() {
788
+ return useDeleteAllInboxNotifications_withClient(useClient());
789
+ }
790
+ function useDeleteInboxNotification() {
791
+ return useDeleteInboxNotification_withClient(useClient());
792
+ }
644
793
  function useUnreadInboxNotificationsCount() {
645
794
  return useUnreadInboxNotificationsCount_withClient(useClient());
646
795
  }
@@ -777,6 +926,9 @@ function selectedThreads(roomId, state, options) {
777
926
  }
778
927
  const query = options.query;
779
928
  if (!query) return true;
929
+ if (query.resolved !== void 0 && thread.resolved !== query.resolved) {
930
+ return false;
931
+ }
780
932
  for (const key in query.metadata) {
781
933
  const metadataValue = thread.metadata[key];
782
934
  const filterValue = query.metadata[key];
@@ -811,36 +963,24 @@ import {
811
963
  addReaction,
812
964
  CommentsApiError,
813
965
  console as console2,
966
+ createCommentId,
967
+ createThreadId,
814
968
  deleteComment,
815
969
  deprecateIf,
816
970
  errorIf,
817
971
  kInternal as kInternal2,
818
972
  makeEventSource,
819
973
  makePoller as makePoller2,
974
+ nanoid as nanoid2,
820
975
  NotificationsApiError,
821
976
  removeReaction,
822
977
  ServerMsgCode,
823
978
  stringify,
824
979
  upsertComment
825
980
  } from "@liveblocks/core";
826
- import { nanoid as nanoid3 } from "nanoid";
827
981
  import * as React4 from "react";
828
982
  import { useSyncExternalStoreWithSelector as useSyncExternalStoreWithSelector2 } from "use-sync-external-store/shim/with-selector.js";
829
983
 
830
- // src/comments/lib/createIds.ts
831
- import { nanoid as nanoid2 } from "nanoid";
832
- var THREAD_ID_PREFIX = "th";
833
- var COMMENT_ID_PREFIX = "cm";
834
- function createOptimisticId(prefix) {
835
- return `${prefix}_${nanoid2()}`;
836
- }
837
- function createThreadId() {
838
- return createOptimisticId(THREAD_ID_PREFIX);
839
- }
840
- function createCommentId() {
841
- return createOptimisticId(COMMENT_ID_PREFIX);
842
- }
843
-
844
984
  // src/comments/lib/select-notification-settings.ts
845
985
  import {
846
986
  applyOptimisticUpdates as applyOptimisticUpdates3,
@@ -851,33 +991,6 @@ function selectNotificationSettings(roomId, state) {
851
991
  return nn(notificationSettings[roomId]);
852
992
  }
853
993
 
854
- // src/lib/use-polyfill.ts
855
- var use = (
856
- // React.use ||
857
- (promise) => {
858
- if (promise.status === "pending") {
859
- throw promise;
860
- } else if (promise.status === "fulfilled") {
861
- return promise.value;
862
- } else if (promise.status === "rejected") {
863
- throw promise.reason;
864
- } else {
865
- promise.status = "pending";
866
- promise.then(
867
- (v) => {
868
- promise.status = "fulfilled";
869
- promise.value = v;
870
- },
871
- (e) => {
872
- promise.status = "rejected";
873
- promise.reason = e;
874
- }
875
- );
876
- throw promise;
877
- }
878
- }
879
- );
880
-
881
994
  // src/use-scroll-to-comment-on-load-effect.ts
882
995
  import * as React3 from "react";
883
996
  function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
@@ -1052,18 +1165,17 @@ function makeExtrasForClient2(client) {
1052
1165
  if (isFetchingThreadsUpdates === true) return;
1053
1166
  try {
1054
1167
  requestStatusByRoom.set(room.id, true);
1055
- const commentsAPI = room[kInternal2].comments;
1056
- const updates = await commentsAPI.getThreads({ since });
1168
+ const updates = await room.getThreadsSince({ since });
1057
1169
  setTimeout(() => {
1058
1170
  requestStatusByRoom.set(room.id, false);
1059
1171
  }, DEFAULT_DEDUPING_INTERVAL);
1060
1172
  store.updateThreadsAndNotifications(
1061
- updates.threads,
1062
- updates.inboxNotifications,
1063
- updates.deletedThreads,
1064
- updates.deletedInboxNotifications
1173
+ updates.threads.modified,
1174
+ updates.inboxNotifications.modified,
1175
+ updates.threads.deleted,
1176
+ updates.inboxNotifications.deleted
1065
1177
  );
1066
- lastRequestedAtByRoom.set(room.id, updates.meta.requestedAt);
1178
+ lastRequestedAtByRoom.set(room.id, updates.requestedAt);
1067
1179
  } catch (err) {
1068
1180
  requestStatusByRoom.set(room.id, false);
1069
1181
  return;
@@ -1072,8 +1184,7 @@ function makeExtrasForClient2(client) {
1072
1184
  async function getThreadsAndInboxNotifications(room, queryKey, options, { retryCount } = { retryCount: 0 }) {
1073
1185
  const existingRequest = requestsByQuery.get(queryKey);
1074
1186
  if (existingRequest !== void 0) return existingRequest;
1075
- const commentsAPI = room[kInternal2].comments;
1076
- const request = commentsAPI.getThreads(options);
1187
+ const request = room.getThreads(options);
1077
1188
  requestsByQuery.set(queryKey, request);
1078
1189
  store.setQueryState(queryKey, {
1079
1190
  isLoading: true
@@ -1082,14 +1193,15 @@ function makeExtrasForClient2(client) {
1082
1193
  const result = await request;
1083
1194
  store.updateThreadsAndNotifications(
1084
1195
  result.threads,
1196
+ // TODO: Figure out how to remove this casting
1085
1197
  result.inboxNotifications,
1086
- result.deletedThreads,
1087
- result.deletedInboxNotifications,
1198
+ [],
1199
+ [],
1088
1200
  queryKey
1089
1201
  );
1090
1202
  const lastRequestedAt = lastRequestedAtByRoom.get(room.id);
1091
- if (lastRequestedAt === void 0 || lastRequestedAt > result.meta.requestedAt) {
1092
- lastRequestedAtByRoom.set(room.id, result.meta.requestedAt);
1203
+ if (lastRequestedAt === void 0 || lastRequestedAt > result.requestedAt) {
1204
+ lastRequestedAtByRoom.set(room.id, result.requestedAt);
1093
1205
  }
1094
1206
  poller.start(POLLING_INTERVAL2);
1095
1207
  } catch (err) {
@@ -1110,7 +1222,7 @@ function makeExtrasForClient2(client) {
1110
1222
  const existingRequest = requestsByQuery.get(queryKey);
1111
1223
  if (existingRequest !== void 0) return existingRequest;
1112
1224
  try {
1113
- const request = room[kInternal2].notifications.getRoomNotificationSettings();
1225
+ const request = room.getNotificationSettings();
1114
1226
  requestsByQuery.set(queryKey, request);
1115
1227
  store.setQueryState(queryKey, {
1116
1228
  isLoading: true
@@ -1330,10 +1442,8 @@ function RoomProviderInner(props) {
1330
1442
  store.deleteThread(message.threadId);
1331
1443
  return;
1332
1444
  }
1333
- const info = await room[kInternal2].comments.getThread({
1334
- threadId: message.threadId
1335
- });
1336
- if (!info) {
1445
+ const info = await room.getThread(message.threadId);
1446
+ if (!info.thread) {
1337
1447
  store.deleteThread(message.threadId);
1338
1448
  return;
1339
1449
  }
@@ -1734,7 +1844,7 @@ function useCreateThread() {
1734
1844
  comments: [newComment],
1735
1845
  resolved: false
1736
1846
  };
1737
- const optimisticUpdateId = nanoid3();
1847
+ const optimisticUpdateId = nanoid2();
1738
1848
  const { store, onMutationFailure } = getExtrasForClient2(client);
1739
1849
  store.pushOptimisticUpdate({
1740
1850
  type: "create-thread",
@@ -1742,8 +1852,7 @@ function useCreateThread() {
1742
1852
  id: optimisticUpdateId,
1743
1853
  roomId: room.id
1744
1854
  });
1745
- const commentsAPI = room[kInternal2].comments;
1746
- commentsAPI.createThread({ threadId, commentId, body, metadata }).then(
1855
+ room.createThread({ threadId, commentId, body, metadata }).then(
1747
1856
  (thread) => {
1748
1857
  store.set((state) => ({
1749
1858
  ...state,
@@ -1778,7 +1887,7 @@ function useDeleteThread() {
1778
1887
  const room = useRoom();
1779
1888
  return React4.useCallback(
1780
1889
  (threadId) => {
1781
- const optimisticUpdateId = nanoid3();
1890
+ const optimisticUpdateId = nanoid2();
1782
1891
  const { store, onMutationFailure } = getExtrasForClient2(client);
1783
1892
  const thread = store.get().threads[threadId];
1784
1893
  const userId = getCurrentUserId(room);
@@ -1792,8 +1901,7 @@ function useDeleteThread() {
1792
1901
  threadId,
1793
1902
  deletedAt: /* @__PURE__ */ new Date()
1794
1903
  });
1795
- const commentsAPI = room[kInternal2].comments;
1796
- commentsAPI.deleteThread({ threadId }).then(
1904
+ room.deleteThread(threadId).then(
1797
1905
  () => {
1798
1906
  store.set((state) => {
1799
1907
  const existingThread = state.threads[threadId];
@@ -1837,7 +1945,7 @@ function useEditThreadMetadata() {
1837
1945
  const threadId = options.threadId;
1838
1946
  const metadata = options.metadata;
1839
1947
  const updatedAt = /* @__PURE__ */ new Date();
1840
- const optimisticUpdateId = nanoid3();
1948
+ const optimisticUpdateId = nanoid2();
1841
1949
  const { store, onMutationFailure } = getExtrasForClient2(client);
1842
1950
  store.pushOptimisticUpdate({
1843
1951
  type: "edit-thread-metadata",
@@ -1846,8 +1954,7 @@ function useEditThreadMetadata() {
1846
1954
  threadId,
1847
1955
  updatedAt
1848
1956
  });
1849
- const commentsAPI = room[kInternal2].comments;
1850
- commentsAPI.editThreadMetadata({ metadata, threadId }).then(
1957
+ room.editThreadMetadata({ metadata, threadId }).then(
1851
1958
  (metadata2) => {
1852
1959
  store.set((state) => {
1853
1960
  const existingThread = state.threads[threadId];
@@ -1916,14 +2023,14 @@ function useCreateComment() {
1916
2023
  body,
1917
2024
  reactions: []
1918
2025
  };
1919
- const optimisticUpdateId = nanoid3();
2026
+ const optimisticUpdateId = nanoid2();
1920
2027
  const { store, onMutationFailure } = getExtrasForClient2(client);
1921
2028
  store.pushOptimisticUpdate({
1922
2029
  type: "create-comment",
1923
2030
  comment,
1924
2031
  id: optimisticUpdateId
1925
2032
  });
1926
- room[kInternal2].comments.createComment({ threadId, commentId, body }).then(
2033
+ room.createComment({ threadId, commentId, body }).then(
1927
2034
  (newComment) => {
1928
2035
  store.set((state) => {
1929
2036
  const existingThread = state.threads[threadId];
@@ -1983,7 +2090,7 @@ function useEditComment() {
1983
2090
  return React4.useCallback(
1984
2091
  ({ threadId, commentId, body }) => {
1985
2092
  const editedAt = /* @__PURE__ */ new Date();
1986
- const optimisticUpdateId = nanoid3();
2093
+ const optimisticUpdateId = nanoid2();
1987
2094
  const { store, onMutationFailure } = getExtrasForClient2(client);
1988
2095
  const thread = store.get().threads[threadId];
1989
2096
  if (thread === void 0) {
@@ -2010,7 +2117,7 @@ function useEditComment() {
2010
2117
  },
2011
2118
  id: optimisticUpdateId
2012
2119
  });
2013
- room[kInternal2].comments.editComment({ threadId, commentId, body }).then(
2120
+ room.editComment({ threadId, commentId, body }).then(
2014
2121
  (editedComment) => {
2015
2122
  store.set((state) => {
2016
2123
  const existingThread = state.threads[threadId];
@@ -2055,7 +2162,7 @@ function useDeleteComment() {
2055
2162
  return React4.useCallback(
2056
2163
  ({ threadId, commentId }) => {
2057
2164
  const deletedAt = /* @__PURE__ */ new Date();
2058
- const optimisticUpdateId = nanoid3();
2165
+ const optimisticUpdateId = nanoid2();
2059
2166
  const { store, onMutationFailure } = getExtrasForClient2(client);
2060
2167
  store.pushOptimisticUpdate({
2061
2168
  type: "delete-comment",
@@ -2065,7 +2172,7 @@ function useDeleteComment() {
2065
2172
  id: optimisticUpdateId,
2066
2173
  roomId: room.id
2067
2174
  });
2068
- room[kInternal2].comments.deleteComment({ threadId, commentId }).then(
2175
+ room.deleteComment({ threadId, commentId }).then(
2069
2176
  () => {
2070
2177
  store.set((state) => {
2071
2178
  const existingThread = state.threads[threadId];
@@ -2109,7 +2216,7 @@ function useAddReaction() {
2109
2216
  ({ threadId, commentId, emoji }) => {
2110
2217
  const createdAt = /* @__PURE__ */ new Date();
2111
2218
  const userId = getCurrentUserId(room);
2112
- const optimisticUpdateId = nanoid3();
2219
+ const optimisticUpdateId = nanoid2();
2113
2220
  const { store, onMutationFailure } = getExtrasForClient2(client);
2114
2221
  store.pushOptimisticUpdate({
2115
2222
  type: "add-reaction",
@@ -2122,7 +2229,7 @@ function useAddReaction() {
2122
2229
  },
2123
2230
  id: optimisticUpdateId
2124
2231
  });
2125
- room[kInternal2].comments.addReaction({ threadId, commentId, emoji }).then(
2232
+ room.addReaction({ threadId, commentId, emoji }).then(
2126
2233
  (addedReaction) => {
2127
2234
  store.set((state) => {
2128
2235
  const existingThread = state.threads[threadId];
@@ -2171,7 +2278,7 @@ function useRemoveReaction() {
2171
2278
  ({ threadId, commentId, emoji }) => {
2172
2279
  const userId = getCurrentUserId(room);
2173
2280
  const removedAt = /* @__PURE__ */ new Date();
2174
- const optimisticUpdateId = nanoid3();
2281
+ const optimisticUpdateId = nanoid2();
2175
2282
  const { store, onMutationFailure } = getExtrasForClient2(client);
2176
2283
  store.pushOptimisticUpdate({
2177
2284
  type: "remove-reaction",
@@ -2182,7 +2289,7 @@ function useRemoveReaction() {
2182
2289
  removedAt,
2183
2290
  id: optimisticUpdateId
2184
2291
  });
2185
- room[kInternal2].comments.removeReaction({ threadId, commentId, emoji }).then(
2292
+ room.removeReaction({ threadId, commentId, emoji }).then(
2186
2293
  () => {
2187
2294
  store.set((state) => {
2188
2295
  const existingThread = state.threads[threadId];
@@ -2238,7 +2345,7 @@ function useMarkThreadAsRead() {
2238
2345
  (inboxNotification2) => inboxNotification2.kind === "thread" && inboxNotification2.threadId === threadId
2239
2346
  );
2240
2347
  if (!inboxNotification) return;
2241
- const optimisticUpdateId = nanoid3();
2348
+ const optimisticUpdateId = nanoid2();
2242
2349
  const now = /* @__PURE__ */ new Date();
2243
2350
  store.pushOptimisticUpdate({
2244
2351
  type: "mark-inbox-notification-as-read",
@@ -2246,7 +2353,7 @@ function useMarkThreadAsRead() {
2246
2353
  inboxNotificationId: inboxNotification.id,
2247
2354
  readAt: now
2248
2355
  });
2249
- room[kInternal2].notifications.markInboxNotificationAsRead(inboxNotification.id).then(
2356
+ room.markInboxNotificationAsRead(inboxNotification.id).then(
2250
2357
  () => {
2251
2358
  store.set((state) => ({
2252
2359
  ...state,
@@ -2282,7 +2389,7 @@ function useMarkThreadAsResolved() {
2282
2389
  const room = useRoom();
2283
2390
  return React4.useCallback(
2284
2391
  (threadId) => {
2285
- const optimisticUpdateId = nanoid3();
2392
+ const optimisticUpdateId = nanoid2();
2286
2393
  const updatedAt = /* @__PURE__ */ new Date();
2287
2394
  const { store, onMutationFailure } = getExtrasForClient2(client);
2288
2395
  store.pushOptimisticUpdate({
@@ -2291,8 +2398,7 @@ function useMarkThreadAsResolved() {
2291
2398
  threadId,
2292
2399
  updatedAt
2293
2400
  });
2294
- const commentsAPI = room[kInternal2].comments;
2295
- commentsAPI.markThreadAsResolved({ threadId }).then(
2401
+ room.markThreadAsResolved(threadId).then(
2296
2402
  () => {
2297
2403
  store.set((state) => {
2298
2404
  const existingThread = state.threads[threadId];
@@ -2348,7 +2454,7 @@ function useMarkThreadAsUnresolved() {
2348
2454
  const room = useRoom();
2349
2455
  return React4.useCallback(
2350
2456
  (threadId) => {
2351
- const optimisticUpdateId = nanoid3();
2457
+ const optimisticUpdateId = nanoid2();
2352
2458
  const updatedAt = /* @__PURE__ */ new Date();
2353
2459
  const { store, onMutationFailure } = getExtrasForClient2(client);
2354
2460
  store.pushOptimisticUpdate({
@@ -2357,8 +2463,7 @@ function useMarkThreadAsUnresolved() {
2357
2463
  threadId,
2358
2464
  updatedAt
2359
2465
  });
2360
- const commentsAPI = room[kInternal2].comments;
2361
- commentsAPI.markThreadAsUnresolved({ threadId }).then(
2466
+ room.markThreadAsUnresolved(threadId).then(
2362
2467
  () => {
2363
2468
  store.set((state) => {
2364
2469
  const existingThread = state.threads[threadId];
@@ -2478,7 +2583,7 @@ function useUpdateRoomNotificationSettings() {
2478
2583
  const room = useRoom();
2479
2584
  return React4.useCallback(
2480
2585
  (settings) => {
2481
- const optimisticUpdateId = nanoid3();
2586
+ const optimisticUpdateId = nanoid2();
2482
2587
  const { store, onMutationFailure } = getExtrasForClient2(client);
2483
2588
  store.pushOptimisticUpdate({
2484
2589
  id: optimisticUpdateId,
@@ -2486,7 +2591,7 @@ function useUpdateRoomNotificationSettings() {
2486
2591
  roomId: room.id,
2487
2592
  settings
2488
2593
  });
2489
- room[kInternal2].notifications.updateRoomNotificationSettings(settings).then(
2594
+ room.updateNotificationSettings(settings).then(
2490
2595
  (settings2) => {
2491
2596
  store.set((state) => ({
2492
2597
  ...state,
@@ -2693,6 +2798,8 @@ export {
2693
2798
  useInboxNotificationsSuspense,
2694
2799
  useMarkAllInboxNotificationsAsRead,
2695
2800
  useMarkInboxNotificationAsRead,
2801
+ useDeleteAllInboxNotifications,
2802
+ useDeleteInboxNotification,
2696
2803
  useUnreadInboxNotificationsCount,
2697
2804
  useUnreadInboxNotificationsCountSuspense,
2698
2805
  useRoomInfo,
@@ -2754,4 +2861,4 @@ export {
2754
2861
  _useStorageRoot,
2755
2862
  _useUpdateMyPresence
2756
2863
  };
2757
- //# sourceMappingURL=chunk-AKAI4UTH.mjs.map
2864
+ //# sourceMappingURL=chunk-2ITOEAYK.mjs.map