fix: prevent ai detail sync render 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-03-25 17:33:11 +08:00
parent c823910185
commit b62926cf6e

View File

@ -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;
}