@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/schema",
3
- "version": "4.0.24",
3
+ "version": "4.0.25",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,4 +1,5 @@
1
1
  import { OPERATION } from "../encoding/spec.js";
2
+ import { DEFAULT_VIEW_TAG } from "../annotations.js";
2
3
  import { Schema } from "../Schema.js";
3
4
  import { $changes, $childType, $decoder, $onEncodeEnd, $encoder, $getByIndex, $refId, $refTypeFieldIndexes, $viewFieldIndexes, type $deleteByIndex } from "../types/symbols.js";
4
5
 
@@ -570,7 +571,8 @@ export class ChangeTree<T extends Ref = any> {
570
571
  }
571
572
  key += `-${parentIndex}`;
572
573
 
573
- const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentConstructor?.[Symbol.metadata], parentIndex);
574
+ const parentMetadata = parentConstructor?.[Symbol.metadata];
575
+ const fieldHasViewTag = Metadata.hasViewTagAtIndex(parentMetadata, parentIndex);
574
576
 
575
577
  this.isFiltered = parent[$changes].isFiltered // in case parent is already filtered
576
578
  || this.root.types.parentFiltered[key]
@@ -581,11 +583,23 @@ export class ChangeTree<T extends Ref = any> {
581
583
  // when it's available, we need to enqueue the "changes" changeset into the "filteredChanges" changeset.
582
584
  //
583
585
  if (this.isFiltered) {
584
-
586
+ //
587
+ // Children of a `@view(N)` collection (non-default tag) inherit
588
+ // visibility from their parent, so items pushed/set after the
589
+ // initial `view.add(state, N)` show up automatically.
590
+ //
591
+ // Default-tag `@view()` collections deliberately keep per-item
592
+ // gating — `view.add(item)` is required to opt each one in.
593
+ //
594
+ // The `parentMetadata[parentIndex].tag` access is safe inside
595
+ // this branch: the OR's short-circuit means we only reach it
596
+ // when `fieldHasViewTag` is true, which guarantees the metadata
597
+ // entry and its `tag` property exist.
598
+ //
585
599
  this.isVisibilitySharedWithParent = (
586
600
  parentChangeTree.isFiltered &&
587
601
  typeof (refType) !== "string" &&
588
- !fieldHasViewTag
602
+ (!fieldHasViewTag || (parentIsCollection && parentMetadata[parentIndex].tag !== DEFAULT_VIEW_TAG))
589
603
  );
590
604
 
591
605
  if (!this.filteredChanges) {