fix: stop agent generation workspace 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-18 23:31:42 +08:00
parent 8a34cd4570
commit 2a2d4f46b3

View File

@ -481,7 +481,13 @@ export function AgentGenerationWorkspaceDarkV2({
imageUrl: String(item.imageUrl || "").trim(),
candidateId: item.candidateId || null,
sortOrder: item.sortOrder ?? 0,
assignedProductIndex: item.assignedProductIndex ?? null,
assignedProductIndex:
selectedProductAttachments.length > 0
? Math.min(
item.assignedProductIndex ?? 0,
Math.max(selectedProductAttachments.length - 1, 0)
)
: null,
})),
}
: undefined;
@ -1294,26 +1300,6 @@ export function AgentGenerationWorkspaceDarkV2({
),
}));
}, [updateSkuReplacementState]);
useEffect(() => {
if (!isSkuReplacementPreset) return;
updateSkuReplacementState((current) => ({
...current,
references: current.references.map((card, index) => ({
...card,
assignedProductIndex:
selectedProductAttachments.length > 0
? Math.min(
card.assignedProductIndex ?? index,
Math.max(selectedProductAttachments.length - 1, 0)
)
: null,
})),
}));
}, [
isSkuReplacementPreset,
selectedProductAttachments.length,
updateSkuReplacementState,
]);
const handleRemoveSkuReferenceCard = useCallback((cardId: string) => {
updateSkuReplacementState((current) => ({
...current,
@ -2388,6 +2374,18 @@ export function AgentGenerationWorkspaceDarkV2({
key={card.id}
className="overflow-hidden rounded-[22px] border border-white/10 bg-black/20"
>
{(() => {
const resolvedAssignedProductIndex =
selectedProductAttachments.length > 0
? Math.min(
typeof card.assignedProductIndex === "number"
? card.assignedProductIndex
: index,
Math.max(selectedProductAttachments.length - 1, 0)
)
: null;
return (
<>
<div className="relative aspect-[5/3] overflow-hidden bg-[radial-gradient(circle_at_top,rgba(16,185,129,0.12),transparent_55%),linear-gradient(180deg,#0b0d0f_0%,#101316_100%)]">
<button
type="button"
@ -2415,8 +2413,8 @@ export function AgentGenerationWorkspaceDarkV2({
<>
<div className="mb-2 text-[11px] text-white/45">
当前对应输入图:
{typeof card.assignedProductIndex === "number"
? `输入图 ${Math.min(card.assignedProductIndex + 1, selectedProductAttachments.length)}`
{typeof resolvedAssignedProductIndex === "number"
? `输入图 ${resolvedAssignedProductIndex + 1}`
: "未指定"}
</div>
<div className="flex flex-wrap gap-2">
@ -2429,7 +2427,7 @@ export function AgentGenerationWorkspaceDarkV2({
}
className={cn(
"rounded-full border px-2.5 py-1 text-[11px] transition-colors",
card.assignedProductIndex === productIndex
resolvedAssignedProductIndex === productIndex
? "border-emerald-400/45 bg-emerald-500/[0.12] text-emerald-200"
: "border-white/10 bg-white/[0.03] text-white/58 hover:border-white/20 hover:text-white"
)}
@ -2444,6 +2442,9 @@ export function AgentGenerationWorkspaceDarkV2({
删除某张后,后面的参考图会自动上移补位,不留空位。
</div>
</div>
</>
);
})()}
</div>
))
) : (