@liveblocks/react 0.18.2 → 0.18.3
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/index.d.ts +15 -0
- package/index.js +41 -14
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -32,6 +32,21 @@ declare type RoomProviderProps<TPresence extends JsonObject, TStorage extends Ls
|
|
|
32
32
|
*/
|
|
33
33
|
id: string;
|
|
34
34
|
children: React.ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* If you're on React 17 or lower, pass in a reference to
|
|
37
|
+
* `ReactDOM.unstable_batchedUpdates` or
|
|
38
|
+
* `ReactNative.unstable_batchedUpdates` here.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* import { unstable_batchedUpdates } from "react-dom";
|
|
42
|
+
*
|
|
43
|
+
* <RoomProvider ... unstable_batchedUpdates={unstable_batchedUpdates} />
|
|
44
|
+
*
|
|
45
|
+
* This will prevent you from running into the so-called "stale props"
|
|
46
|
+
* and/or "zombie child" problem that React 17 and lower can suffer from.
|
|
47
|
+
* Not necessary when you're on React v18 or later.
|
|
48
|
+
*/
|
|
49
|
+
unstable_batchedUpdates?: (cb: () => void) => void;
|
|
35
50
|
} & RoomInitializers<TPresence, TStorage>>;
|
|
36
51
|
/**
|
|
37
52
|
* For any function type, returns a similar function type, but without the
|
package/index.js
CHANGED
|
@@ -12,6 +12,10 @@ function ClientSideSuspense(props) {
|
|
|
12
12
|
|
|
13
13
|
// src/factory.tsx
|
|
14
14
|
var _client = require('@liveblocks/client');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
15
19
|
var _internal = require('@liveblocks/client/internal');
|
|
16
20
|
|
|
17
21
|
var _withselector = require('use-sync-external-store/shim/with-selector');
|
|
@@ -33,8 +37,20 @@ function useInitial(value) {
|
|
|
33
37
|
var noop = () => {
|
|
34
38
|
};
|
|
35
39
|
var identity = (x) => x;
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
var missing_unstable_batchedUpdates = (reactVersion, roomId) => `We noticed you\u2019re using React ${reactVersion}. Please pass unstable_batchedUpdates at the RoomProvider level until you\u2019re ready to upgrade to React 18:
|
|
41
|
+
|
|
42
|
+
import { unstable_batchedUpdates } from "react-dom"; // or "react-native"
|
|
43
|
+
|
|
44
|
+
<RoomProvider id=${JSON.stringify(
|
|
45
|
+
roomId
|
|
46
|
+
)} ... unstable_batchedUpdates={unstable_batchedUpdates}>
|
|
47
|
+
...
|
|
48
|
+
</RoomProvider>
|
|
49
|
+
|
|
50
|
+
Why? Please see https://liveblocks.io/docs/guides/troubleshooting#stale-props-zombie-child for more information`;
|
|
51
|
+
var superfluous_unstable_batchedUpdates = "You don\u2019t need to pass unstable_batchedUpdates to RoomProvider anymore, since you\u2019re on React 18+ already.";
|
|
52
|
+
function useSyncExternalStore(s, gs, gss) {
|
|
53
|
+
return _withselector.useSyncExternalStoreWithSelector.call(void 0, s, gs, gss, identity);
|
|
38
54
|
}
|
|
39
55
|
var EMPTY_OTHERS = _internal.asArrayWithLegacyMethods.call(void 0, []);
|
|
40
56
|
function getEmptyOthers() {
|
|
@@ -70,7 +86,12 @@ function makeMutationContext(room) {
|
|
|
70
86
|
function createRoomContext(client) {
|
|
71
87
|
const RoomContext = React2.createContext(null);
|
|
72
88
|
function RoomProvider(props) {
|
|
73
|
-
const {
|
|
89
|
+
const {
|
|
90
|
+
id: roomId,
|
|
91
|
+
initialPresence,
|
|
92
|
+
initialStorage,
|
|
93
|
+
unstable_batchedUpdates
|
|
94
|
+
} = props;
|
|
74
95
|
if (process.env.NODE_ENV !== "production") {
|
|
75
96
|
if (!roomId) {
|
|
76
97
|
throw new Error(
|
|
@@ -80,15 +101,27 @@ function createRoomContext(client) {
|
|
|
80
101
|
if (typeof roomId !== "string") {
|
|
81
102
|
throw new Error("RoomProvider id property should be a string.");
|
|
82
103
|
}
|
|
104
|
+
const majorReactVersion = parseInt(React2.version) || 1;
|
|
105
|
+
const oldReactVersion = majorReactVersion < 18;
|
|
106
|
+
_internal.errorIf.call(void 0,
|
|
107
|
+
oldReactVersion && props.unstable_batchedUpdates === void 0,
|
|
108
|
+
missing_unstable_batchedUpdates(majorReactVersion, roomId)
|
|
109
|
+
);
|
|
110
|
+
_internal.deprecateIf.call(void 0,
|
|
111
|
+
!oldReactVersion && props.unstable_batchedUpdates !== void 0,
|
|
112
|
+
superfluous_unstable_batchedUpdates
|
|
113
|
+
);
|
|
83
114
|
}
|
|
84
115
|
const frozen = useInitial({
|
|
85
116
|
initialPresence,
|
|
86
|
-
initialStorage
|
|
117
|
+
initialStorage,
|
|
118
|
+
unstable_batchedUpdates
|
|
87
119
|
});
|
|
88
120
|
const [room, setRoom] = React2.useState(
|
|
89
121
|
() => client.enter(roomId, {
|
|
90
|
-
initialPresence,
|
|
91
|
-
initialStorage,
|
|
122
|
+
initialPresence: frozen.initialPresence,
|
|
123
|
+
initialStorage: frozen.initialStorage,
|
|
124
|
+
unstable_batchedUpdates: frozen.unstable_batchedUpdates,
|
|
92
125
|
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
93
126
|
})
|
|
94
127
|
);
|
|
@@ -97,6 +130,7 @@ function createRoomContext(client) {
|
|
|
97
130
|
client.enter(roomId, {
|
|
98
131
|
initialPresence: frozen.initialPresence,
|
|
99
132
|
initialStorage: frozen.initialStorage,
|
|
133
|
+
unstable_batchedUpdates: frozen.unstable_batchedUpdates,
|
|
100
134
|
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
101
135
|
})
|
|
102
136
|
);
|
|
@@ -166,19 +200,12 @@ function createRoomContext(client) {
|
|
|
166
200
|
}
|
|
167
201
|
const NOT_FOUND = Symbol();
|
|
168
202
|
function useOther(connectionId, selector, isEqual) {
|
|
169
|
-
const lastKnownValue = React2.useRef(NOT_FOUND);
|
|
170
203
|
const wrappedSelector = React2.useCallback(
|
|
171
204
|
(others) => {
|
|
172
205
|
const other2 = others.find(
|
|
173
206
|
(other3) => other3.connectionId === connectionId
|
|
174
207
|
);
|
|
175
|
-
|
|
176
|
-
const value = selector(other2);
|
|
177
|
-
lastKnownValue.current = value;
|
|
178
|
-
return value;
|
|
179
|
-
} else {
|
|
180
|
-
return lastKnownValue.current;
|
|
181
|
-
}
|
|
208
|
+
return other2 !== void 0 ? selector(other2) : NOT_FOUND;
|
|
182
209
|
},
|
|
183
210
|
[connectionId, selector]
|
|
184
211
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
4
4
|
"description": "A set of React hooks and providers to use Liveblocks declaratively.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.mjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"use-sync-external-store": "^1.2.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@liveblocks/client": "0.18.
|
|
30
|
+
"@liveblocks/client": "0.18.3",
|
|
31
31
|
"react": "^16.14.0 || ^17 || ^18"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|