From ed66a1500494d0852f4d86a8b0a16dd22f36769c Mon Sep 17 00:00:00 2001 From: Kris Baumgartner Date: Fri, 3 Jan 2025 16:38:03 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20core:=20fix=20updateEach=20insta?= =?UTF-8?q?bility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kris Baumgartner --- packages/core/src/query/query-result.ts | 10 ++++++---- packages/core/tests/query.test.ts | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/core/src/query/query-result.ts b/packages/core/src/query/query-result.ts index eb2efbd..ff0b761 100644 --- a/packages/core/src/query/query-result.ts +++ b/packages/core/src/query/query-result.ts @@ -80,15 +80,16 @@ export function createQueryResult( const trait = traits[index]; const ctx = trait[$internal]; const newValue = state[index]; + const store = stores[index]; let changed = false; if (ctx.type === 'aos') { - changed = ctx.fastSetWithChangeDetection(eid, stores[j], newValue); + changed = ctx.fastSetWithChangeDetection(eid, store, newValue); if (!changed) { - changed = !shallowEqual(newValue, atomicSnapshots[j]); + changed = !shallowEqual(newValue, atomicSnapshots[index]); } } else { - changed = ctx.fastSetWithChangeDetection(eid, stores[j], newValue); + changed = ctx.fastSetWithChangeDetection(eid, store, newValue); } // Collect changed traits. @@ -100,7 +101,8 @@ export function createQueryResult( const index = untrackedIndices[j]; const trait = traits[index]; const ctx = trait[$internal]; - ctx.fastSet(eid, stores[index], state[index]); + const store = stores[index]; + ctx.fastSet(eid, store, state[index]); } } diff --git a/packages/core/tests/query.test.ts b/packages/core/tests/query.test.ts index 3a9bf4e..e025a2d 100644 --- a/packages/core/tests/query.test.ts +++ b/packages/core/tests/query.test.ts @@ -715,8 +715,9 @@ describe('Query', () => { // This has changes tracked automatically. // Here we test that mixing tracked and untracked traits works. + // We do it would of order to catch misaligned indices internally. world.spawn(Position, Name); - world.query(Position, Name).updateEach(([position]) => { + world.query(Name, Position).updateEach(([name, position]) => { position.x = 1; });