@liveblocks/react 0.17.2 → 0.17.5

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.
Files changed (4) hide show
  1. package/index.d.ts +6 -6
  2. package/index.js +33 -23
  3. package/index.mjs +33 -23
  4. package/package.json +3 -2
package/index.d.ts CHANGED
@@ -240,12 +240,12 @@ declare type RoomContext<
240
240
  * @example
241
241
  * const animals = useList("animals"); // e.g. [] or ["🦁", "🐍", "🦍"]
242
242
  */
243
- deprecated_useList<TValue extends Lson>(key: string): LiveList<TValue> | null;
243
+ useList_deprecated<TValue extends Lson>(key: string): LiveList<TValue> | null;
244
244
  /**
245
245
  * @deprecated We no longer recommend initializing the
246
246
  * items from the useList() hook. For details, see https://bit.ly/3Niy5aP.
247
247
  */
248
- deprecated_useList<TValue extends Lson>(
248
+ useList_deprecated<TValue extends Lson>(
249
249
  key: string,
250
250
  items: TValue[]
251
251
  ): LiveList<TValue> | null;
@@ -259,14 +259,14 @@ declare type RoomContext<
259
259
  * @example
260
260
  * const shapesById = useMap("shapes");
261
261
  */
262
- deprecated_useMap<TKey extends string, TValue extends Lson>(
262
+ useMap_deprecated<TKey extends string, TValue extends Lson>(
263
263
  key: string
264
264
  ): LiveMap<TKey, TValue> | null;
265
265
  /**
266
266
  * @deprecated We no longer recommend initializing the
267
267
  * entries from the useMap() hook. For details, see https://bit.ly/3Niy5aP.
268
268
  */
269
- deprecated_useMap<TKey extends string, TValue extends Lson>(
269
+ useMap_deprecated<TKey extends string, TValue extends Lson>(
270
270
  key: string,
271
271
  entries: readonly (readonly [TKey, TValue])[] | null
272
272
  ): LiveMap<TKey, TValue> | null;
@@ -280,14 +280,14 @@ declare type RoomContext<
280
280
  * @example
281
281
  * const object = useObject("obj");
282
282
  */
283
- deprecated_useObject<TData extends LsonObject>(
283
+ useObject_deprecated<TData extends LsonObject>(
284
284
  key: string
285
285
  ): LiveObject<TData> | null;
286
286
  /**
287
287
  * @deprecated We no longer recommend initializing the fields from the
288
288
  * useObject() hook. For details, see https://bit.ly/3Niy5aP.
289
289
  */
290
- deprecated_useObject<TData extends LsonObject>(
290
+ useObject_deprecated<TData extends LsonObject>(
291
291
  key: string,
292
292
  initialData: TData
293
293
  ): LiveObject<TData> | null;
package/index.js CHANGED
@@ -67,6 +67,9 @@ function useRerender() {
67
67
  return x + 1;
68
68
  }, 0)[1];
69
69
  }
70
+ function useInitial(value) {
71
+ return React__namespace.useRef(value).current;
72
+ }
70
73
  function createRoomContext(client$1) {
71
74
  var useClient$1;
72
75
  useClient$1 =
@@ -125,7 +128,7 @@ function createRoomContext(client$1) {
125
128
  [root]
126
129
  );
127
130
  }
128
- function deprecated_useMap(key, entries) {
131
+ function useMap_deprecated(key, entries) {
129
132
  internal.errorIf(
130
133
  entries,
131
134
  "Support for initializing entries in useMap() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n const initialStorage = () => ({\n " +
@@ -148,7 +151,7 @@ function createRoomContext(client$1) {
148
151
  ),
149
152
  null);
150
153
  }
151
- function deprecated_useList(key, items) {
154
+ function useList_deprecated(key, items) {
152
155
  internal.errorIf(
153
156
  items,
154
157
  'Support for initializing items in useList() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n import { LiveList } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ' +
@@ -168,7 +171,7 @@ function createRoomContext(client$1) {
168
171
  ),
169
172
  null);
170
173
  }
171
- function deprecated_useObject(key, initialData) {
174
+ function useObject_deprecated(key, initialData) {
172
175
  internal.errorIf(
173
176
  initialData,
174
177
  'Support for initializing data in useObject() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n import { LiveObject } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ' +
@@ -194,14 +197,15 @@ function createRoomContext(client$1) {
194
197
  function useStorageValue(key, initialValue) {
195
198
  var room = useRoom(),
196
199
  root = useStorage()[0],
197
- rerender = useRerender();
200
+ rerender = useRerender(),
201
+ frozenInitialValue = useInitial(initialValue);
198
202
  if (
199
203
  (React__namespace.useEffect(
200
204
  function () {
201
205
  if (null != root) {
202
206
  var liveValue = root.get(key);
203
207
  null == liveValue &&
204
- ((liveValue = initialValue), root.set(key, liveValue));
208
+ ((liveValue = frozenInitialValue), root.set(key, liveValue));
205
209
  var unsubscribeCrdt = room.subscribe(liveValue, rerender),
206
210
  unsubscribeRoot = room.subscribe(root, function () {
207
211
  var newCrdt = root.get(key);
@@ -219,7 +223,7 @@ function createRoomContext(client$1) {
219
223
  );
220
224
  }
221
225
  },
222
- [root, room]
226
+ [root, room, key, frozenInitialValue, rerender]
223
227
  ),
224
228
  null == root)
225
229
  )
@@ -253,6 +257,12 @@ function createRoomContext(client$1) {
253
257
  "RoomProvider's `defaultStorageRoot` prop will be removed in @liveblocks/react 0.18. Please use `initialStorage` instead. For more info, see https://bit.ly/3Niy5aP"
254
258
  );
255
259
  var _client = useClient$1(),
260
+ frozen = useInitial({
261
+ initialPresence: initialPresence,
262
+ initialStorage: initialStorage,
263
+ defaultPresence: defaultPresence,
264
+ defaultStorageRoot: defaultStorageRoot,
265
+ }),
256
266
  _React$useState = React__namespace.useState(function () {
257
267
  return _client.enter(roomId, {
258
268
  initialPresence: initialPresence,
@@ -270,10 +280,10 @@ function createRoomContext(client$1) {
270
280
  return (
271
281
  setRoom(
272
282
  _client.enter(roomId, {
273
- initialPresence: initialPresence,
274
- initialStorage: initialStorage,
275
- defaultPresence: defaultPresence,
276
- defaultStorageRoot: defaultStorageRoot,
283
+ initialPresence: frozen.initialPresence,
284
+ initialStorage: frozen.initialStorage,
285
+ defaultPresence: frozen.defaultPresence,
286
+ defaultStorageRoot: frozen.defaultStorageRoot,
277
287
  DO_NOT_USE_withoutConnecting: "undefined" == typeof window,
278
288
  })
279
289
  ),
@@ -282,7 +292,7 @@ function createRoomContext(client$1) {
282
292
  }
283
293
  );
284
294
  },
285
- [_client, roomId]
295
+ [_client, roomId, frozen]
286
296
  ),
287
297
  React__namespace.createElement(
288
298
  RoomCtx.Provider,
@@ -342,10 +352,10 @@ function createRoomContext(client$1) {
342
352
  },
343
353
  useHistory: useHistory,
344
354
  useList: function (key) {
345
- return deprecated_useList(key);
355
+ return useList_deprecated(key);
346
356
  },
347
357
  useMap: function (key) {
348
- return deprecated_useMap(key);
358
+ return useMap_deprecated(key);
349
359
  },
350
360
  useMyPresence: function () {
351
361
  var room = useRoom(),
@@ -359,7 +369,7 @@ function createRoomContext(client$1) {
359
369
  unsubscribe();
360
370
  };
361
371
  },
362
- [room]
372
+ [room, rerender]
363
373
  ),
364
374
  [
365
375
  presence,
@@ -373,7 +383,7 @@ function createRoomContext(client$1) {
373
383
  );
374
384
  },
375
385
  useObject: function (key) {
376
- return deprecated_useObject(key);
386
+ return useObject_deprecated(key);
377
387
  },
378
388
  useOthers: function () {
379
389
  var room = useRoom(),
@@ -386,7 +396,7 @@ function createRoomContext(client$1) {
386
396
  unsubscribe();
387
397
  };
388
398
  },
389
- [room]
399
+ [room, rerender]
390
400
  ),
391
401
  room.getOthers()
392
402
  );
@@ -407,7 +417,7 @@ function createRoomContext(client$1) {
407
417
  unsubscribePresence(), unsubscribeConnection();
408
418
  };
409
419
  },
410
- [room]
420
+ [room, rerender]
411
421
  ),
412
422
  room.getSelf()
413
423
  );
@@ -425,9 +435,9 @@ function createRoomContext(client$1) {
425
435
  [room]
426
436
  );
427
437
  },
428
- deprecated_useList: deprecated_useList,
429
- deprecated_useMap: deprecated_useMap,
430
- deprecated_useObject: deprecated_useObject,
438
+ useList_deprecated: useList_deprecated,
439
+ useMap_deprecated: useMap_deprecated,
440
+ useObject_deprecated: useObject_deprecated,
431
441
  };
432
442
  }
433
443
  var _hooks = createRoomContext("__legacy");
@@ -498,7 +508,7 @@ var _hooks = createRoomContext("__legacy");
498
508
  internal.deprecate(
499
509
  "Please use `createRoomContext()` instead of importing `useList` from `@liveblocks/react` directly. See https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details."
500
510
  ),
501
- _hooks.deprecated_useList(key, items)
511
+ _hooks.useList_deprecated(key, items)
502
512
  );
503
513
  }),
504
514
  (exports.useMap = function (key, entries) {
@@ -506,7 +516,7 @@ var _hooks = createRoomContext("__legacy");
506
516
  internal.deprecate(
507
517
  "Please use `createRoomContext()` instead of importing `useMap` from `@liveblocks/react` directly. See https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details."
508
518
  ),
509
- _hooks.deprecated_useMap(key, entries)
519
+ _hooks.useMap_deprecated(key, entries)
510
520
  );
511
521
  }),
512
522
  (exports.useMyPresence = function () {
@@ -522,7 +532,7 @@ var _hooks = createRoomContext("__legacy");
522
532
  internal.deprecate(
523
533
  "Please use `createRoomContext()` instead of importing `useObject` from `@liveblocks/react` directly. See https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details."
524
534
  ),
525
- _hooks.deprecated_useObject(key, initialData)
535
+ _hooks.useObject_deprecated(key, initialData)
526
536
  );
527
537
  }),
528
538
  (exports.useOthers = function () {
package/index.mjs CHANGED
@@ -55,6 +55,9 @@ function useRerender() {
55
55
  const [, update] = useReducer((x) => x + 1, 0);
56
56
  return update;
57
57
  }
58
+ function useInitial(value) {
59
+ return React.useRef(value).current;
60
+ }
58
61
  function createRoomContext(client) {
59
62
  let useClient$1;
60
63
  useClient$1 = "__legacy" !== client ? () => client : useClient;
@@ -86,7 +89,7 @@ function createRoomContext(client) {
86
89
  [root]
87
90
  );
88
91
  }
89
- function deprecated_useMap(key, entries) {
92
+ function useMap_deprecated(key, entries) {
90
93
  errorIf(
91
94
  entries,
92
95
  `Support for initializing entries in useMap() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n const initialStorage = () => ({\n ${JSON.stringify(
@@ -109,7 +112,7 @@ function createRoomContext(client) {
109
112
  ),
110
113
  null);
111
114
  }
112
- function deprecated_useList(key, items) {
115
+ function useList_deprecated(key, items) {
113
116
  errorIf(
114
117
  items,
115
118
  `Support for initializing items in useList() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n import { LiveList } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(
@@ -129,7 +132,7 @@ function createRoomContext(client) {
129
132
  ),
130
133
  null);
131
134
  }
132
- function deprecated_useObject(key, initialData) {
135
+ function useObject_deprecated(key, initialData) {
133
136
  errorIf(
134
137
  initialData,
135
138
  `Support for initializing data in useObject() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n import { LiveObject } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(
@@ -155,13 +158,14 @@ function createRoomContext(client) {
155
158
  function useStorageValue(key, initialValue) {
156
159
  const room = useRoom(),
157
160
  [root] = useStorage(),
158
- rerender = useRerender();
161
+ rerender = useRerender(),
162
+ frozenInitialValue = useInitial(initialValue);
159
163
  if (
160
164
  (React.useEffect(() => {
161
165
  if (null == root) return;
162
166
  let liveValue = root.get(key);
163
167
  null == liveValue &&
164
- ((liveValue = initialValue), root.set(key, liveValue));
168
+ ((liveValue = frozenInitialValue), root.set(key, liveValue));
165
169
  let unsubscribeCrdt = room.subscribe(liveValue, rerender);
166
170
  const unsubscribeRoot = room.subscribe(root, function () {
167
171
  const newCrdt = root.get(key);
@@ -177,7 +181,7 @@ function createRoomContext(client) {
177
181
  unsubscribeRoot(), unsubscribeCrdt();
178
182
  }
179
183
  );
180
- }, [root, room]),
184
+ }, [root, room, key, frozenInitialValue, rerender]),
181
185
  null == root)
182
186
  )
183
187
  return { status: "loading" };
@@ -214,6 +218,12 @@ function createRoomContext(client) {
214
218
  "RoomProvider's `defaultStorageRoot` prop will be removed in @liveblocks/react 0.18. Please use `initialStorage` instead. For more info, see https://bit.ly/3Niy5aP"
215
219
  );
216
220
  const _client = useClient$1(),
221
+ frozen = useInitial({
222
+ initialPresence: initialPresence,
223
+ initialStorage: initialStorage,
224
+ defaultPresence: defaultPresence,
225
+ defaultStorageRoot: defaultStorageRoot,
226
+ }),
217
227
  [room, setRoom] = React.useState(() =>
218
228
  _client.enter(roomId, {
219
229
  initialPresence: initialPresence,
@@ -228,10 +238,10 @@ function createRoomContext(client) {
228
238
  () => (
229
239
  setRoom(
230
240
  _client.enter(roomId, {
231
- initialPresence: initialPresence,
232
- initialStorage: initialStorage,
233
- defaultPresence: defaultPresence,
234
- defaultStorageRoot: defaultStorageRoot,
241
+ initialPresence: frozen.initialPresence,
242
+ initialStorage: frozen.initialStorage,
243
+ defaultPresence: frozen.defaultPresence,
244
+ defaultStorageRoot: frozen.defaultStorageRoot,
235
245
  DO_NOT_USE_withoutConnecting: "undefined" == typeof window,
236
246
  })
237
247
  ),
@@ -239,7 +249,7 @@ function createRoomContext(client) {
239
249
  _client.leave(roomId);
240
250
  }
241
251
  ),
242
- [_client, roomId]
252
+ [_client, roomId, frozen]
243
253
  ),
244
254
  React.createElement(RoomCtx.Provider, { value: room }, props.children)
245
255
  );
@@ -288,10 +298,10 @@ function createRoomContext(client) {
288
298
  },
289
299
  useHistory: useHistory,
290
300
  useList: function (key) {
291
- return deprecated_useList(key);
301
+ return useList_deprecated(key);
292
302
  },
293
303
  useMap: function (key) {
294
- return deprecated_useMap(key);
304
+ return useMap_deprecated(key);
295
305
  },
296
306
  useMyPresence: function () {
297
307
  const room = useRoom(),
@@ -303,7 +313,7 @@ function createRoomContext(client) {
303
313
  return () => {
304
314
  unsubscribe();
305
315
  };
306
- }, [room]),
316
+ }, [room, rerender]),
307
317
  [
308
318
  presence,
309
319
  React.useCallback(
@@ -314,7 +324,7 @@ function createRoomContext(client) {
314
324
  );
315
325
  },
316
326
  useObject: function (key) {
317
- return deprecated_useObject(key);
327
+ return useObject_deprecated(key);
318
328
  },
319
329
  useOthers: function () {
320
330
  const room = useRoom(),
@@ -325,7 +335,7 @@ function createRoomContext(client) {
325
335
  return () => {
326
336
  unsubscribe();
327
337
  };
328
- }, [room]),
338
+ }, [room, rerender]),
329
339
  room.getOthers()
330
340
  );
331
341
  },
@@ -343,7 +353,7 @@ function createRoomContext(client) {
343
353
  return () => {
344
354
  unsubscribePresence(), unsubscribeConnection();
345
355
  };
346
- }, [room]),
356
+ }, [room, rerender]),
347
357
  room.getSelf()
348
358
  );
349
359
  },
@@ -360,9 +370,9 @@ function createRoomContext(client) {
360
370
  [room]
361
371
  );
362
372
  },
363
- deprecated_useList: deprecated_useList,
364
- deprecated_useMap: deprecated_useMap,
365
- deprecated_useObject: deprecated_useObject,
373
+ useList_deprecated: useList_deprecated,
374
+ useMap_deprecated: useMap_deprecated,
375
+ useObject_deprecated: useObject_deprecated,
366
376
  };
367
377
  }
368
378
  const _hooks = createRoomContext("__legacy");
@@ -483,7 +493,7 @@ function useList(key, items) {
483
493
  deprecate(
484
494
  "Please use `createRoomContext()` instead of importing `useList` from `@liveblocks/react` directly. See https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details."
485
495
  ),
486
- _hooks.deprecated_useList(key, items)
496
+ _hooks.useList_deprecated(key, items)
487
497
  );
488
498
  }
489
499
  function useMap(key, entries) {
@@ -491,7 +501,7 @@ function useMap(key, entries) {
491
501
  deprecate(
492
502
  "Please use `createRoomContext()` instead of importing `useMap` from `@liveblocks/react` directly. See https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details."
493
503
  ),
494
- _hooks.deprecated_useMap(key, entries)
504
+ _hooks.useMap_deprecated(key, entries)
495
505
  );
496
506
  }
497
507
  function useObject(key, initialData) {
@@ -499,7 +509,7 @@ function useObject(key, initialData) {
499
509
  deprecate(
500
510
  "Please use `createRoomContext()` instead of importing `useObject` from `@liveblocks/react` directly. See https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details."
501
511
  ),
502
- _hooks.deprecated_useObject(key, initialData)
512
+ _hooks.useObject_deprecated(key, initialData)
503
513
  );
504
514
  }
505
515
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/react",
3
- "version": "0.17.2",
3
+ "version": "0.17.5",
4
4
  "description": "A set of React hooks and providers to use Liveblocks declaratively.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "license": "Apache-2.0",
31
31
  "peerDependencies": {
32
- "@liveblocks/client": "0.17.2",
32
+ "@liveblocks/client": "0.17.5",
33
33
  "react": "^16.14.0 || ^17 || ^18"
34
34
  },
35
35
  "devDependencies": {
@@ -48,6 +48,7 @@
48
48
  "@typescript-eslint/parser": "^5.26.0",
49
49
  "eslint": "^8.12.0",
50
50
  "eslint-plugin-import": "^2.26.0",
51
+ "eslint-plugin-react-hooks": "^4.6.0",
51
52
  "eslint-plugin-simple-import-sort": "^7.0.0",
52
53
  "jest": "^26.6.3",
53
54
  "msw": "^0.27.1",