@liveblocks/core 2.14.0-v2encoding → 2.15.0-debug1

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.mjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "2.14.0-v2encoding";
9
+ var PKG_VERSION = "2.15.0-debug1";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -2668,7 +2668,7 @@ var ManagedSocket = class {
2668
2668
  #machine;
2669
2669
  #cleanups;
2670
2670
  events;
2671
- constructor(delegates, enableDebugLogging = false, waitForActorId = true) {
2671
+ constructor(delegates, enableDebugLogging = true, waitForActorId = true) {
2672
2672
  const { machine, events, cleanups } = createConnectionStateMachine(
2673
2673
  delegates,
2674
2674
  { waitForActorId, enableDebugLogging }
@@ -3214,68 +3214,13 @@ function unlinkDevTools(roomId) {
3214
3214
  });
3215
3215
  }
3216
3216
 
3217
- // src/lib/create-store.ts
3218
- function createStore(initialState) {
3219
- let notifyImmediately = true;
3220
- let dirty = false;
3221
- let state = initialState;
3222
- const subscribers = /* @__PURE__ */ new Set();
3223
- function get() {
3224
- return state;
3225
- }
3226
- function set(callback) {
3227
- const oldState = state;
3228
- const newState = callback(oldState);
3229
- if (newState !== oldState) {
3230
- state = newState;
3231
- dirty = true;
3232
- }
3233
- if (notifyImmediately) {
3234
- notify();
3235
- }
3236
- }
3237
- function notify() {
3238
- if (!dirty) {
3239
- return;
3240
- }
3241
- dirty = false;
3242
- for (const subscriber of subscribers) {
3243
- subscriber(state);
3244
- }
3245
- }
3246
- function batch2(cb) {
3247
- if (notifyImmediately === false) {
3248
- return cb();
3249
- }
3250
- notifyImmediately = false;
3251
- try {
3252
- cb();
3253
- } finally {
3254
- notifyImmediately = true;
3255
- notify();
3256
- }
3257
- }
3258
- function subscribe(callback) {
3259
- subscribers.add(callback);
3260
- return () => {
3261
- subscribers.delete(callback);
3262
- };
3263
- }
3264
- return {
3265
- get,
3266
- set,
3267
- batch: batch2,
3268
- subscribe
3269
- };
3270
- }
3271
-
3272
3217
  // src/lib/freeze.ts
3273
3218
  var freeze = process.env.NODE_ENV === "production" ? (
3274
3219
  /* istanbul ignore next */
3275
3220
  (x) => x
3276
3221
  ) : Object.freeze;
3277
3222
 
3278
- // src/lib/Signal.ts
3223
+ // src/lib/signals.ts
3279
3224
  var kSinks = Symbol("kSinks");
3280
3225
  var kTrigger = Symbol("kTrigger");
3281
3226
  var signalsToTrigger = null;
@@ -3515,7 +3460,7 @@ var MutableSignal = class extends AbstractSignal {
3515
3460
  */
3516
3461
  mutate(callback) {
3517
3462
  batch(() => {
3518
- const result = callback(this.#state);
3463
+ const result = callback ? callback(this.#state) : true;
3519
3464
  if (result !== null && typeof result === "object" && "then" in result) {
3520
3465
  raise("MutableSignal.mutate() does not support async callbacks");
3521
3466
  }
@@ -6324,8 +6269,25 @@ function createRoom(options, config) {
6324
6269
  // Debug
6325
6270
  opStackTraces: process.env.NODE_ENV !== "production" ? /* @__PURE__ */ new Map() : void 0
6326
6271
  };
6327
- const doNotBatchUpdates = (cb) => cb();
6328
- const batchUpdates = config.unstable_batchedUpdates ?? doNotBatchUpdates;
6272
+ function printPending(cs) {
6273
+ if (cs) globalThis.console.log(`[debug] at ${cs}`);
6274
+ if (context.unacknowledgedOps.size === 0) {
6275
+ globalThis.console.log("[debug] no pending ops");
6276
+ } else {
6277
+ globalThis.console.log(
6278
+ `[debug] pending ops (${context.unacknowledgedOps.size}):`
6279
+ );
6280
+ for (const [opId, op] of context.unacknowledgedOps) {
6281
+ globalThis.console.log(
6282
+ "[debug] opid=",
6283
+ opId,
6284
+ "op=",
6285
+ JSON.stringify(op)
6286
+ );
6287
+ }
6288
+ }
6289
+ globalThis.console.log("[debug] storage status", getStorageStatus());
6290
+ }
6329
6291
  let lastTokenKey;
6330
6292
  function onStatusDidChange(newStatus) {
6331
6293
  const authValue = managedSocket.authValue;
@@ -6347,34 +6309,26 @@ function createRoom(options, config) {
6347
6309
  }
6348
6310
  }
6349
6311
  }
6350
- batchUpdates(() => {
6351
- eventHub.status.notify(newStatus);
6352
- notifySelfChanged(doNotBatchUpdates);
6353
- });
6312
+ eventHub.status.notify(newStatus);
6313
+ notifySelfChanged();
6354
6314
  }
6355
6315
  let _connectionLossTimerId;
6356
6316
  let _hasLostConnection = false;
6357
6317
  function handleConnectionLossEvent(newStatus) {
6358
6318
  if (newStatus === "reconnecting") {
6359
6319
  _connectionLossTimerId = setTimeout(() => {
6360
- batchUpdates(() => {
6361
- eventHub.lostConnection.notify("lost");
6362
- _hasLostConnection = true;
6363
- context.others.clearOthers();
6364
- notify({ others: [{ type: "reset" }] }, doNotBatchUpdates);
6365
- });
6320
+ eventHub.lostConnection.notify("lost");
6321
+ _hasLostConnection = true;
6322
+ context.others.clearOthers();
6323
+ notify({ others: [{ type: "reset" }] });
6366
6324
  }, config.lostConnectionTimeout);
6367
6325
  } else {
6368
6326
  clearTimeout(_connectionLossTimerId);
6369
6327
  if (_hasLostConnection) {
6370
6328
  if (newStatus === "disconnected") {
6371
- batchUpdates(() => {
6372
- eventHub.lostConnection.notify("failed");
6373
- });
6329
+ eventHub.lostConnection.notify("failed");
6374
6330
  } else {
6375
- batchUpdates(() => {
6376
- eventHub.lostConnection.notify("restored");
6377
- });
6331
+ eventHub.lostConnection.notify("restored");
6378
6332
  }
6379
6333
  _hasLostConnection = false;
6380
6334
  }
@@ -6404,14 +6358,12 @@ function createRoom(options, config) {
6404
6358
  managedSocket.events.didConnect.subscribe(onDidConnect);
6405
6359
  managedSocket.events.didDisconnect.subscribe(onDidDisconnect);
6406
6360
  managedSocket.events.onLiveblocksError.subscribe((err) => {
6407
- batchUpdates(() => {
6408
- if (process.env.NODE_ENV !== "production") {
6409
- error2(
6410
- `Connection to websocket server closed. Reason: ${err.message} (code: ${err.code}).`
6411
- );
6412
- }
6413
- eventHub.error.notify(err);
6414
- });
6361
+ if (process.env.NODE_ENV !== "production") {
6362
+ error2(
6363
+ `Connection to websocket server closed. Reason: ${err.message} (code: ${err.code}).`
6364
+ );
6365
+ }
6366
+ eventHub.error.notify(err);
6415
6367
  });
6416
6368
  const pool = {
6417
6369
  roomId: config.roomId,
@@ -6447,12 +6399,10 @@ function createRoom(options, config) {
6447
6399
  }
6448
6400
  activeBatch.reverseOps.unshift(...reverse);
6449
6401
  } else {
6450
- batchUpdates(() => {
6451
- addToUndoStack(reverse, doNotBatchUpdates);
6452
- context.redoStack.length = 0;
6453
- dispatchOps(ops);
6454
- notify({ storageUpdates }, doNotBatchUpdates);
6455
- });
6402
+ addToUndoStack(reverse);
6403
+ context.redoStack.length = 0;
6404
+ dispatchOps(ops);
6405
+ notify({ storageUpdates });
6456
6406
  }
6457
6407
  },
6458
6408
  assertStorageIsWritable: () => {
@@ -6550,12 +6500,10 @@ function createRoom(options, config) {
6550
6500
  }
6551
6501
  );
6552
6502
  let _lastSelf;
6553
- function notifySelfChanged(batchedUpdatesWrapper) {
6503
+ function notifySelfChanged() {
6554
6504
  const currSelf = self.get();
6555
6505
  if (currSelf !== null && currSelf !== _lastSelf) {
6556
- batchedUpdatesWrapper(() => {
6557
- eventHub.self.notify(currSelf);
6558
- });
6506
+ eventHub.self.notify(currSelf);
6559
6507
  _lastSelf = currSelf;
6560
6508
  }
6561
6509
  }
@@ -6563,12 +6511,12 @@ function createRoom(options, config) {
6563
6511
  self,
6564
6512
  (me) => me !== null ? userToTreeNode("Me", me) : null
6565
6513
  );
6566
- function createOrUpdateRootFromMessage(message, batchedUpdatesWrapper) {
6514
+ function createOrUpdateRootFromMessage(message) {
6567
6515
  if (message.items.length === 0) {
6568
6516
  throw new Error("Internal error: cannot load storage without items");
6569
6517
  }
6570
6518
  if (context.root !== void 0) {
6571
- updateRoot(message.items, batchedUpdatesWrapper);
6519
+ updateRoot(message.items);
6572
6520
  } else {
6573
6521
  context.root = LiveObject._fromItems(message.items, pool);
6574
6522
  }
@@ -6587,7 +6535,7 @@ function createRoom(options, config) {
6587
6535
  }
6588
6536
  context.undoStack.length = stackSizeBefore;
6589
6537
  }
6590
- function updateRoot(items, batchedUpdatesWrapper) {
6538
+ function updateRoot(items) {
6591
6539
  if (context.root === void 0) {
6592
6540
  return;
6593
6541
  }
@@ -6597,42 +6545,40 @@ function createRoom(options, config) {
6597
6545
  }
6598
6546
  const ops = getTreesDiffOperations(currentItems, new Map(items));
6599
6547
  const result = applyOps(ops, false);
6600
- notify(result.updates, batchedUpdatesWrapper);
6548
+ notify(result.updates);
6601
6549
  }
6602
- function _addToRealUndoStack(historyOps, batchedUpdatesWrapper) {
6550
+ function _addToRealUndoStack(historyOps) {
6603
6551
  if (context.undoStack.length >= 50) {
6604
6552
  context.undoStack.shift();
6605
6553
  }
6606
6554
  context.undoStack.push(historyOps);
6607
- onHistoryChange(batchedUpdatesWrapper);
6555
+ onHistoryChange();
6608
6556
  }
6609
- function addToUndoStack(historyOps, batchedUpdatesWrapper) {
6557
+ function addToUndoStack(historyOps) {
6610
6558
  if (context.pausedHistory !== null) {
6611
6559
  context.pausedHistory.unshift(...historyOps);
6612
6560
  } else {
6613
- _addToRealUndoStack(historyOps, batchedUpdatesWrapper);
6561
+ _addToRealUndoStack(historyOps);
6614
6562
  }
6615
6563
  }
6616
- function notify(updates, batchedUpdatesWrapper) {
6564
+ function notify(updates) {
6617
6565
  const storageUpdates = updates.storageUpdates;
6618
6566
  const othersUpdates = updates.others;
6619
- batchedUpdatesWrapper(() => {
6620
- if (othersUpdates !== void 0 && othersUpdates.length > 0) {
6621
- const others = context.others.get();
6622
- for (const event of othersUpdates) {
6623
- eventHub.others.notify({ ...event, others });
6624
- }
6625
- }
6626
- if (updates.presence ?? false) {
6627
- notifySelfChanged(doNotBatchUpdates);
6628
- eventHub.myPresence.notify(context.myPresence.get());
6629
- }
6630
- if (storageUpdates !== void 0 && storageUpdates.size > 0) {
6631
- const updates2 = Array.from(storageUpdates.values());
6632
- eventHub.storageBatch.notify(updates2);
6567
+ if (othersUpdates !== void 0 && othersUpdates.length > 0) {
6568
+ const others = context.others.get();
6569
+ for (const event of othersUpdates) {
6570
+ eventHub.others.notify({ ...event, others });
6633
6571
  }
6634
- notifyStorageStatus();
6635
- });
6572
+ }
6573
+ if (updates.presence ?? false) {
6574
+ notifySelfChanged();
6575
+ eventHub.myPresence.notify(context.myPresence.get());
6576
+ }
6577
+ if (storageUpdates !== void 0 && storageUpdates.size > 0) {
6578
+ const updates2 = Array.from(storageUpdates.values());
6579
+ eventHub.storageBatch.notify(updates2);
6580
+ }
6581
+ notifyStorageStatus();
6636
6582
  }
6637
6583
  function getConnectionId() {
6638
6584
  const info = context.dynamicSessionInfoSig.get();
@@ -6644,6 +6590,7 @@ function createRoom(options, config) {
6644
6590
  );
6645
6591
  }
6646
6592
  function applyOps(rawOps, isLocal) {
6593
+ printPending("start of applyOps");
6647
6594
  const output = {
6648
6595
  reverse: [],
6649
6596
  storageUpdates: /* @__PURE__ */ new Map(),
@@ -6686,6 +6633,9 @@ function createRoom(options, config) {
6686
6633
  nn(context.opStackTraces).delete(opId);
6687
6634
  }
6688
6635
  const deleted = context.unacknowledgedOps.delete(opId);
6636
+ if (deleted) {
6637
+ globalThis.console.log("[debug] acked", opId);
6638
+ }
6689
6639
  source = deleted ? 2 /* ACK */ : 1 /* REMOTE */;
6690
6640
  }
6691
6641
  const applyOpResult = applyOp(op, source);
@@ -6707,6 +6657,7 @@ function createRoom(options, config) {
6707
6657
  }
6708
6658
  }
6709
6659
  }
6660
+ printPending("end of applyOps");
6710
6661
  return {
6711
6662
  ops,
6712
6663
  reverse: output.reverse,
@@ -6786,15 +6737,10 @@ function createRoom(options, config) {
6786
6737
  context.activeBatch.updates.presence = true;
6787
6738
  } else {
6788
6739
  flushNowOrSoon();
6789
- batchUpdates(() => {
6790
- if (options2?.addToHistory) {
6791
- addToUndoStack(
6792
- [{ type: "presence", data: oldValues }],
6793
- doNotBatchUpdates
6794
- );
6795
- }
6796
- notify({ presence: true }, doNotBatchUpdates);
6797
- });
6740
+ if (options2?.addToHistory) {
6741
+ addToUndoStack([{ type: "presence", data: oldValues }]);
6742
+ }
6743
+ notify({ presence: true });
6798
6744
  }
6799
6745
  }
6800
6746
  function onUpdatePresenceMessage(message) {
@@ -6827,14 +6773,14 @@ function createRoom(options, config) {
6827
6773
  }
6828
6774
  return null;
6829
6775
  }
6830
- function onRoomStateMessage(message, batchedUpdatesWrapper) {
6776
+ function onRoomStateMessage(message) {
6831
6777
  context.dynamicSessionInfoSig.set({
6832
6778
  actor: message.actor,
6833
6779
  nonce: message.nonce,
6834
6780
  scopes: message.scopes
6835
6781
  });
6836
6782
  context.idFactory = makeIdFactory(message.actor);
6837
- notifySelfChanged(batchedUpdatesWrapper);
6783
+ notifySelfChanged();
6838
6784
  for (const connectionId of context.others.connectionIds()) {
6839
6785
  const user = message.users[connectionId];
6840
6786
  if (user === void 0) {
@@ -6859,10 +6805,8 @@ function createRoom(options, config) {
6859
6805
  function canRedo() {
6860
6806
  return context.redoStack.length > 0;
6861
6807
  }
6862
- function onHistoryChange(batchedUpdatesWrapper) {
6863
- batchedUpdatesWrapper(() => {
6864
- eventHub.history.notify({ canUndo: canUndo(), canRedo: canRedo() });
6865
- });
6808
+ function onHistoryChange() {
6809
+ eventHub.history.notify({ canUndo: canUndo(), canRedo: canRedo() });
6866
6810
  }
6867
6811
  function onUserJoinedMessage(message) {
6868
6812
  context.others.setConnection(
@@ -6896,7 +6840,7 @@ function createRoom(options, config) {
6896
6840
  return compact([parseServerMessage(data)]);
6897
6841
  }
6898
6842
  }
6899
- function applyAndSendOps(offlineOps, batchedUpdatesWrapper) {
6843
+ function applyAndSendOps(offlineOps) {
6900
6844
  if (offlineOps.size === 0) {
6901
6845
  return;
6902
6846
  }
@@ -6907,7 +6851,7 @@ function createRoom(options, config) {
6907
6851
  type: 201 /* UPDATE_STORAGE */,
6908
6852
  ops: result.ops
6909
6853
  });
6910
- notify(result.updates, batchedUpdatesWrapper);
6854
+ notify(result.updates);
6911
6855
  sendMessages(messages);
6912
6856
  }
6913
6857
  function handleServerMessage(event) {
@@ -6922,104 +6866,102 @@ function createRoom(options, config) {
6922
6866
  storageUpdates: /* @__PURE__ */ new Map(),
6923
6867
  others: []
6924
6868
  };
6925
- batchUpdates(() => {
6926
- for (const message of messages) {
6927
- switch (message.type) {
6928
- case 101 /* USER_JOINED */: {
6929
- const userJoinedUpdate = onUserJoinedMessage(message);
6930
- if (userJoinedUpdate) {
6931
- updates.others.push(userJoinedUpdate);
6932
- }
6933
- break;
6869
+ for (const message of messages) {
6870
+ switch (message.type) {
6871
+ case 101 /* USER_JOINED */: {
6872
+ const userJoinedUpdate = onUserJoinedMessage(message);
6873
+ if (userJoinedUpdate) {
6874
+ updates.others.push(userJoinedUpdate);
6934
6875
  }
6935
- case 100 /* UPDATE_PRESENCE */: {
6936
- const othersPresenceUpdate = onUpdatePresenceMessage(message);
6937
- if (othersPresenceUpdate) {
6938
- updates.others.push(othersPresenceUpdate);
6939
- }
6940
- break;
6941
- }
6942
- case 103 /* BROADCASTED_EVENT */: {
6943
- const others = context.others.get();
6944
- eventHub.customEvent.notify({
6945
- connectionId: message.actor,
6946
- user: message.actor < 0 ? null : others.find((u) => u.connectionId === message.actor) ?? null,
6947
- event: message.event
6948
- });
6949
- break;
6950
- }
6951
- case 102 /* USER_LEFT */: {
6952
- const event2 = onUserLeftMessage(message);
6953
- if (event2) {
6954
- updates.others.push(event2);
6955
- }
6956
- break;
6957
- }
6958
- case 300 /* UPDATE_YDOC */: {
6959
- eventHub.ydoc.notify(message);
6960
- break;
6961
- }
6962
- case 104 /* ROOM_STATE */: {
6963
- updates.others.push(onRoomStateMessage(message, doNotBatchUpdates));
6964
- break;
6965
- }
6966
- case 200 /* INITIAL_STORAGE_STATE */: {
6967
- processInitialStorage(message);
6968
- break;
6876
+ break;
6877
+ }
6878
+ case 100 /* UPDATE_PRESENCE */: {
6879
+ const othersPresenceUpdate = onUpdatePresenceMessage(message);
6880
+ if (othersPresenceUpdate) {
6881
+ updates.others.push(othersPresenceUpdate);
6969
6882
  }
6970
- case 201 /* UPDATE_STORAGE */: {
6971
- const applyResult = applyOps(message.ops, false);
6972
- for (const [key, value] of applyResult.updates.storageUpdates) {
6973
- updates.storageUpdates.set(
6974
- key,
6975
- mergeStorageUpdates(updates.storageUpdates.get(key), value)
6976
- );
6977
- }
6978
- break;
6883
+ break;
6884
+ }
6885
+ case 103 /* BROADCASTED_EVENT */: {
6886
+ const others = context.others.get();
6887
+ eventHub.customEvent.notify({
6888
+ connectionId: message.actor,
6889
+ user: message.actor < 0 ? null : others.find((u) => u.connectionId === message.actor) ?? null,
6890
+ event: message.event
6891
+ });
6892
+ break;
6893
+ }
6894
+ case 102 /* USER_LEFT */: {
6895
+ const event2 = onUserLeftMessage(message);
6896
+ if (event2) {
6897
+ updates.others.push(event2);
6979
6898
  }
6980
- case 299 /* REJECT_STORAGE_OP */: {
6981
- errorWithTitle(
6982
- "Storage mutation rejection error",
6983
- message.reason
6899
+ break;
6900
+ }
6901
+ case 300 /* UPDATE_YDOC */: {
6902
+ eventHub.ydoc.notify(message);
6903
+ break;
6904
+ }
6905
+ case 104 /* ROOM_STATE */: {
6906
+ updates.others.push(onRoomStateMessage(message));
6907
+ break;
6908
+ }
6909
+ case 200 /* INITIAL_STORAGE_STATE */: {
6910
+ processInitialStorage(message);
6911
+ break;
6912
+ }
6913
+ case 201 /* UPDATE_STORAGE */: {
6914
+ const applyResult = applyOps(message.ops, false);
6915
+ for (const [key, value] of applyResult.updates.storageUpdates) {
6916
+ updates.storageUpdates.set(
6917
+ key,
6918
+ mergeStorageUpdates(updates.storageUpdates.get(key), value)
6984
6919
  );
6985
- if (process.env.NODE_ENV !== "production") {
6986
- const traces = /* @__PURE__ */ new Set();
6987
- for (const opId of message.opIds) {
6988
- const trace = context.opStackTraces?.get(opId);
6989
- if (trace) {
6990
- traces.add(trace);
6991
- }
6920
+ }
6921
+ break;
6922
+ }
6923
+ case 299 /* REJECT_STORAGE_OP */: {
6924
+ errorWithTitle(
6925
+ "Storage mutation rejection error",
6926
+ message.reason
6927
+ );
6928
+ if (process.env.NODE_ENV !== "production") {
6929
+ const traces = /* @__PURE__ */ new Set();
6930
+ for (const opId of message.opIds) {
6931
+ const trace = context.opStackTraces?.get(opId);
6932
+ if (trace) {
6933
+ traces.add(trace);
6992
6934
  }
6993
- if (traces.size > 0) {
6994
- warnWithTitle(
6995
- "The following function calls caused the rejected storage mutations:",
6996
- `
6935
+ }
6936
+ if (traces.size > 0) {
6937
+ warnWithTitle(
6938
+ "The following function calls caused the rejected storage mutations:",
6939
+ `
6997
6940
 
6998
6941
  ${Array.from(traces).join("\n\n")}`
6999
- );
7000
- }
7001
- throw new Error(
7002
- `Storage mutations rejected by server: ${message.reason}`
7003
6942
  );
7004
6943
  }
7005
- break;
7006
- }
7007
- case 400 /* THREAD_CREATED */:
7008
- case 407 /* THREAD_DELETED */:
7009
- case 401 /* THREAD_METADATA_UPDATED */:
7010
- case 408 /* THREAD_UPDATED */:
7011
- case 405 /* COMMENT_REACTION_ADDED */:
7012
- case 406 /* COMMENT_REACTION_REMOVED */:
7013
- case 402 /* COMMENT_CREATED */:
7014
- case 403 /* COMMENT_EDITED */:
7015
- case 404 /* COMMENT_DELETED */: {
7016
- eventHub.comments.notify(message);
7017
- break;
6944
+ throw new Error(
6945
+ `Storage mutations rejected by server: ${message.reason}`
6946
+ );
7018
6947
  }
6948
+ break;
6949
+ }
6950
+ case 400 /* THREAD_CREATED */:
6951
+ case 407 /* THREAD_DELETED */:
6952
+ case 401 /* THREAD_METADATA_UPDATED */:
6953
+ case 408 /* THREAD_UPDATED */:
6954
+ case 405 /* COMMENT_REACTION_ADDED */:
6955
+ case 406 /* COMMENT_REACTION_REMOVED */:
6956
+ case 402 /* COMMENT_CREATED */:
6957
+ case 403 /* COMMENT_EDITED */:
6958
+ case 404 /* COMMENT_DELETED */: {
6959
+ eventHub.comments.notify(message);
6960
+ break;
7019
6961
  }
7020
6962
  }
7021
- notify(updates, doNotBatchUpdates);
7022
- });
6963
+ }
6964
+ notify(updates);
7023
6965
  }
7024
6966
  function flushNowOrSoon() {
7025
6967
  const storageOps = context.buffer.storageOperations;
@@ -7027,6 +6969,7 @@ ${Array.from(traces).join("\n\n")}`
7027
6969
  for (const op of storageOps) {
7028
6970
  context.unacknowledgedOps.set(nn(op.opId), op);
7029
6971
  }
6972
+ printPending("flushNowOrSoon");
7030
6973
  notifyStorageStatus();
7031
6974
  }
7032
6975
  if (managedSocket.getStatus() !== "connected") {
@@ -7084,12 +7027,11 @@ ${Array.from(traces).join("\n\n")}`
7084
7027
  }
7085
7028
  return messages;
7086
7029
  }
7087
- function updateYDoc(update, guid, isV2) {
7030
+ function updateYDoc(update, guid) {
7088
7031
  const clientMsg = {
7089
7032
  type: 301 /* UPDATE_YDOC */,
7090
7033
  update,
7091
- guid,
7092
- v2: isV2
7034
+ guid
7093
7035
  };
7094
7036
  context.buffer.messages.push(clientMsg);
7095
7037
  eventHub.ydoc.notify(clientMsg);
@@ -7117,9 +7059,10 @@ ${Array.from(traces).join("\n\n")}`
7117
7059
  let _getStorage$ = null;
7118
7060
  let _resolveStoragePromise = null;
7119
7061
  function processInitialStorage(message) {
7062
+ printPending("initial local ops");
7120
7063
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
7121
- createOrUpdateRootFromMessage(message, doNotBatchUpdates);
7122
- applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
7064
+ createOrUpdateRootFromMessage(message);
7065
+ applyAndSendOps(unacknowledgedOps);
7123
7066
  _resolveStoragePromise?.();
7124
7067
  notifyStorageStatus();
7125
7068
  eventHub.storageDidLoad.notify();
@@ -7170,15 +7113,14 @@ ${Array.from(traces).join("\n\n")}`
7170
7113
  root: nn(context.root)
7171
7114
  };
7172
7115
  }
7173
- function fetchYDoc(vector, guid, isV2) {
7116
+ function fetchYDoc(vector, guid) {
7174
7117
  if (!context.buffer.messages.find((m) => {
7175
- return m.type === 300 /* FETCH_YDOC */ && m.vector === vector && m.guid === guid && m.v2 === isV2;
7118
+ return m.type === 300 /* FETCH_YDOC */ && m.vector === vector && m.guid === guid;
7176
7119
  })) {
7177
7120
  context.buffer.messages.push({
7178
7121
  type: 300 /* FETCH_YDOC */,
7179
7122
  vector,
7180
- guid,
7181
- v2: isV2
7123
+ guid
7182
7124
  });
7183
7125
  }
7184
7126
  flushNowOrSoon();
@@ -7193,11 +7135,9 @@ ${Array.from(traces).join("\n\n")}`
7193
7135
  }
7194
7136
  context.pausedHistory = null;
7195
7137
  const result = applyOps(historyOps, true);
7196
- batchUpdates(() => {
7197
- notify(result.updates, doNotBatchUpdates);
7198
- context.redoStack.push(result.reverse);
7199
- onHistoryChange(doNotBatchUpdates);
7200
- });
7138
+ notify(result.updates);
7139
+ context.redoStack.push(result.reverse);
7140
+ onHistoryChange();
7201
7141
  for (const op of result.ops) {
7202
7142
  if (op.type !== "presence") {
7203
7143
  context.buffer.storageOperations.push(op);
@@ -7215,11 +7155,9 @@ ${Array.from(traces).join("\n\n")}`
7215
7155
  }
7216
7156
  context.pausedHistory = null;
7217
7157
  const result = applyOps(historyOps, true);
7218
- batchUpdates(() => {
7219
- notify(result.updates, doNotBatchUpdates);
7220
- context.undoStack.push(result.reverse);
7221
- onHistoryChange(doNotBatchUpdates);
7222
- });
7158
+ notify(result.updates);
7159
+ context.undoStack.push(result.reverse);
7160
+ onHistoryChange();
7223
7161
  for (const op of result.ops) {
7224
7162
  if (op.type !== "presence") {
7225
7163
  context.buffer.storageOperations.push(op);
@@ -7236,34 +7174,32 @@ ${Array.from(traces).join("\n\n")}`
7236
7174
  return callback();
7237
7175
  }
7238
7176
  let returnValue = void 0;
7239
- batchUpdates(() => {
7240
- context.activeBatch = {
7241
- ops: [],
7242
- updates: {
7243
- storageUpdates: /* @__PURE__ */ new Map(),
7244
- presence: false,
7245
- others: []
7246
- },
7247
- reverseOps: []
7248
- };
7249
- try {
7250
- returnValue = callback();
7251
- } finally {
7252
- const currentBatch = context.activeBatch;
7253
- context.activeBatch = null;
7254
- if (currentBatch.reverseOps.length > 0) {
7255
- addToUndoStack(currentBatch.reverseOps, doNotBatchUpdates);
7256
- }
7257
- if (currentBatch.ops.length > 0) {
7258
- context.redoStack.length = 0;
7259
- }
7260
- if (currentBatch.ops.length > 0) {
7261
- dispatchOps(currentBatch.ops);
7262
- }
7263
- notify(currentBatch.updates, doNotBatchUpdates);
7264
- flushNowOrSoon();
7177
+ context.activeBatch = {
7178
+ ops: [],
7179
+ updates: {
7180
+ storageUpdates: /* @__PURE__ */ new Map(),
7181
+ presence: false,
7182
+ others: []
7183
+ },
7184
+ reverseOps: []
7185
+ };
7186
+ try {
7187
+ returnValue = callback();
7188
+ } finally {
7189
+ const currentBatch = context.activeBatch;
7190
+ context.activeBatch = null;
7191
+ if (currentBatch.reverseOps.length > 0) {
7192
+ addToUndoStack(currentBatch.reverseOps);
7265
7193
  }
7266
- });
7194
+ if (currentBatch.ops.length > 0) {
7195
+ context.redoStack.length = 0;
7196
+ }
7197
+ if (currentBatch.ops.length > 0) {
7198
+ dispatchOps(currentBatch.ops);
7199
+ }
7200
+ notify(currentBatch.updates);
7201
+ flushNowOrSoon();
7202
+ }
7267
7203
  return returnValue;
7268
7204
  }
7269
7205
  function pauseHistory() {
@@ -7275,7 +7211,7 @@ ${Array.from(traces).join("\n\n")}`
7275
7211
  const historyOps = context.pausedHistory;
7276
7212
  context.pausedHistory = null;
7277
7213
  if (historyOps !== null && historyOps.length > 0) {
7278
- _addToRealUndoStack(historyOps, batchUpdates);
7214
+ _addToRealUndoStack(historyOps);
7279
7215
  }
7280
7216
  }
7281
7217
  const syncSourceForStorage = config.createSyncSource();
@@ -7738,10 +7674,10 @@ function createClient(options) {
7738
7674
  clientOptions.backgroundKeepAliveTimeout
7739
7675
  );
7740
7676
  const baseUrl = getBaseUrl(clientOptions.baseUrl);
7741
- const currentUserIdStore = createStore(void 0);
7677
+ const currentUserId = new Signal(void 0);
7742
7678
  const authManager = createAuthManager(options, (token) => {
7743
7679
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
7744
- currentUserIdStore.set(() => userId);
7680
+ currentUserId.set(() => userId);
7745
7681
  });
7746
7682
  const fetchPolyfill = clientOptions.polyfills?.fetch || /* istanbul ignore next */
7747
7683
  globalThis.fetch?.bind(globalThis);
@@ -7800,7 +7736,6 @@ function createClient(options) {
7800
7736
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
7801
7737
  },
7802
7738
  enableDebugLogging: clientOptions.enableDebugLogging,
7803
- unstable_batchedUpdates: options2?.unstable_batchedUpdates,
7804
7739
  baseUrl,
7805
7740
  unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
7806
7741
  unstable_streamData: !!clientOptions.unstable_streamData,
@@ -7835,7 +7770,7 @@ function createClient(options) {
7835
7770
  }
7836
7771
  function logout() {
7837
7772
  authManager.reset();
7838
- currentUserIdStore.set(() => void 0);
7773
+ currentUserId.set(() => void 0);
7839
7774
  for (const { room } of roomsById.values()) {
7840
7775
  if (!isIdle(room.getStatus())) {
7841
7776
  room.reconnect();
@@ -7947,7 +7882,7 @@ function createClient(options) {
7947
7882
  },
7948
7883
  // Internal
7949
7884
  [kInternal]: {
7950
- currentUserIdStore,
7885
+ currentUserId,
7951
7886
  mentionSuggestionsCache,
7952
7887
  resolveMentionSuggestions: clientOptions.resolveMentionSuggestions,
7953
7888
  usersStore,
@@ -8930,15 +8865,18 @@ export {
8930
8865
  ClientMsgCode,
8931
8866
  CommentsApiError,
8932
8867
  CrdtType,
8868
+ DerivedSignal,
8933
8869
  HttpError,
8934
8870
  LiveList,
8935
8871
  LiveMap,
8936
8872
  LiveObject,
8873
+ MutableSignal,
8937
8874
  NotificationsApiError,
8938
8875
  OpCode,
8939
8876
  Permission,
8940
8877
  Promise_withResolvers,
8941
8878
  ServerMsgCode,
8879
+ Signal,
8942
8880
  SortedList,
8943
8881
  TextEditorType,
8944
8882
  WebsocketCloseCodes,
@@ -8948,6 +8886,7 @@ export {
8948
8886
  assertNever,
8949
8887
  autoRetry,
8950
8888
  b64decode,
8889
+ batch,
8951
8890
  chunk,
8952
8891
  cloneLson,
8953
8892
  compactObject,
@@ -8960,7 +8899,6 @@ export {
8960
8899
  createCommentAttachmentId,
8961
8900
  createCommentId,
8962
8901
  createInboxNotificationId,
8963
- createStore,
8964
8902
  createThreadId,
8965
8903
  deprecate,
8966
8904
  deprecateIf,