@colyseus/schema 4.0.23 → 4.0.24

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/build/index.cjs CHANGED
@@ -1231,12 +1231,26 @@ class ChangeTree {
1231
1231
  }
1232
1232
  return;
1233
1233
  }
1234
- const changeSet = (this.filteredChanges !== undefined)
1234
+ // Mirror `change()`: a field's add/delete must target the same
1235
+ // changeset family (filtered vs non-filtered). Otherwise
1236
+ // `deleteOperationAtIndex` falls through to its "find last
1237
+ // operation" branch and evicts an unrelated sibling field —
1238
+ // surfaced as encodeAll() dropping a non-@view field after a
1239
+ // sibling @view field is set to undefined on a Schema with
1240
+ // mixed @view / non-@view fields (filteredChanges defined,
1241
+ // isFiltered false).
1242
+ const isFiltered = this.isFiltered || (this.metadata?.[index]?.tag !== undefined);
1243
+ const changeSet = (isFiltered)
1235
1244
  ? this.filteredChanges
1236
1245
  : this.changes;
1237
1246
  this.indexedOperations[index] = operation ?? exports.OPERATION.DELETE;
1238
1247
  setOperationAtIndex(changeSet, index);
1239
- deleteOperationAtIndex(this.allChanges, allChangesIndex);
1248
+ if (isFiltered) {
1249
+ deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);
1250
+ }
1251
+ else {
1252
+ deleteOperationAtIndex(this.allChanges, allChangesIndex);
1253
+ }
1240
1254
  const previousValue = this.getValue(index);
1241
1255
  // remove `root` reference
1242
1256
  if (previousValue && previousValue[$changes]) {
@@ -1252,11 +1266,7 @@ class ChangeTree {
1252
1266
  //
1253
1267
  this.root?.remove(previousValue[$changes]);
1254
1268
  }
1255
- //
1256
- // FIXME: this is looking a ugly and repeated
1257
- //
1258
- if (this.filteredChanges !== undefined) {
1259
- deleteOperationAtIndex(this.allFilteredChanges, allChangesIndex);
1269
+ if (isFiltered) {
1260
1270
  this.root?.enqueueChangeTree(this, 'filteredChanges');
1261
1271
  }
1262
1272
  else {