@liveblocks/react 1.4.5 → 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 +57 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -40
- 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";
|
|
@@ -626,18 +627,6 @@ function useDebounce(value, delay = DEFAULT_DELAY) {
|
|
|
626
627
|
return debouncedValue;
|
|
627
628
|
}
|
|
628
629
|
|
|
629
|
-
// src/lib/stable-stringify.ts
|
|
630
|
-
function stableStringify(object, ...args) {
|
|
631
|
-
const sortedObject = Object.keys(object).sort().reduce(
|
|
632
|
-
(sortedObject2, key) => {
|
|
633
|
-
sortedObject2[key] = object[key];
|
|
634
|
-
return sortedObject2;
|
|
635
|
-
},
|
|
636
|
-
{}
|
|
637
|
-
);
|
|
638
|
-
return JSON.stringify(sortedObject, ...args);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
630
|
// src/lib/use-async-cache.ts
|
|
642
631
|
import { useCallback, useEffect as useEffect4, useMemo, useRef as useRef3 } from "react";
|
|
643
632
|
import { useSyncExternalStore as useSyncExternalStore2 } from "use-sync-external-store/shim/index.js";
|
|
@@ -662,10 +651,10 @@ function useAsyncCache(cache, key, options) {
|
|
|
662
651
|
if (key === null || !cache) {
|
|
663
652
|
return null;
|
|
664
653
|
}
|
|
665
|
-
const cacheItem2 = cache.create(key
|
|
654
|
+
const cacheItem2 = cache.create(key);
|
|
666
655
|
void cacheItem2.get();
|
|
667
656
|
return cacheItem2;
|
|
668
|
-
}, [cache,
|
|
657
|
+
}, [cache, key]);
|
|
669
658
|
const subscribe = useCallback(
|
|
670
659
|
(callback) => cacheItem?.subscribe(callback) ?? noop,
|
|
671
660
|
[cacheItem]
|
|
@@ -680,18 +669,33 @@ function useAsyncCache(cache, key, options) {
|
|
|
680
669
|
let data = state.data;
|
|
681
670
|
useEffect4(() => {
|
|
682
671
|
previousData.current = { key, data: state.data };
|
|
683
|
-
}, [key, state]);
|
|
684
|
-
if (
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
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
|
+
}
|
|
688
695
|
}
|
|
689
696
|
if (state.isLoading && frozenOptions?.keepPreviousDataWhileLoading && typeof state.data === "undefined" && previousData.current?.key !== key && typeof previousData.current?.data !== "undefined") {
|
|
690
697
|
data = previousData.current.data;
|
|
691
698
|
}
|
|
692
|
-
if (frozenOptions?.suspense && state.error) {
|
|
693
|
-
throw state.error;
|
|
694
|
-
}
|
|
695
699
|
return {
|
|
696
700
|
isLoading: state.isLoading,
|
|
697
701
|
data,
|
|
@@ -740,6 +744,9 @@ function alwaysEmptyList() {
|
|
|
740
744
|
function alwaysNull() {
|
|
741
745
|
return null;
|
|
742
746
|
}
|
|
747
|
+
function alwaysConnecting() {
|
|
748
|
+
return "connecting";
|
|
749
|
+
}
|
|
743
750
|
function makeMutationContext(room) {
|
|
744
751
|
const errmsg = "This mutation cannot be used until connected to the Liveblocks room";
|
|
745
752
|
return {
|
|
@@ -767,13 +774,13 @@ function makeMutationContext(room) {
|
|
|
767
774
|
setMyPresence: room.updatePresence
|
|
768
775
|
};
|
|
769
776
|
}
|
|
770
|
-
var
|
|
771
|
-
function
|
|
772
|
-
if (!
|
|
777
|
+
var hasWarnedIfNoResolveUsers = false;
|
|
778
|
+
function warnIfNoResolveUsers(usersCache) {
|
|
779
|
+
if (!hasWarnedIfNoResolveUsers && !usersCache && process.env.NODE_ENV !== "production") {
|
|
773
780
|
console.warn(
|
|
774
|
-
"Set the
|
|
781
|
+
"Set the resolveUsers option in createRoomContext to specify user info."
|
|
775
782
|
);
|
|
776
|
-
|
|
783
|
+
hasWarnedIfNoResolveUsers = true;
|
|
777
784
|
}
|
|
778
785
|
}
|
|
779
786
|
var hasWarnedAboutCommentsBeta = false;
|
|
@@ -878,7 +885,8 @@ function createRoomContext(client, options) {
|
|
|
878
885
|
const room = useRoom();
|
|
879
886
|
const subscribe = room.events.status.subscribe;
|
|
880
887
|
const getSnapshot = room.getStatus;
|
|
881
|
-
|
|
888
|
+
const getServerSnapshot = alwaysConnecting;
|
|
889
|
+
return useSyncExternalStore3(subscribe, getSnapshot, getServerSnapshot);
|
|
882
890
|
}
|
|
883
891
|
function useMyPresence() {
|
|
884
892
|
const room = useRoom();
|
|
@@ -1143,6 +1151,7 @@ function createRoomContext(client, options) {
|
|
|
1143
1151
|
}
|
|
1144
1152
|
ensureNotServerSide();
|
|
1145
1153
|
throw new Promise((res) => {
|
|
1154
|
+
room.events.self.subscribeOnce(() => res());
|
|
1146
1155
|
room.events.status.subscribeOnce(() => res());
|
|
1147
1156
|
});
|
|
1148
1157
|
}
|
|
@@ -1298,19 +1307,21 @@ function createRoomContext(client, options) {
|
|
|
1298
1307
|
[room]
|
|
1299
1308
|
);
|
|
1300
1309
|
}
|
|
1301
|
-
const {
|
|
1302
|
-
const usersCache =
|
|
1303
|
-
|
|
1310
|
+
const { resolveUsers, resolveMentionSuggestions } = options ?? {};
|
|
1311
|
+
const usersCache = resolveUsers ? createAsyncCache(async (stringifiedOptions) => {
|
|
1312
|
+
const users = await resolveUsers(
|
|
1304
1313
|
JSON.parse(stringifiedOptions)
|
|
1305
1314
|
);
|
|
1315
|
+
return users?.[0];
|
|
1306
1316
|
}) : void 0;
|
|
1307
1317
|
function useUser(userId) {
|
|
1318
|
+
const room = useRoom();
|
|
1308
1319
|
const resolverKey = React2.useMemo(
|
|
1309
|
-
() =>
|
|
1310
|
-
[userId]
|
|
1320
|
+
() => stringify({ userIds: [userId], roomId: room.id }),
|
|
1321
|
+
[userId, room.id]
|
|
1311
1322
|
);
|
|
1312
1323
|
const state = useAsyncCache(usersCache, resolverKey);
|
|
1313
|
-
React2.useEffect(() =>
|
|
1324
|
+
React2.useEffect(() => warnIfNoResolveUsers(usersCache), []);
|
|
1314
1325
|
if (state.isLoading) {
|
|
1315
1326
|
return {
|
|
1316
1327
|
isLoading: true
|
|
@@ -1324,14 +1335,15 @@ function createRoomContext(client, options) {
|
|
|
1324
1335
|
}
|
|
1325
1336
|
}
|
|
1326
1337
|
function useUserSuspense(userId) {
|
|
1338
|
+
const room = useRoom();
|
|
1327
1339
|
const resolverKey = React2.useMemo(
|
|
1328
|
-
() =>
|
|
1329
|
-
[userId]
|
|
1340
|
+
() => stringify({ userIds: [userId], roomId: room.id }),
|
|
1341
|
+
[userId, room.id]
|
|
1330
1342
|
);
|
|
1331
1343
|
const state = useAsyncCache(usersCache, resolverKey, {
|
|
1332
1344
|
suspense: true
|
|
1333
1345
|
});
|
|
1334
|
-
React2.useEffect(() =>
|
|
1346
|
+
React2.useEffect(() => warnIfNoResolveUsers(usersCache), []);
|
|
1335
1347
|
return {
|
|
1336
1348
|
user: state.data,
|
|
1337
1349
|
isLoading: false
|
|
@@ -1348,7 +1360,7 @@ function createRoomContext(client, options) {
|
|
|
1348
1360
|
const room = useRoom();
|
|
1349
1361
|
const debouncedSearch = useDebounce(search, 500);
|
|
1350
1362
|
const resolverKey = React2.useMemo(
|
|
1351
|
-
() => debouncedSearch !== void 0 ?
|
|
1363
|
+
() => debouncedSearch !== void 0 ? stringify({ text: debouncedSearch, roomId: room.id }) : null,
|
|
1352
1364
|
[debouncedSearch, room.id]
|
|
1353
1365
|
);
|
|
1354
1366
|
const { data } = useAsyncCache(mentionSuggestionsCache, resolverKey, {
|