Skip to content

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

fix(vue): detach nested selection projection values

Danila Poyarkov9eea1beb2ac1
diff --git a/packages/vue/src/editor/selection-state/nodes.ts b/packages/vue/src/editor/selection-state/nodes.ts
index 45a380bf6..0887d25b0 100644
--- a/packages/vue/src/editor/selection-state/nodes.ts
+++ b/packages/vue/src/editor/selection-state/nodes.ts
@@ -31,7 +31,7 @@ export function createSelectedNodeState(
void revision.value
void editor.state.sceneVersion
void editor.state.currentPageId
- return editor.getSelectedNodes().map((node) => shallowReactive(node))
+ return editor.getSelectedNodes().map((node) => shallowReactive(structuredClone(node)))
})
const byId = computed(() => new Map(nodes.value.map((node) => [node.id, node])))
const node = computed(() => (nodes.value.length === 1 ? nodes.value[0] : null))
@@ -39,7 +39,7 @@ export function createSelectedNodeState(
function updatePreview(id: string, changes: Partial<SceneNode>) {
if (!editor.state.selectedIds.has(id)) return
const selected = byId.value.get(id)
- if (selected) Object.assign(selected, changes)
+ if (selected) Object.assign(selected, structuredClone(changes))
}
const dispose = watchImmediate(
diff --git a/tests/engine/vue/editor/selected-nodes.test.ts b/tests/engine/vue/editor/selected-nodes.test.ts
index 08d392603..c52407014 100644
--- a/tests/engine/vue/editor/selected-nodes.test.ts
+++ b/tests/engine/vue/editor/selected-nodes.test.ts
@@ -3,7 +3,7 @@ import { describe, expect, test } from 'bun:test'
import { computed, createApp, effectScope, ref, shallowReactive } from 'vue'
import { createDefaultEditorState, createEditor } from '@open-pencil/core/editor'
-import { getSharedStyles, SceneGraph } from '@open-pencil/scene-graph'
+import { getSharedStyles, SceneGraph, type Fill } from '@open-pencil/scene-graph'
import { EDITOR_KEY } from '#vue/editor/context'
import { createSelectedNodeState, useSelectedNodeState } from '#vue/editor/selection-state/nodes'
@@ -31,6 +31,34 @@ function setup() {
}
describe('selected-node preview projections', () => {
+ for (const phase of ['initial', 'preview'] as const) {
+ test(`detaches nested ${phase} values from the graph`, () => {
+ const fixture = setup()
+ const { editor, first, selection } = fixture
+ const fill: Fill = {
+ type: 'SOLID',
+ color: { r: 0.2, g: 0.3, b: 0.4, a: 1 },
+ opacity: 1,
+ visible: true
+ }
+ try {
+ editor.updateNode(first.id, { fills: [fill] })
+ const projected = selection.node.value
+ if (!projected) throw new Error('Missing projection')
+ const preview = editor.beginNodePreview('Paint')
+ if (phase === 'preview') preview.update(first.id, { fills: [{ ...fill, opacity: 0.5 }] })
+ projected.fills[0].color.r = 0.9
+ projected.childIds.push('projection-only')
+ expect(first.fills[0].color.r).toBe(0.2)
+ expect(first.childIds).toEqual([])
+ preview.cancel()
+ expect(first.fills[0]).toEqual(fill)
+ expect(editor.undo.canUndo).toBe(false)
+ } finally {
+ fixture.dispose()
+ }
+ })
+ }
test('tracks committed changes and selection with a plain editor state', () => {
const editor = createEditor()
const active = ref(true)