From 494a3c6d485a42b84baa1121e2b376206560ccb6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 1 Apr 2026 22:04:53 +0800 Subject: [PATCH] fix: stop psd dialog update loop --- .../agents/AgentPsdTemplateEditorDialog.tsx | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/components/agents/AgentPsdTemplateEditorDialog.tsx b/components/agents/AgentPsdTemplateEditorDialog.tsx index 0e00fabc9..cbd4a1bba 100644 --- a/components/agents/AgentPsdTemplateEditorDialog.tsx +++ b/components/agents/AgentPsdTemplateEditorDialog.tsx @@ -510,7 +510,12 @@ export function AgentPsdTemplateEditorDialog({ useEffect(() => { if (!selectedTemplate) { - setImageSizes({}); + setImageSizes((current) => { + if (Object.keys(current).length === 0) { + return current; + } + return {}; + }); return; } if (typeof window === "undefined" || typeof window.Image !== "function") { @@ -532,13 +537,24 @@ export function AgentPsdTemplateEditorDialog({ const image = new window.Image(); image.onload = () => { if (cancelled) return; - setImageSizes((current) => ({ - ...current, - [layer.id]: { - width: Math.max(1, image.naturalWidth || layer.width), - height: Math.max(1, image.naturalHeight || layer.height), - }, - })); + const nextWidth = Math.max(1, image.naturalWidth || layer.width); + const nextHeight = Math.max(1, image.naturalHeight || layer.height); + setImageSizes((current) => { + if ( + current[layer.id]?.width === nextWidth && + current[layer.id]?.height === nextHeight + ) { + return current; + } + + return { + ...current, + [layer.id]: { + width: nextWidth, + height: nextHeight, + }, + }; + }); }; image.src = assignedUrl; }