From 61e0e5fbe4aa2fa9aafa6faef7aca2f76464fa28 Mon Sep 17 00:00:00 2001 From: Danila Poyarkov Date: Sun, 30 Aug 2026 21:31:31 +0300 Subject: [PATCH] fix(scene-graph): tighten component property helpers --- packages/scene-graph/src/component-properties.ts | 16 +++++++++------- packages/scene-graph/src/index.ts | 1 + .../scene-graph/component-properties.test.ts | 3 +++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/scene-graph/src/component-properties.ts b/packages/scene-graph/src/component-properties.ts index e64f825d2..233ab9b73 100644 --- a/packages/scene-graph/src/component-properties.ts +++ b/packages/scene-graph/src/component-properties.ts @@ -39,13 +39,15 @@ export function resolveComponentPropertyValue(graph: SceneGraph, value: string): const componentId = direct.childIds.find((id) => graph.getNode(id)?.type === 'COMPONENT') return componentId ? (graph.getNode(componentId) ?? null) : null } - return ( - [...graph.getAllNodes()].find( - (node) => - node.type === 'COMPONENT' && - (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value) - ) ?? null - ) + for (const node of graph.getAllNodes()) { + if ( + node.type === 'COMPONENT' && + (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value) + ) { + return node + } + } + return null } export function findComponentPropertyTarget( diff --git a/packages/scene-graph/src/index.ts b/packages/scene-graph/src/index.ts index f9af9a0b0..391a0bc9c 100644 --- a/packages/scene-graph/src/index.ts +++ b/packages/scene-graph/src/index.ts @@ -1,4 +1,5 @@ /* eslint-disable max-lines -- SceneGraph exposes a stable facade over domain modules */ +export * from './images' export * from './component-properties' export * from './copy' export { copyInstanceComponentProps } from './instances' diff --git a/tests/engine/scene-graph/component-properties.test.ts b/tests/engine/scene-graph/component-properties.test.ts index 213db3027..28ab00ff3 100644 --- a/tests/engine/scene-graph/component-properties.test.ts +++ b/tests/engine/scene-graph/component-properties.test.ts @@ -50,11 +50,14 @@ describe('component properties', () => { const icon = component(graph, 'Icon', page.id) const keyed = component(graph, 'Keyed', page.id) graph.updateNode(keyed.id, { componentKey: 'icon-key' }) + const library = component(graph, 'Library', page.id) + graph.updateNode(library.id, { sourceLibraryKey: 'library-key' }) const set = graph.createNode('COMPONENT_SET', page.id) graph.reparentNode(icon.id, set.id) expect(resolveComponentPropertyValue(graph, keyed.id)?.id).toBe(keyed.id) expect(resolveComponentPropertyValue(graph, 'icon-key')?.id).toBe(keyed.id) + expect(resolveComponentPropertyValue(graph, 'library-key')?.id).toBe(library.id) expect(resolveComponentPropertyValue(graph, set.id)?.id).toBe(icon.id) })