Skip to content

AI-native design editor. Open-source Figma alternative.

fix(scene-graph): preserve text instance overrides

Danila Poyarkov01353e7ca764
diff --git a/packages/core/src/figma-api/proxy.ts b/packages/core/src/figma-api/proxy.ts
index 81b53f5da..97b031044 100644
--- a/packages/core/src/figma-api/proxy.ts
+++ b/packages/core/src/figma-api/proxy.ts
@@ -1,3 +1,4 @@
+import { recordInstanceOverride } from '@open-pencil/scene-graph'
import type {
SceneGraph,
SceneNode,
@@ -137,7 +138,10 @@ export class FigmaNodeProxy {
private _update(changes: Partial<SceneNode>): void {
assertNodeEditable(this[INTERNAL_GRAPH], this[INTERNAL_ID])
- this[INTERNAL_GRAPH].updateNode(this[INTERNAL_ID], changes)
+ const graph = this[INTERNAL_GRAPH]
+ const id = this[INTERNAL_ID]
+ graph.updateNode(id, changes)
+ recordInstanceOverride(graph, id, Object.keys(changes))
}
private _raw(): SceneNode {
diff --git a/tests/engine/figma/api/create/instance-fill-override.test.ts b/tests/engine/figma/api/create/instance-fill-override.test.ts
index 8d4e51422..aa24a70f3 100644
--- a/tests/engine/figma/api/create/instance-fill-override.test.ts
+++ b/tests/engine/figma/api/create/instance-fill-override.test.ts
@@ -20,6 +20,24 @@ describe('setting fills on an instance descendant', () => {
expect(raw?.overrides[`${vector.id}:fills`]).toBe(true)
})
+ test('preserves text edits on an instance descendant during resync', () => {
+ const api = createAPI()
+ const component = api.createComponent()
+ const text = api.createText()
+ text.characters = 'Default'
+ component.appendChild(text)
+
+ const instance = component.createInstance()
+ const instanceText = instance.children[0]
+ if (!instanceText) throw new Error('instance text not found')
+ instanceText.characters = 'Custom'
+
+ expect(api.graph.getNode(instance.id)?.overrides[`${instanceText.id}:text`]).toBe(true)
+ text.characters = 'Updated default'
+ api.graph.syncInstances(component.id)
+
+ expect(instanceText.characters).toBe('Custom')
+ })
test('does not record an override for a node with no instance ancestor', () => {
const api = createAPI()
const frame = api.createFrame()