@liveblocks/react 1.4.4 → 1.4.6-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.
- package/dist/index.d.mts +33 -11
- package/dist/index.d.ts +33 -11
- package/dist/index.js +68 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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.4.
|
|
8
|
+
var PKG_VERSION = "1.4.6-test1";
|
|
9
9
|
var PKG_FORMAT = "esm";
|
|
10
10
|
|
|
11
11
|
// src/ClientSideSuspense.tsx
|
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
deprecateIf,
|
|
26
26
|
errorIf,
|
|
27
27
|
isLiveNode,
|
|
28
|
-
makeEventSource as makeEventSource2
|
|
28
|
+
makeEventSource as makeEventSource2,
|
|
29
|
+
stringify
|
|
29
30
|
} from "@liveblocks/core";
|
|
30
31
|
import * as React2 from "react";
|
|
31
32
|
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
|
|
@@ -257,21 +258,23 @@ function createCommentsRoom(room, errorEventSource) {
|
|
|
257
258
|
const threadId = createOptimisticId(THREAD_ID_PREFIX);
|
|
258
259
|
const commentId = createOptimisticId(COMMENT_ID_PREFIX);
|
|
259
260
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
261
|
+
const newComment = {
|
|
262
|
+
id: commentId,
|
|
263
|
+
threadId,
|
|
264
|
+
roomId: room.id,
|
|
265
|
+
createdAt: now,
|
|
266
|
+
type: "comment",
|
|
267
|
+
userId: getCurrentUserId(),
|
|
268
|
+
body,
|
|
269
|
+
reactions: []
|
|
270
|
+
};
|
|
260
271
|
const newThread = {
|
|
261
272
|
id: threadId,
|
|
262
273
|
type: "thread",
|
|
263
274
|
createdAt: now,
|
|
264
275
|
roomId: room.id,
|
|
265
276
|
metadata,
|
|
266
|
-
comments: [
|
|
267
|
-
{
|
|
268
|
-
id: commentId,
|
|
269
|
-
createdAt: now,
|
|
270
|
-
type: "comment",
|
|
271
|
-
userId: getCurrentUserId(),
|
|
272
|
-
body
|
|
273
|
-
}
|
|
274
|
-
]
|
|
277
|
+
comments: [newComment]
|
|
275
278
|
};
|
|
276
279
|
mutate(room.createThread({ threadId, commentId, body, metadata }), {
|
|
277
280
|
optimisticData: [...threads, newThread]
|
|
@@ -624,18 +627,6 @@ function useDebounce(value, delay = DEFAULT_DELAY) {
|
|
|
624
627
|
return debouncedValue;
|
|
625
628
|
}
|
|
626
629
|
|
|
627
|
-
// src/lib/stable-stringify.ts
|
|
628
|
-
function stableStringify(object, ...args) {
|
|
629
|
-
const sortedObject = Object.keys(object).sort().reduce(
|
|
630
|
-
(sortedObject2, key) => {
|
|
631
|
-
sortedObject2[key] = object[key];
|
|
632
|
-
return sortedObject2;
|
|
633
|
-
},
|
|
634
|
-
{}
|
|
635
|
-
);
|
|
636
|
-
return JSON.stringify(sortedObject, ...args);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
630
|
// src/lib/use-async-cache.ts
|
|
640
631
|
import { useCallback, useEffect as useEffect4, useMemo, useRef as useRef3 } from "react";
|
|
641
632
|
import { useSyncExternalStore as useSyncExternalStore2 } from "use-sync-external-store/shim/index.js";
|
|
@@ -660,10 +651,10 @@ function useAsyncCache(cache, key, options) {
|
|
|
660
651
|
if (key === null || !cache) {
|
|
661
652
|
return null;
|
|
662
653
|
}
|
|
663
|
-
const cacheItem2 = cache.create(key
|
|
654
|
+
const cacheItem2 = cache.create(key);
|
|
664
655
|
void cacheItem2.get();
|
|
665
656
|
return cacheItem2;
|
|
666
|
-
}, [cache,
|
|
657
|
+
}, [cache, key]);
|
|
667
658
|
const subscribe = useCallback(
|
|
668
659
|
(callback) => cacheItem?.subscribe(callback) ?? noop,
|
|
669
660
|
[cacheItem]
|
|
@@ -678,18 +669,33 @@ function useAsyncCache(cache, key, options) {
|
|
|
678
669
|
let data = state.data;
|
|
679
670
|
useEffect4(() => {
|
|
680
671
|
previousData.current = { key, data: state.data };
|
|
681
|
-
}, [key, state]);
|
|
682
|
-
if (
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
672
|
+
}, [key, state.data]);
|
|
673
|
+
if (!cacheItem) {
|
|
674
|
+
return {
|
|
675
|
+
isLoading: false,
|
|
676
|
+
data: void 0,
|
|
677
|
+
error: void 0,
|
|
678
|
+
getState,
|
|
679
|
+
revalidate
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
if (frozenOptions?.suspense) {
|
|
683
|
+
const error = getState().error;
|
|
684
|
+
if (error) {
|
|
685
|
+
throw error;
|
|
686
|
+
} else if (getState().isLoading) {
|
|
687
|
+
throw new Promise((resolve) => {
|
|
688
|
+
cacheItem.subscribeOnce((state2) => {
|
|
689
|
+
if (!state2.isLoading) {
|
|
690
|
+
resolve();
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
}
|
|
686
695
|
}
|
|
687
696
|
if (state.isLoading && frozenOptions?.keepPreviousDataWhileLoading && typeof state.data === "undefined" && previousData.current?.key !== key && typeof previousData.current?.data !== "undefined") {
|
|
688
697
|
data = previousData.current.data;
|
|
689
698
|
}
|
|
690
|
-
if (frozenOptions?.suspense && state.error) {
|
|
691
|
-
throw state.error;
|
|
692
|
-
}
|
|
693
699
|
return {
|
|
694
700
|
isLoading: state.isLoading,
|
|
695
701
|
data,
|
|
@@ -738,6 +744,9 @@ function alwaysEmptyList() {
|
|
|
738
744
|
function alwaysNull() {
|
|
739
745
|
return null;
|
|
740
746
|
}
|
|
747
|
+
function alwaysConnecting() {
|
|
748
|
+
return "connecting";
|
|
749
|
+
}
|
|
741
750
|
function makeMutationContext(room) {
|
|
742
751
|
const errmsg = "This mutation cannot be used until connected to the Liveblocks room";
|
|
743
752
|
return {
|
|
@@ -765,13 +774,13 @@ function makeMutationContext(room) {
|
|
|
765
774
|
setMyPresence: room.updatePresence
|
|
766
775
|
};
|
|
767
776
|
}
|
|
768
|
-
var
|
|
769
|
-
function
|
|
770
|
-
if (!
|
|
777
|
+
var hasWarnedIfNoResolveUsers = false;
|
|
778
|
+
function warnIfNoResolveUsers(usersCache) {
|
|
779
|
+
if (!hasWarnedIfNoResolveUsers && !usersCache && process.env.NODE_ENV !== "production") {
|
|
771
780
|
console.warn(
|
|
772
|
-
"Set the
|
|
781
|
+
"Set the resolveUsers option in createRoomContext to specify user info."
|
|
773
782
|
);
|
|
774
|
-
|
|
783
|
+
hasWarnedIfNoResolveUsers = true;
|
|
775
784
|
}
|
|
776
785
|
}
|
|
777
786
|
var hasWarnedAboutCommentsBeta = false;
|
|
@@ -876,7 +885,8 @@ function createRoomContext(client, options) {
|
|
|
876
885
|
const room = useRoom();
|
|
877
886
|
const subscribe = room.events.status.subscribe;
|
|
878
887
|
const getSnapshot = room.getStatus;
|
|
879
|
-
|
|
888
|
+
const getServerSnapshot = alwaysConnecting;
|
|
889
|
+
return useSyncExternalStore3(subscribe, getSnapshot, getServerSnapshot);
|
|
880
890
|
}
|
|
881
891
|
function useMyPresence() {
|
|
882
892
|
const room = useRoom();
|
|
@@ -1141,6 +1151,7 @@ function createRoomContext(client, options) {
|
|
|
1141
1151
|
}
|
|
1142
1152
|
ensureNotServerSide();
|
|
1143
1153
|
throw new Promise((res) => {
|
|
1154
|
+
room.events.self.subscribeOnce(() => res());
|
|
1144
1155
|
room.events.status.subscribeOnce(() => res());
|
|
1145
1156
|
});
|
|
1146
1157
|
}
|
|
@@ -1296,19 +1307,21 @@ function createRoomContext(client, options) {
|
|
|
1296
1307
|
[room]
|
|
1297
1308
|
);
|
|
1298
1309
|
}
|
|
1299
|
-
const {
|
|
1300
|
-
const usersCache =
|
|
1301
|
-
|
|
1310
|
+
const { resolveUsers, resolveMentionSuggestions } = options ?? {};
|
|
1311
|
+
const usersCache = resolveUsers ? createAsyncCache(async (stringifiedOptions) => {
|
|
1312
|
+
const users = await resolveUsers(
|
|
1302
1313
|
JSON.parse(stringifiedOptions)
|
|
1303
1314
|
);
|
|
1315
|
+
return users?.[0];
|
|
1304
1316
|
}) : void 0;
|
|
1305
1317
|
function useUser(userId) {
|
|
1318
|
+
const room = useRoom();
|
|
1306
1319
|
const resolverKey = React2.useMemo(
|
|
1307
|
-
() =>
|
|
1308
|
-
[userId]
|
|
1320
|
+
() => stringify({ userIds: [userId], roomId: room.id }),
|
|
1321
|
+
[userId, room.id]
|
|
1309
1322
|
);
|
|
1310
1323
|
const state = useAsyncCache(usersCache, resolverKey);
|
|
1311
|
-
React2.useEffect(() =>
|
|
1324
|
+
React2.useEffect(() => warnIfNoResolveUsers(usersCache), []);
|
|
1312
1325
|
if (state.isLoading) {
|
|
1313
1326
|
return {
|
|
1314
1327
|
isLoading: true
|
|
@@ -1322,14 +1335,15 @@ function createRoomContext(client, options) {
|
|
|
1322
1335
|
}
|
|
1323
1336
|
}
|
|
1324
1337
|
function useUserSuspense(userId) {
|
|
1338
|
+
const room = useRoom();
|
|
1325
1339
|
const resolverKey = React2.useMemo(
|
|
1326
|
-
() =>
|
|
1327
|
-
[userId]
|
|
1340
|
+
() => stringify({ userIds: [userId], roomId: room.id }),
|
|
1341
|
+
[userId, room.id]
|
|
1328
1342
|
);
|
|
1329
1343
|
const state = useAsyncCache(usersCache, resolverKey, {
|
|
1330
1344
|
suspense: true
|
|
1331
1345
|
});
|
|
1332
|
-
React2.useEffect(() =>
|
|
1346
|
+
React2.useEffect(() => warnIfNoResolveUsers(usersCache), []);
|
|
1333
1347
|
return {
|
|
1334
1348
|
user: state.data,
|
|
1335
1349
|
isLoading: false
|
|
@@ -1346,7 +1360,7 @@ function createRoomContext(client, options) {
|
|
|
1346
1360
|
const room = useRoom();
|
|
1347
1361
|
const debouncedSearch = useDebounce(search, 500);
|
|
1348
1362
|
const resolverKey = React2.useMemo(
|
|
1349
|
-
() => debouncedSearch !== void 0 ?
|
|
1363
|
+
() => debouncedSearch !== void 0 ? stringify({ text: debouncedSearch, roomId: room.id }) : null,
|
|
1350
1364
|
[debouncedSearch, room.id]
|
|
1351
1365
|
);
|
|
1352
1366
|
const { data } = useAsyncCache(mentionSuggestionsCache, resolverKey, {
|