@colyseus/schema 4.0.24 → 4.0.25

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.js CHANGED
@@ -1375,7 +1375,8 @@
1375
1375
  key += `-${this.root.types.schemas.get(parentConstructor)}`;
1376
1376
  }
1377
1377
  key += `-${parentIndex}`;
1378
- const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentConstructor?.[Symbol.metadata], parentIndex);
1378
+ const parentMetadata = parentConstructor?.[Symbol.metadata];
1379
+ const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentMetadata, parentIndex);
1379
1380
  this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered
1380
1381
  || this.root.types.parentFiltered[key]
1381
1382
  || fieldHasViewTag;
@@ -1384,9 +1385,22 @@
1384
1385
  // when it's available, we need to enqueue the "changes" changeset into the "filteredChanges" changeset.
1385
1386
  //
1386
1387
  if (this.isFiltered) {
1388
+ //
1389
+ // Children of a `@view(N)` collection (non-default tag) inherit
1390
+ // visibility from their parent, so items pushed/set after the
1391
+ // initial `view.add(state, N)` show up automatically.
1392
+ //
1393
+ // Default-tag `@view()` collections deliberately keep per-item
1394
+ // gating — `view.add(item)` is required to opt each one in.
1395
+ //
1396
+ // The `parentMetadata[parentIndex].tag` access is safe inside
1397
+ // this branch: the OR's short-circuit means we only reach it
1398
+ // when `fieldHasViewTag` is true, which guarantees the metadata
1399
+ // entry and its `tag` property exist.
1400
+ //
1387
1401
  this.isVisibilitySharedWithParent = (parentChangeTree.isFiltered &&
1388
1402
  typeof (refType) !== "string" &&
1389
- !fieldHasViewTag);
1403
+ (!fieldHasViewTag || (parentIsCollection && parentMetadata[parentIndex].tag !== DEFAULT_VIEW_TAG)));
1390
1404
  if (!this.filteredChanges) {
1391
1405
  this.filteredChanges = createChangeSet();
1392
1406
  this.allFilteredChanges = createChangeSet();
package/build/index.mjs CHANGED
@@ -1369,7 +1369,8 @@ class ChangeTree {
1369
1369
  key += `-${this.root.types.schemas.get(parentConstructor)}`;
1370
1370
  }
1371
1371
  key += `-${parentIndex}`;
1372
- const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentConstructor?.[Symbol.metadata], parentIndex);
1372
+ const parentMetadata = parentConstructor?.[Symbol.metadata];
1373
+ const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentMetadata, parentIndex);
1373
1374
  this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered
1374
1375
  || this.root.types.parentFiltered[key]
1375
1376
  || fieldHasViewTag;
@@ -1378,9 +1379,22 @@ class ChangeTree {
1378
1379
  // when it's available, we need to enqueue the "changes" changeset into the "filteredChanges" changeset.
1379
1380
  //
1380
1381
  if (this.isFiltered) {
1382
+ //
1383
+ // Children of a `@view(N)` collection (non-default tag) inherit
1384
+ // visibility from their parent, so items pushed/set after the
1385
+ // initial `view.add(state, N)` show up automatically.
1386
+ //
1387
+ // Default-tag `@view()` collections deliberately keep per-item
1388
+ // gating — `view.add(item)` is required to opt each one in.
1389
+ //
1390
+ // The `parentMetadata[parentIndex].tag` access is safe inside
1391
+ // this branch: the OR's short-circuit means we only reach it
1392
+ // when `fieldHasViewTag` is true, which guarantees the metadata
1393
+ // entry and its `tag` property exist.
1394
+ //
1381
1395
  this.isVisibilitySharedWithParent = (parentChangeTree.isFiltered &&
1382
1396
  typeof (refType) !== "string" &&
1383
- !fieldHasViewTag);
1397
+ (!fieldHasViewTag || (parentIsCollection && parentMetadata[parentIndex].tag !== DEFAULT_VIEW_TAG)));
1384
1398
  if (!this.filteredChanges) {
1385
1399
  this.filteredChanges = createChangeSet();
1386
1400
  this.allFilteredChanges = createChangeSet();