@liveblocks/react 0.17.4 → 0.17.7

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 LIVEBLOCKS PTY LTD
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -28,17 +28,17 @@ npm install @liveblocks/client @liveblocks/react
28
28
 
29
29
  ## Documentation
30
30
 
31
- - Start with the [React guide](https://liveblocks.io/docs/get-started/react).
32
- - Explore the [API Reference](https://liveblocks.io/docs/api-reference/liveblocks-react).
31
+ Read the [documentation](https://liveblocks.io/docs) for guides and API references.
33
32
 
34
33
  ## Examples
35
34
 
36
- - Browse our gallery of collaborative UI patterns. [View examples gallery](https://liveblocks.io/examples)
37
- - Explore and clone any of our open-source examples. [View code examples](https://github.com/liveblocks/liveblocks/tree/main/examples)
35
+ Explore our [collaborative examples](https://liveblocks.io/examples) to help you get started.
36
+
37
+ > All examples are open-source and live in this repository, within [`/examples`](../../examples).
38
38
 
39
39
  ## Releases
40
40
 
41
- For changelog, visit [https://github.com/liveblocks/liveblocks/releases](https://github.com/liveblocks/liveblocks/releases).
41
+ See the [latest changes](https://github.com/liveblocks/liveblocks/releases) or learn more about [upcoming releases](https://github.com/liveblocks/liveblocks/milestones).
42
42
 
43
43
  ## Community
44
44
 
package/index.d.ts CHANGED
@@ -5,10 +5,10 @@ import {
5
5
  LsonObject,
6
6
  BaseUserMeta,
7
7
  Json,
8
+ Room,
8
9
  BroadcastOptions,
9
10
  History,
10
11
  Others,
11
- Room,
12
12
  User,
13
13
  LiveObject,
14
14
  Lson,
@@ -52,12 +52,18 @@ declare type RoomProviderProps<
52
52
  children: React.ReactNode;
53
53
  } & RoomInitializers<TPresence, TStorage>
54
54
  >;
55
- declare type RoomContext<
55
+ declare type RoomContextBundle<
56
56
  TPresence extends JsonObject,
57
57
  TStorage extends LsonObject,
58
58
  TUserMeta extends BaseUserMeta,
59
59
  TRoomEvent extends Json
60
60
  > = {
61
+ RoomContext: React.Context<Room<
62
+ TPresence,
63
+ TStorage,
64
+ TUserMeta,
65
+ TRoomEvent
66
+ > | null>;
61
67
  /**
62
68
  * Makes a Room available in the component hierarchy below.
63
69
  * When this component is unmounted, the current user leave the room.
@@ -240,12 +246,12 @@ declare type RoomContext<
240
246
  * @example
241
247
  * const animals = useList("animals"); // e.g. [] or ["🦁", "🐍", "🦍"]
242
248
  */
243
- deprecated_useList<TValue extends Lson>(key: string): LiveList<TValue> | null;
249
+ useList_deprecated<TValue extends Lson>(key: string): LiveList<TValue> | null;
244
250
  /**
245
251
  * @deprecated We no longer recommend initializing the
246
252
  * items from the useList() hook. For details, see https://bit.ly/3Niy5aP.
247
253
  */
248
- deprecated_useList<TValue extends Lson>(
254
+ useList_deprecated<TValue extends Lson>(
249
255
  key: string,
250
256
  items: TValue[]
251
257
  ): LiveList<TValue> | null;
@@ -259,14 +265,14 @@ declare type RoomContext<
259
265
  * @example
260
266
  * const shapesById = useMap("shapes");
261
267
  */
262
- deprecated_useMap<TKey extends string, TValue extends Lson>(
268
+ useMap_deprecated<TKey extends string, TValue extends Lson>(
263
269
  key: string
264
270
  ): LiveMap<TKey, TValue> | null;
265
271
  /**
266
272
  * @deprecated We no longer recommend initializing the
267
273
  * entries from the useMap() hook. For details, see https://bit.ly/3Niy5aP.
268
274
  */
269
- deprecated_useMap<TKey extends string, TValue extends Lson>(
275
+ useMap_deprecated<TKey extends string, TValue extends Lson>(
270
276
  key: string,
271
277
  entries: readonly (readonly [TKey, TValue])[] | null
272
278
  ): LiveMap<TKey, TValue> | null;
@@ -280,14 +286,14 @@ declare type RoomContext<
280
286
  * @example
281
287
  * const object = useObject("obj");
282
288
  */
283
- deprecated_useObject<TData extends LsonObject>(
289
+ useObject_deprecated<TData extends LsonObject>(
284
290
  key: string
285
291
  ): LiveObject<TData> | null;
286
292
  /**
287
293
  * @deprecated We no longer recommend initializing the fields from the
288
294
  * useObject() hook. For details, see https://bit.ly/3Niy5aP.
289
295
  */
290
- deprecated_useObject<TData extends LsonObject>(
296
+ useObject_deprecated<TData extends LsonObject>(
291
297
  key: string,
292
298
  initialData: TData
293
299
  ): LiveObject<TData> | null;
@@ -297,7 +303,9 @@ declare function createRoomContext<
297
303
  TStorage extends LsonObject = LsonObject,
298
304
  TUserMeta extends BaseUserMeta = BaseUserMeta,
299
305
  TRoomEvent extends Json = never
300
- >(client: Client): RoomContext<TPresence, TStorage, TUserMeta, TRoomEvent>;
306
+ >(
307
+ client: Client
308
+ ): RoomContextBundle<TPresence, TStorage, TUserMeta, TRoomEvent>;
301
309
 
302
310
  /**
303
311
  * NOTE:
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 =
@@ -75,9 +78,9 @@ function createRoomContext(client$1) {
75
78
  return client$1;
76
79
  }
77
80
  : useClient;
78
- var RoomCtx = React__namespace.createContext(null);
81
+ var RoomContext = React__namespace.createContext(null);
79
82
  function useRoom() {
80
- var room = React__namespace.useContext(RoomCtx);
83
+ var room = React__namespace.useContext(RoomContext);
81
84
  if (null == room)
82
85
  throw new Error("RoomProvider is missing from the react tree");
83
86
  return room;
@@ -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,10 +292,10 @@ 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
- RoomCtx.Provider,
298
+ RoomContext.Provider,
289
299
  { value: room },
290
300
  props.children
291
301
  )
@@ -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,10 @@ 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
+ RoomContext: RoomContext,
439
+ useList_deprecated: useList_deprecated,
440
+ useMap_deprecated: useMap_deprecated,
441
+ useObject_deprecated: useObject_deprecated,
431
442
  };
432
443
  }
433
444
  var _hooks = createRoomContext("__legacy");
@@ -498,7 +509,7 @@ var _hooks = createRoomContext("__legacy");
498
509
  internal.deprecate(
499
510
  "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
511
  ),
501
- _hooks.deprecated_useList(key, items)
512
+ _hooks.useList_deprecated(key, items)
502
513
  );
503
514
  }),
504
515
  (exports.useMap = function (key, entries) {
@@ -506,7 +517,7 @@ var _hooks = createRoomContext("__legacy");
506
517
  internal.deprecate(
507
518
  "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
519
  ),
509
- _hooks.deprecated_useMap(key, entries)
520
+ _hooks.useMap_deprecated(key, entries)
510
521
  );
511
522
  }),
512
523
  (exports.useMyPresence = function () {
@@ -522,7 +533,7 @@ var _hooks = createRoomContext("__legacy");
522
533
  internal.deprecate(
523
534
  "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
535
  ),
525
- _hooks.deprecated_useObject(key, initialData)
536
+ _hooks.useObject_deprecated(key, initialData)
526
537
  );
527
538
  }),
528
539
  (exports.useOthers = function () {
package/index.mjs CHANGED
@@ -55,12 +55,15 @@ 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;
61
- const RoomCtx = React.createContext(null);
64
+ const RoomContext = React.createContext(null);
62
65
  function useRoom() {
63
- const room = React.useContext(RoomCtx);
66
+ const room = React.useContext(RoomContext);
64
67
  if (null == room)
65
68
  throw new Error("RoomProvider is missing from the react tree");
66
69
  return room;
@@ -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,9 +249,13 @@ function createRoomContext(client) {
239
249
  _client.leave(roomId);
240
250
  }
241
251
  ),
242
- [_client, roomId]
252
+ [_client, roomId, frozen]
243
253
  ),
244
- React.createElement(RoomCtx.Provider, { value: room }, props.children)
254
+ React.createElement(
255
+ RoomContext.Provider,
256
+ { value: room },
257
+ props.children
258
+ )
245
259
  );
246
260
  },
247
261
  useBatch: function () {
@@ -288,10 +302,10 @@ function createRoomContext(client) {
288
302
  },
289
303
  useHistory: useHistory,
290
304
  useList: function (key) {
291
- return deprecated_useList(key);
305
+ return useList_deprecated(key);
292
306
  },
293
307
  useMap: function (key) {
294
- return deprecated_useMap(key);
308
+ return useMap_deprecated(key);
295
309
  },
296
310
  useMyPresence: function () {
297
311
  const room = useRoom(),
@@ -303,7 +317,7 @@ function createRoomContext(client) {
303
317
  return () => {
304
318
  unsubscribe();
305
319
  };
306
- }, [room]),
320
+ }, [room, rerender]),
307
321
  [
308
322
  presence,
309
323
  React.useCallback(
@@ -314,7 +328,7 @@ function createRoomContext(client) {
314
328
  );
315
329
  },
316
330
  useObject: function (key) {
317
- return deprecated_useObject(key);
331
+ return useObject_deprecated(key);
318
332
  },
319
333
  useOthers: function () {
320
334
  const room = useRoom(),
@@ -325,7 +339,7 @@ function createRoomContext(client) {
325
339
  return () => {
326
340
  unsubscribe();
327
341
  };
328
- }, [room]),
342
+ }, [room, rerender]),
329
343
  room.getOthers()
330
344
  );
331
345
  },
@@ -343,7 +357,7 @@ function createRoomContext(client) {
343
357
  return () => {
344
358
  unsubscribePresence(), unsubscribeConnection();
345
359
  };
346
- }, [room]),
360
+ }, [room, rerender]),
347
361
  room.getSelf()
348
362
  );
349
363
  },
@@ -360,9 +374,10 @@ function createRoomContext(client) {
360
374
  [room]
361
375
  );
362
376
  },
363
- deprecated_useList: deprecated_useList,
364
- deprecated_useMap: deprecated_useMap,
365
- deprecated_useObject: deprecated_useObject,
377
+ RoomContext: RoomContext,
378
+ useList_deprecated: useList_deprecated,
379
+ useMap_deprecated: useMap_deprecated,
380
+ useObject_deprecated: useObject_deprecated,
366
381
  };
367
382
  }
368
383
  const _hooks = createRoomContext("__legacy");
@@ -483,7 +498,7 @@ function useList(key, items) {
483
498
  deprecate(
484
499
  "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
500
  ),
486
- _hooks.deprecated_useList(key, items)
501
+ _hooks.useList_deprecated(key, items)
487
502
  );
488
503
  }
489
504
  function useMap(key, entries) {
@@ -491,7 +506,7 @@ function useMap(key, entries) {
491
506
  deprecate(
492
507
  "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
508
  ),
494
- _hooks.deprecated_useMap(key, entries)
509
+ _hooks.useMap_deprecated(key, entries)
495
510
  );
496
511
  }
497
512
  function useObject(key, initialData) {
@@ -499,7 +514,7 @@ function useObject(key, initialData) {
499
514
  deprecate(
500
515
  "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
516
  ),
502
- _hooks.deprecated_useObject(key, initialData)
517
+ _hooks.useObject_deprecated(key, initialData)
503
518
  );
504
519
  }
505
520
  export {
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@liveblocks/react",
3
- "version": "0.17.4",
3
+ "version": "0.17.7",
4
4
  "description": "A set of React hooks and providers to use Liveblocks declaratively.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
7
7
  "types": "./index.d.ts",
8
- "files": [
9
- "**"
10
- ],
11
8
  "keywords": [
12
9
  "react",
13
10
  "liveblocks",
@@ -18,49 +15,11 @@
18
15
  "bugs": {
19
16
  "url": "https://github.com/liveblocks/liveblocks/issues"
20
17
  },
21
- "scripts": {
22
- "build": "rollup -c && cp ./package.json ./README.md ./lib",
23
- "start": "rollup -c -w",
24
- "format": "eslint --fix src/ && prettier --write src/",
25
- "lint": "eslint src/",
26
- "test": "jest --watch --silent --verbose",
27
- "test-ci": "jest --silent --verbose",
28
- "codegen": "tsc scripts/generate-compat.ts && node scripts/generate-compat.js && eslint --fix src/compat.tsx && prettier --write src/compat.tsx"
29
- },
30
18
  "license": "Apache-2.0",
31
19
  "peerDependencies": {
32
- "@liveblocks/client": "0.17.4",
20
+ "@liveblocks/client": "0.17.7",
33
21
  "react": "^16.14.0 || ^17 || ^18"
34
22
  },
35
- "devDependencies": {
36
- "@babel/core": "^7.17.10",
37
- "@babel/preset-env": "^7.17.10",
38
- "@babel/preset-react": "^7.16.7",
39
- "@babel/preset-typescript": "^7.16.7",
40
- "@rollup/plugin-babel": "^5.3.1",
41
- "@rollup/plugin-node-resolve": "^11.2.1",
42
- "@rollup/plugin-replace": "^4.0.0",
43
- "@rollup/plugin-typescript": "^8.3.1",
44
- "@testing-library/jest-dom": "^5.11.9",
45
- "@testing-library/react": "^13.1.1",
46
- "@types/jest": "^26.0.24",
47
- "@typescript-eslint/eslint-plugin": "^5.26.0",
48
- "@typescript-eslint/parser": "^5.26.0",
49
- "eslint": "^8.12.0",
50
- "eslint-plugin-import": "^2.26.0",
51
- "eslint-plugin-simple-import-sort": "^7.0.0",
52
- "jest": "^26.6.3",
53
- "msw": "^0.27.1",
54
- "react-error-boundary": "^3.1.1",
55
- "rollup": "^2.39.0",
56
- "rollup-plugin-command": "^1.1.3",
57
- "rollup-plugin-dts": "^4.2.2",
58
- "rollup-plugin-prettier": "^2.2.2",
59
- "rollup-plugin-terser": "^7.0.2",
60
- "ts-node": "^10.8.1",
61
- "typescript": "^4.7.3",
62
- "whatwg-fetch": "^3.6.2"
63
- },
64
23
  "repository": {
65
24
  "type": "git",
66
25
  "url": "https://github.com/liveblocks/liveblocks.git",