A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(prefab): a key only the source carries is inherited, not overridden
yhhfa7622366311
diff --git a/sdk/src/prefab/diff.ts b/sdk/src/prefab/diff.tsindex 2aaa16428..112673ba7 100644--- a/sdk/src/prefab/diff.ts+++ b/sdk/src/prefab/diff.ts@@ -266,6 +266,10 @@ function diffComponents(...Object.keys(instComp.data),]);for (const key of keys) {+ // A key only the BASE carries is INHERITED — a component's schema owns+ // which keys exist, hence `metadata_removed` and no `property_removed`.+ // Diffing one clones an `undefined` that no save can write.+ if (!(key in instComp.data)) continue;// Entity refs diff (and store) in stable-id space so an unchanged// cross-reference isn't logged as a dangling numeric override — both// sides normalise through their own runtime-id→stable-id map.diff --git a/sdk/tests/prefab-rigor.test.ts b/sdk/tests/prefab-rigor.test.tsindex 19b3dd1a2..67f0d28bd 100644--- a/sdk/tests/prefab-rigor.test.ts+++ b/sdk/tests/prefab-rigor.test.ts@@ -461,6 +461,31 @@ describe('diffAgainstSource', () => {});});+ // The trap: `JSON.stringify(undefined)` is `undefined`, so diffing a key only+ // the source carries threw `"undefined" is not valid JSON` out of save, for+ // good. A re-imported model an open scene instances is the path there.+ it('inherits a source key the instance does not carry, rather than throwing', () => {+ const prefab = uuidPrefab();+ const instance = cloneForInstance(prefab);+ delete (instance[0].components[1].data as Record<string, unknown>).color;+ const { overrides } = diffAgainstSource(prefab, instance);+ expect(overrides).toEqual([]);+ });++ it('still emits a property override for a key only the instance carries', () => {+ const prefab = uuidPrefab();+ const instance = cloneForInstance(prefab);+ (instance[0].components[1].data as Record<string, unknown>).flipX = true;+ const { overrides } = diffAgainstSource(prefab, instance);+ expect(overrides).toContainEqual({+ prefabEntityId: 'root',+ type: 'property',+ componentType: 'Sprite',+ propertyName: 'flipX',+ value: true,+ });+ });+it('emits component_added for new component and component_removed for missing one', () => {const prefab = uuidPrefab();const instance = cloneForInstance(prefab);