From c6217eb88e8d38a71dc35513a45d1cbeb3dd23bb Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 1 May 2026 05:03:06 -0700 Subject: [PATCH] PageScene: ColorAction signals panel refresh on apply/revert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the user undoes a color change while the Object Panel is open, the THREE.js material reverts correctly but the panel's local React `color` state stays at the redo value — the panel preview Button and the color input value disagree with the actual scene material. Root cause: the per-frame `getSelectedSum` check in renderSingleFrame pushes a fresh `objectPanel` slice to Zustand whenever transforms change, which re-fires the panel's useEffect and re-reads userData.color. Color changes don't move the sum, so the push never happens after a color undo/redo. Fix: ColorAction.apply/revert now calls `editor.selection.updateSelectedUI()` after the engine setColor. That pushes a new currentSceneObject reference into Zustand, the panel's [currentSceneObject] effect fires, and `setColor(editorEngine?.selected?.userData.color)` reads the freshly reverted value. Same pattern the lock/transform paths already use for UI sync. --- .../pages/PageScene/engine/editor/actions/ColorAction.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/apps/artcraft/app/src/pages/PageScene/engine/editor/actions/ColorAction.ts b/frontend/apps/artcraft/app/src/pages/PageScene/engine/editor/actions/ColorAction.ts index 3cde028590..4a4ba9cf69 100644 --- a/frontend/apps/artcraft/app/src/pages/PageScene/engine/editor/actions/ColorAction.ts +++ b/frontend/apps/artcraft/app/src/pages/PageScene/engine/editor/actions/ColorAction.ts @@ -4,6 +4,13 @@ import type { UndoableAction } from "../HistoryManager"; // Records a color change. apply() and revert() both call // activeScene.setColor — the engine handles material magic. The action // captures the uuid + before/after hex pair at construction time. +// +// Each replay also fires SelectionBridge.updateSelectedUI() so the +// Object Panel re-reads userData.color and refreshes its preview. +// Without this, undo correctly reverts the THREE.js material but +// ControlPanelSceneObject's local React state stays at the redo +// value (the per-frame getSelectedSum check that picks up transform +// changes doesn't notice color changes). export class ColorAction implements UndoableAction { readonly label = "Color"; @@ -16,9 +23,11 @@ export class ColorAction implements UndoableAction { apply(): void { this.editor.activeScene.setColor(this.uuid, this.after); + this.editor.selection.updateSelectedUI(); } revert(): void { this.editor.activeScene.setColor(this.uuid, this.before); + this.editor.selection.updateSelectedUI(); } }