@liveblocks/react 1.6.0 → 1.7.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.
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.6.0";
8
+ var PKG_VERSION = "1.7.0";
9
9
  var PKG_FORMAT = "esm";
10
10
 
11
11
  // src/ClientSideSuspense.tsx
@@ -32,7 +32,7 @@ import * as React2 from "react";
32
32
  import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
33
33
 
34
34
  // src/comments/CommentsRoom.ts
35
- import { makeEventSource } from "@liveblocks/core";
35
+ import { CommentsApiError, console as console2, makeEventSource } from "@liveblocks/core";
36
36
  import { nanoid } from "nanoid";
37
37
  import { useEffect as useEffect2 } from "react";
38
38
  import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
@@ -136,6 +136,14 @@ function createThreadsManager() {
136
136
  }
137
137
  };
138
138
  }
139
+ function handleCommentsApiError(err) {
140
+ const message = `Request failed with status ${err.status}: ${err.message}`;
141
+ if (err.details?.error === "FORBIDDEN") {
142
+ const detailedMessage = [message, err.details.suggestion, err.details.docs].filter(Boolean).join("\n");
143
+ console2.error(detailedMessage);
144
+ }
145
+ return new Error(message);
146
+ }
139
147
  function createCommentsRoom(room, errorEventSource) {
140
148
  const manager = createThreadsManager();
141
149
  let timestamp = 0;
@@ -242,8 +250,12 @@ function createCommentsRoom(room, errorEventSource) {
242
250
  mutate(room.editThreadMetadata({ metadata, threadId }), {
243
251
  optimisticData
244
252
  }).catch((err) => {
253
+ if (!(err instanceof CommentsApiError)) {
254
+ throw err;
255
+ }
256
+ const error = handleCommentsApiError(err);
245
257
  errorEventSource.notify(
246
- new EditThreadMetadataError(err, {
258
+ new EditThreadMetadataError(error, {
247
259
  roomId: room.id,
248
260
  threadId,
249
261
  metadata
@@ -278,17 +290,21 @@ function createCommentsRoom(room, errorEventSource) {
278
290
  };
279
291
  mutate(room.createThread({ threadId, commentId, body, metadata }), {
280
292
  optimisticData: [...threads, newThread]
281
- }).catch(
282
- (er) => errorEventSource.notify(
283
- new CreateThreadError(er, {
293
+ }).catch((err) => {
294
+ if (!(err instanceof CommentsApiError)) {
295
+ throw err;
296
+ }
297
+ const error = handleCommentsApiError(err);
298
+ errorEventSource.notify(
299
+ new CreateThreadError(error, {
284
300
  roomId: room.id,
285
301
  threadId,
286
302
  commentId,
287
303
  body,
288
304
  metadata
289
305
  })
290
- )
291
- );
306
+ );
307
+ });
292
308
  return newThread;
293
309
  }
294
310
  function createComment({
@@ -316,16 +332,20 @@ function createCommentsRoom(room, errorEventSource) {
316
332
  );
317
333
  mutate(room.createComment({ threadId, commentId, body }), {
318
334
  optimisticData
319
- }).catch(
320
- (er) => errorEventSource.notify(
321
- new CreateCommentError(er, {
335
+ }).catch((err) => {
336
+ if (!(err instanceof CommentsApiError)) {
337
+ throw err;
338
+ }
339
+ const error = handleCommentsApiError(err);
340
+ errorEventSource.notify(
341
+ new CreateCommentError(error, {
322
342
  roomId: room.id,
323
343
  threadId,
324
344
  commentId,
325
345
  body
326
346
  })
327
- )
328
- );
347
+ );
348
+ });
329
349
  return comment;
330
350
  }
331
351
  function editComment({ threadId, commentId, body }) {
@@ -345,16 +365,20 @@ function createCommentsRoom(room, errorEventSource) {
345
365
  );
346
366
  mutate(room.editComment({ threadId, commentId, body }), {
347
367
  optimisticData
348
- }).catch(
349
- (er) => errorEventSource.notify(
350
- new EditCommentError(er, {
368
+ }).catch((err) => {
369
+ if (!(err instanceof CommentsApiError)) {
370
+ throw err;
371
+ }
372
+ const error = handleCommentsApiError(err);
373
+ errorEventSource.notify(
374
+ new EditCommentError(error, {
351
375
  roomId: room.id,
352
376
  threadId,
353
377
  commentId,
354
378
  body
355
379
  })
356
- )
357
- );
380
+ );
381
+ });
358
382
  }
359
383
  function deleteComment({ threadId, commentId }) {
360
384
  const threads = getThreads();
@@ -381,15 +405,19 @@ function createCommentsRoom(room, errorEventSource) {
381
405
  }
382
406
  mutate(room.deleteComment({ threadId, commentId }), {
383
407
  optimisticData: newThreads
384
- }).catch(
385
- (er) => errorEventSource.notify(
386
- new DeleteCommentError(er, {
408
+ }).catch((err) => {
409
+ if (!(err instanceof CommentsApiError)) {
410
+ throw err;
411
+ }
412
+ const error = handleCommentsApiError(err);
413
+ errorEventSource.notify(
414
+ new DeleteCommentError(error, {
387
415
  roomId: room.id,
388
416
  threadId,
389
417
  commentId
390
418
  })
391
- )
392
- );
419
+ );
420
+ });
393
421
  }
394
422
  function getCurrentUserId() {
395
423
  const self = room.getSelf();
@@ -527,8 +555,12 @@ function createCommentsRoom(room, errorEventSource) {
527
555
  mutate(room.addReaction({ threadId, commentId, emoji }), {
528
556
  optimisticData
529
557
  }).catch((err) => {
558
+ if (!(err instanceof CommentsApiError)) {
559
+ throw err;
560
+ }
561
+ const error = handleCommentsApiError(err);
530
562
  errorEventSource.notify(
531
- new AddReactionError(err, {
563
+ new AddReactionError(error, {
532
564
  roomId: room.id,
533
565
  threadId,
534
566
  commentId,
@@ -580,8 +612,12 @@ function createCommentsRoom(room, errorEventSource) {
580
612
  mutate(room.removeReaction({ threadId, commentId, emoji }), {
581
613
  optimisticData
582
614
  }).catch((err) => {
615
+ if (!(err instanceof CommentsApiError)) {
616
+ throw err;
617
+ }
618
+ const error = handleCommentsApiError(err);
583
619
  errorEventSource.notify(
584
- new RemoveReactionError(err, {
620
+ new RemoveReactionError(error, {
585
621
  roomId: room.id,
586
622
  threadId,
587
623
  commentId,
@@ -790,15 +826,6 @@ function warnIfNoResolveUsers(usersCache) {
790
826
  hasWarnedIfNoResolveUsers = true;
791
827
  }
792
828
  }
793
- var hasWarnedAboutCommentsBeta = false;
794
- function warnIfBetaCommentsHook() {
795
- if (!hasWarnedAboutCommentsBeta && process.env.NODE_ENV !== "production") {
796
- console.warn(
797
- "Comments is currently in private beta. Learn more at https://liveblocks.io/docs/products/comments."
798
- );
799
- hasWarnedAboutCommentsBeta = true;
800
- }
801
- }
802
829
  var ContextBundle = React2.createContext(null);
803
830
  function useRoomContextBundle() {
804
831
  const bundle = React2.useContext(ContextBundle);
@@ -1245,23 +1272,14 @@ function createRoomContext(client, options) {
1245
1272
  }
1246
1273
  function useThreads() {
1247
1274
  const room = useRoom();
1248
- React2.useEffect(() => {
1249
- warnIfBetaCommentsHook();
1250
- }, []);
1251
1275
  return getCommentsRoom(room).useThreads();
1252
1276
  }
1253
1277
  function useThreadsSuspense() {
1254
1278
  const room = useRoom();
1255
- React2.useEffect(() => {
1256
- warnIfBetaCommentsHook();
1257
- }, []);
1258
1279
  return getCommentsRoom(room).useThreadsSuspense();
1259
1280
  }
1260
1281
  function useCreateThread() {
1261
1282
  const room = useRoom();
1262
- React2.useEffect(() => {
1263
- warnIfBetaCommentsHook();
1264
- }, []);
1265
1283
  return React2.useCallback(
1266
1284
  (options2) => getCommentsRoom(room).createThread(options2),
1267
1285
  [room]
@@ -1269,9 +1287,6 @@ function createRoomContext(client, options) {
1269
1287
  }
1270
1288
  function useEditThreadMetadata() {
1271
1289
  const room = useRoom();
1272
- React2.useEffect(() => {
1273
- warnIfBetaCommentsHook();
1274
- }, []);
1275
1290
  return React2.useCallback(
1276
1291
  (options2) => getCommentsRoom(room).editThreadMetadata(options2),
1277
1292
  [room]
@@ -1279,9 +1294,6 @@ function createRoomContext(client, options) {
1279
1294
  }
1280
1295
  function useAddReaction() {
1281
1296
  const room = useRoom();
1282
- React2.useEffect(() => {
1283
- warnIfBetaCommentsHook();
1284
- }, []);
1285
1297
  return React2.useCallback(
1286
1298
  (options2) => getCommentsRoom(room).addReaction(options2),
1287
1299
  [room]
@@ -1289,9 +1301,6 @@ function createRoomContext(client, options) {
1289
1301
  }
1290
1302
  function useRemoveReaction() {
1291
1303
  const room = useRoom();
1292
- React2.useEffect(() => {
1293
- warnIfBetaCommentsHook();
1294
- }, []);
1295
1304
  return React2.useCallback(
1296
1305
  (options2) => getCommentsRoom(room).removeReaction(options2),
1297
1306
  [room]
@@ -1299,9 +1308,6 @@ function createRoomContext(client, options) {
1299
1308
  }
1300
1309
  function useCreateComment() {
1301
1310
  const room = useRoom();
1302
- React2.useEffect(() => {
1303
- warnIfBetaCommentsHook();
1304
- }, []);
1305
1311
  return React2.useCallback(
1306
1312
  (options2) => getCommentsRoom(room).createComment(options2),
1307
1313
  [room]
@@ -1309,9 +1315,6 @@ function createRoomContext(client, options) {
1309
1315
  }
1310
1316
  function useEditComment() {
1311
1317
  const room = useRoom();
1312
- React2.useEffect(() => {
1313
- warnIfBetaCommentsHook();
1314
- }, []);
1315
1318
  return React2.useCallback(
1316
1319
  (options2) => getCommentsRoom(room).editComment(options2),
1317
1320
  [room]
@@ -1319,9 +1322,6 @@ function createRoomContext(client, options) {
1319
1322
  }
1320
1323
  function useDeleteComment() {
1321
1324
  const room = useRoom();
1322
- React2.useEffect(() => {
1323
- warnIfBetaCommentsHook();
1324
- }, []);
1325
1325
  return React2.useCallback(
1326
1326
  (options2) => getCommentsRoom(room).deleteComment(options2),
1327
1327
  [room]