@liveblocks/react 1.10.0-beta1 → 1.10.0-beta2

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.10.0-beta1";
8
+ var PKG_VERSION = "1.10.0-beta2";
9
9
  var PKG_FORMAT = "esm";
10
10
 
11
11
  // src/ClientSideSuspense.tsx
@@ -164,7 +164,7 @@ import {
164
164
  } from "@liveblocks/core";
165
165
  function selectedThreads(roomId, state, options) {
166
166
  const result = applyOptimisticUpdates3(state);
167
- return Object.values(result.threads).filter((thread) => {
167
+ const threads = Object.values(result.threads).filter((thread) => {
168
168
  if (thread.roomId !== roomId)
169
169
  return false;
170
170
  const query = options.query;
@@ -177,6 +177,7 @@ function selectedThreads(roomId, state, options) {
177
177
  }
178
178
  return true;
179
179
  });
180
+ return threads.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
180
181
  }
181
182
 
182
183
  // src/comments/lib/upsert-comment.ts
@@ -299,7 +300,17 @@ function useRoomContextBundle() {
299
300
  }
300
301
  return bundle;
301
302
  }
302
- function createRoomContext(client) {
303
+ function createRoomContext(client, options) {
304
+ if (options?.resolveUsers) {
305
+ throw new Error(
306
+ "The 'resolveUsers' option has moved to 'createClient' from '@liveblocks/client'. Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10."
307
+ );
308
+ }
309
+ if (options?.resolveMentionSuggestions) {
310
+ throw new Error(
311
+ "The 'resolveMentionSuggestions' option has moved to 'createClient' from '@liveblocks/client'. Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10."
312
+ );
313
+ }
303
314
  const RoomContext = React2.createContext(null);
304
315
  const commentsErrorEventSource = makeEventSource();
305
316
  const shared = createSharedContext(client);
@@ -308,13 +319,13 @@ function createRoomContext(client) {
308
319
  () => /* @__PURE__ */ new Map()
309
320
  );
310
321
  const stableEnterRoom = React2.useCallback(
311
- (roomId, options) => {
322
+ (roomId, options2) => {
312
323
  const cached = cache.get(roomId);
313
324
  if (cached)
314
325
  return cached;
315
326
  const rv = client.enterRoom(
316
327
  roomId,
317
- options
328
+ options2
318
329
  );
319
330
  const origLeave = rv.leave;
320
331
  rv.leave = () => {
@@ -507,8 +518,8 @@ function createRoomContext(client) {
507
518
  function useBroadcastEvent() {
508
519
  const room = useRoom();
509
520
  return React2.useCallback(
510
- (event, options = { shouldQueueEventIfNotReady: false }) => {
511
- room.broadcastEvent(event, options);
521
+ (event, options2 = { shouldQueueEventIfNotReady: false }) => {
522
+ room.broadcastEvent(event, options2);
512
523
  },
513
524
  [room]
514
525
  );
@@ -839,7 +850,7 @@ function createRoomContext(client) {
839
850
  }
840
851
  poller.start(POLLING_INTERVAL);
841
852
  }
842
- async function getThreadsAndInboxNotifications(room, queryKey, options) {
853
+ async function getThreadsAndInboxNotifications(room, queryKey, options2) {
843
854
  const roomId = room.id;
844
855
  return getOrInitRequest(
845
856
  queryKey,
@@ -848,7 +859,7 @@ function createRoomContext(client) {
848
859
  if (room2 === null) {
849
860
  return;
850
861
  }
851
- return room2.getThreads(options);
862
+ return room2.getThreads(options2);
852
863
  },
853
864
  (result) => {
854
865
  if (result !== void 0) {
@@ -861,21 +872,18 @@ function createRoomContext(client) {
861
872
  }
862
873
  );
863
874
  }
864
- function useThreads(options = { query: { metadata: {} } }) {
875
+ function useThreads(options2 = { query: { metadata: {} } }) {
865
876
  const room = useRoom();
866
877
  const queryKey = React2.useMemo(
867
- () => generateQueryKey(room.id, options.query),
868
- [room, options]
878
+ () => generateQueryKey(room.id, options2.query),
879
+ [room, options2]
869
880
  );
870
881
  React2.useEffect(() => {
871
- void getThreadsAndInboxNotifications(room, queryKey, options);
882
+ void getThreadsAndInboxNotifications(room, queryKey, options2);
872
883
  incrementQuerySubscribers(queryKey);
873
884
  return () => decrementQuerySubscribers(queryKey);
874
885
  }, [room, queryKey]);
875
- return useSyncExternalStoreWithSelector(
876
- store.subscribe,
877
- store.get,
878
- store.get,
886
+ const selector = React2.useCallback(
879
887
  (state) => {
880
888
  if (state.queries[queryKey] === void 0 || state.queries[queryKey].isLoading) {
881
889
  return {
@@ -883,26 +891,44 @@ function createRoomContext(client) {
883
891
  };
884
892
  }
885
893
  return {
886
- threads: selectedThreads(room.id, state, options),
894
+ threads: selectedThreads(room.id, state, options2),
887
895
  isLoading: false,
888
896
  error: state.queries[queryKey].error
889
897
  };
890
- }
898
+ },
899
+ [room, queryKey]
900
+ // eslint-disable-line react-hooks/exhaustive-deps
901
+ );
902
+ return useSyncExternalStoreWithSelector(
903
+ store.subscribe,
904
+ store.get,
905
+ store.get,
906
+ selector
891
907
  );
892
908
  }
893
- function useThreadsSuspense(options = { query: { metadata: {} } }) {
909
+ function useThreadsSuspense(options2 = { query: { metadata: {} } }) {
894
910
  const room = useRoom();
895
911
  const queryKey = React2.useMemo(
896
- () => generateQueryKey(room.id, options?.query),
897
- [room, options]
912
+ () => generateQueryKey(room.id, options2?.query),
913
+ [room, options2]
898
914
  );
899
915
  const query = store.get().queries[queryKey];
900
916
  if (query === void 0 || query.isLoading) {
901
- throw getThreadsAndInboxNotifications(room, queryKey, options);
917
+ throw getThreadsAndInboxNotifications(room, queryKey, options2);
902
918
  }
903
919
  if (query.error) {
904
920
  throw query.error;
905
921
  }
922
+ const selector = React2.useCallback(
923
+ (state) => {
924
+ return {
925
+ threads: selectedThreads(room.id, state, options2),
926
+ isLoading: false
927
+ };
928
+ },
929
+ [room, queryKey]
930
+ // eslint-disable-line react-hooks/exhaustive-deps
931
+ );
906
932
  React2.useEffect(() => {
907
933
  incrementQuerySubscribers(queryKey);
908
934
  return () => {
@@ -913,20 +939,15 @@ function createRoomContext(client) {
913
939
  store.subscribe,
914
940
  store.get,
915
941
  store.get,
916
- (state) => {
917
- return {
918
- threads: selectedThreads(room.id, state, options),
919
- isLoading: false
920
- };
921
- }
942
+ selector
922
943
  );
923
944
  }
924
945
  function useCreateThread() {
925
946
  const room = useRoom();
926
947
  return React2.useCallback(
927
- (options) => {
928
- const body = options.body;
929
- const metadata = "metadata" in options ? options.metadata : {};
948
+ (options2) => {
949
+ const body = options2.body;
950
+ const metadata = "metadata" in options2 ? options2.metadata : {};
930
951
  const threadId = createThreadId();
931
952
  const commentId = createCommentId();
932
953
  const now = /* @__PURE__ */ new Date();
@@ -987,12 +1008,12 @@ function createRoomContext(client) {
987
1008
  function useEditThreadMetadata() {
988
1009
  const room = useRoom();
989
1010
  return React2.useCallback(
990
- (options) => {
991
- if (!("metadata" in options)) {
1011
+ (options2) => {
1012
+ if (!("metadata" in options2)) {
992
1013
  return;
993
1014
  }
994
- const threadId = options.threadId;
995
- const metadata = options.metadata;
1015
+ const threadId = options2.threadId;
1016
+ const metadata = options2.metadata;
996
1017
  const optimisticUpdateId = nanoid2();
997
1018
  store.pushOptimisticUpdate({
998
1019
  type: "edit-thread-metadata",