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(() => {
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;
}