From b62926cf6ef780d3f9cf1ccb1f052aea3bf462e8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 25 Mar 2026 17:33:11 +0800 Subject: [PATCH] fix: prevent ai detail sync render loop --- .../agents/AgentGenerationWorkspaceDarkV2.tsx | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/components/agents/AgentGenerationWorkspaceDarkV2.tsx b/components/agents/AgentGenerationWorkspaceDarkV2.tsx index ca178bc1c..d0a97d0d2 100644 --- a/components/agents/AgentGenerationWorkspaceDarkV2.tsx +++ b/components/agents/AgentGenerationWorkspaceDarkV2.tsx @@ -236,6 +236,36 @@ function arePickedAttachmentsEqual( return true; } +function areAttachmentValuesEqual( + left: + | PickedAttachment + | { + url?: string | null; + name?: string | null; + contentType?: string | null; + assetId?: string | null; + } + | null + | undefined, + right: + | PickedAttachment + | { + url?: string | null; + name?: string | null; + contentType?: string | null; + assetId?: string | null; + } + | null + | undefined +) { + return ( + String(left?.url || "").trim() === String(right?.url || "").trim() && + String(left?.name || "").trim() === String(right?.name || "").trim() && + String(left?.contentType || "").trim() === String(right?.contentType || "").trim() && + String(left?.assetId || "").trim() === String(right?.assetId || "").trim() + ); +} + function mergePersistedHistoryMessages( currentMessages: ChatMessage[], persistedMessages: ChatMessage[] @@ -2639,7 +2669,10 @@ export function AgentGenerationWorkspaceDarkV2({ contentType: attachment.contentType || "image/jpeg", assetId: attachment.assetId || null, }; - if (!currentSlot || currentIsPreviousAutoSelection) { + if ( + (!currentSlot || currentIsPreviousAutoSelection) && + !areAttachmentValuesEqual(currentSlot, nextAttachment) + ) { nextSlots[slotIndex] = nextAttachment; changed = true; } @@ -2667,7 +2700,10 @@ export function AgentGenerationWorkspaceDarkV2({ contentType: selectedModelAttachment.contentType || "image/jpeg", assetId: selectedModelAttachment.assetId || null, }; - if (!currentSlot || currentIsPreviousAutoSelection) { + if ( + (!currentSlot || currentIsPreviousAutoSelection) && + !areAttachmentValuesEqual(currentSlot, nextAttachment) + ) { nextSlots[AGENT_DETAIL_MODEL_SLOT_INDEX] = nextAttachment; changed = true; } @@ -2701,7 +2737,10 @@ export function AgentGenerationWorkspaceDarkV2({ contentType: image.mimeType || "image/jpeg", assetId: image.assetId || null, }; - if (!currentSlot || currentIsPreviousAutoSelection) { + if ( + (!currentSlot || currentIsPreviousAutoSelection) && + !areAttachmentValuesEqual(currentSlot, nextAttachment) + ) { nextSlots[slotIndex] = nextAttachment; changed = true; }