diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Components/ImageAssetSelector.tsx b/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Components/ImageAssetSelector.tsx index 6ec0e1517..42c15c56f 100644 --- a/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Components/ImageAssetSelector.tsx +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Components/ImageAssetSelector.tsx @@ -18,9 +18,9 @@ export function ImageAssetSelector({ onChange: (value: string | null) => void; }) { const [open, setOpen] = useState(false); - const [failedPreviewIds, setFailedPreviewIds] = useState>( - () => new Set(), - ); + const [failedPreviewUrls, setFailedPreviewUrls] = useState< + Record + >({}); const selectedSprite = value ? sprites[value] : undefined; const selectedLabel = selectedSprite ? selectedSprite.metadata.name || value || '未绑定' @@ -38,12 +38,10 @@ export function ImageAssetSelector({ close(); } - function markPreviewFailed(id: string) { - setFailedPreviewIds((current) => { - if (current.has(id)) return current; - const next = new Set(current); - next.add(id); - return next; + function markPreviewFailed(id: string, url: string) { + setFailedPreviewUrls((current) => { + if (current[id] === url) return current; + return { ...current, [id]: url }; }); } @@ -111,7 +109,7 @@ export function ImageAssetSelector({ {Object.entries(sprites).map(([id, sprite]) => { const previewUrl = previewUrls[id]; const hasPreview = - Boolean(previewUrl) && !failedPreviewIds.has(id); + Boolean(previewUrl) && failedPreviewUrls[id] !== previewUrl; const selected = value === id; return (