fix: stop psd dialog update loop
This commit is contained in:
parent
8853bfae77
commit
494a3c6d48
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user