@liveblocks/react 0.18.1 → 0.18.2

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 CHANGED
@@ -318,16 +318,6 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
318
318
  * );
319
319
  */
320
320
  useOthersMapped<T>(itemSelector: (other: User<TPresence, TUserMeta>) => T, itemIsEqual?: (prev: T, curr: T) => boolean): ReadonlyArray<readonly [connectionId: number, data: T]>;
321
- /**
322
- * Given a connection ID (as obtained by using `useOthersConnectionIds`), you can
323
- * call this selector deep down in your component stack to only have the
324
- * component re-render if properties for this particular user change.
325
- *
326
- * @example
327
- * // Returns full user and re-renders whenever anything on the user changes
328
- * const secondUser = useOther(2);
329
- */
330
- useOther(connectionId: number): User<TPresence, TUserMeta>;
331
321
  /**
332
322
  * Given a connection ID (as obtained by using `useOthersConnectionIds`), you
333
323
  * can call this selector deep down in your component stack to only have the
@@ -635,17 +625,6 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
635
625
  * );
636
626
  */
637
627
  useOthersMapped<T>(itemSelector: (other: User<TPresence, TUserMeta>) => T, itemIsEqual?: (prev: T, curr: T) => boolean): ReadonlyArray<readonly [connectionId: number, data: T]>;
638
- /**
639
- * Given a connection ID (as obtained by using `useOthersConnectionIds`),
640
- * you can call this selector deep down in your component stack to only
641
- * have the component re-render if properties for this particular user
642
- * change.
643
- *
644
- * @example
645
- * // Returns full user and re-renders whenever anything on the user changes
646
- * const secondUser = useOther(2);
647
- */
648
- useOther(connectionId: number): User<TPresence, TUserMeta>;
649
628
  /**
650
629
  * Given a connection ID (as obtained by using `useOthersConnectionIds`),
651
630
  * you can call this selector deep down in your component stack to only
package/index.js CHANGED
@@ -164,50 +164,41 @@ function createRoomContext(client) {
164
164
  );
165
165
  return useOthers(wrappedSelector, wrappedIsEqual);
166
166
  }
167
- const sentinel = Symbol();
167
+ const NOT_FOUND = Symbol();
168
168
  function useOther(connectionId, selector, isEqual) {
169
- const _useCallback = React2.useCallback;
170
- const _useOthers = useOthers;
171
- if (selector === void 0) {
172
- const selector2 = _useCallback(
173
- (others) => others.find((other2) => other2.connectionId === connectionId),
174
- [connectionId]
175
- );
176
- const other = _useOthers(selector2, _client.shallow);
177
- if (other === void 0) {
178
- throw new Error(
179
- `No such other user with connection id ${connectionId} exists`
169
+ const lastKnownValue = React2.useRef(NOT_FOUND);
170
+ const wrappedSelector = React2.useCallback(
171
+ (others) => {
172
+ const other2 = others.find(
173
+ (other3) => other3.connectionId === connectionId
180
174
  );
181
- }
182
- return other;
183
- } else {
184
- const wrappedSelector = _useCallback(
185
- (others) => {
186
- const other2 = others.find(
187
- (other3) => other3.connectionId === connectionId
188
- );
189
- return other2 !== void 0 ? selector(other2) : sentinel;
190
- },
191
- [connectionId, selector]
192
- );
193
- const wrappedIsEqual = _useCallback(
194
- (prev, curr) => {
195
- if (prev === sentinel || curr === sentinel) {
196
- return prev === curr;
197
- }
198
- const eq = isEqual != null ? isEqual : Object.is;
199
- return eq(prev, curr);
200
- },
201
- [isEqual]
175
+ if (other2 !== void 0) {
176
+ const value = selector(other2);
177
+ lastKnownValue.current = value;
178
+ return value;
179
+ } else {
180
+ return lastKnownValue.current;
181
+ }
182
+ },
183
+ [connectionId, selector]
184
+ );
185
+ const wrappedIsEqual = React2.useCallback(
186
+ (prev, curr) => {
187
+ if (prev === NOT_FOUND || curr === NOT_FOUND) {
188
+ return prev === curr;
189
+ }
190
+ const eq = isEqual != null ? isEqual : Object.is;
191
+ return eq(prev, curr);
192
+ },
193
+ [isEqual]
194
+ );
195
+ const other = useOthers(wrappedSelector, wrappedIsEqual);
196
+ if (other === NOT_FOUND) {
197
+ throw new Error(
198
+ `No such other user with connection id ${connectionId} exists`
202
199
  );
203
- const other = _useOthers(wrappedSelector, wrappedIsEqual);
204
- if (other === sentinel) {
205
- throw new Error(
206
- `No such other user with connection id ${connectionId} exists`
207
- );
208
- }
209
- return other;
210
200
  }
201
+ return other;
211
202
  }
212
203
  function useBroadcastEvent() {
213
204
  const room = useRoom();
@@ -443,11 +434,7 @@ function createRoomContext(client) {
443
434
  }
444
435
  function useOtherSuspense(connectionId, selector, isEqual) {
445
436
  useSuspendUntilPresenceLoaded();
446
- return useOther(
447
- connectionId,
448
- selector,
449
- isEqual
450
- );
437
+ return useOther(connectionId, selector, isEqual);
451
438
  }
452
439
  function useLegacyKeySuspense(key) {
453
440
  useSuspendUntilStorageLoaded();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/react",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
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.1",
30
+ "@liveblocks/client": "0.18.2",
31
31
  "react": "^16.14.0 || ^17 || ^18"
32
32
  },
33
33
  "repository": {
@@ -1 +0,0 @@
1
- ab4dc80c03188cfbc87c124cad9c824347a785b0