fix: stop psd dialog update loop
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-04-01 22:04:53 +08:00
parent 8853bfae77
commit 494a3c6d48

View File

@ -510,7 +510,12 @@ export function AgentPsdTemplateEditorDialog({
useEffect(() => { useEffect(() => {
if (!selectedTemplate) { if (!selectedTemplate) {
setImageSizes({}); setImageSizes((current) => {
if (Object.keys(current).length === 0) {
return current;
}
return {};
});
return; return;
} }
if (typeof window === "undefined" || typeof window.Image !== "function") { if (typeof window === "undefined" || typeof window.Image !== "function") {
@ -532,13 +537,24 @@ export function AgentPsdTemplateEditorDialog({
const image = new window.Image(); const image = new window.Image();
image.onload = () => { image.onload = () => {
if (cancelled) return; if (cancelled) return;
setImageSizes((current) => ({ const nextWidth = Math.max(1, image.naturalWidth || layer.width);
...current, const nextHeight = Math.max(1, image.naturalHeight || layer.height);
[layer.id]: { setImageSizes((current) => {
width: Math.max(1, image.naturalWidth || layer.width), if (
height: Math.max(1, image.naturalHeight || layer.height), current[layer.id]?.width === nextWidth &&
}, current[layer.id]?.height === nextHeight
})); ) {
return current;
}
return {
...current,
[layer.id]: {
width: nextWidth,
height: nextHeight,
},
};
});
}; };
image.src = assignedUrl; image.src = assignedUrl;
} }