[dyad] Fixed image upload bug - wrote 1 file(s)

This commit is contained in:
[dyad]
2026-01-23 09:01:13 +01:00
parent d5eab618fb
commit 70b9987605

View File

@@ -27,12 +27,13 @@ export function useImageConverter() {
const [isConverting, setIsConverting] = useState(false); const [isConverting, setIsConverting] = useState(false);
const [convertingIndex, setConvertingIndex] = useState<number | null>(null); const [convertingIndex, setConvertingIndex] = useState<number | null>(null);
// Effect to clean up all object URLs when the component unmounts
useEffect(() => { useEffect(() => {
const urls = images.map(img => img.previewUrl);
return () => { return () => {
urls.forEach(url => URL.revokeObjectURL(url)); images.forEach(image => URL.revokeObjectURL(image.previewUrl));
}; };
}, [images]); // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const updateSettings = useCallback((newSettings: Partial<ConversionSettings>) => { const updateSettings = useCallback((newSettings: Partial<ConversionSettings>) => {
setSettings(prev => ({ ...prev, ...newSettings })); setSettings(prev => ({ ...prev, ...newSettings }));
@@ -70,10 +71,11 @@ export function useImageConverter() {
}, []); }, []);
const handleClearAll = useCallback(() => { const handleClearAll = useCallback(() => {
images.forEach(image => URL.revokeObjectURL(image.previewUrl));
setImages([]); setImages([]);
updateSettings({ width: initialSettings.width, height: initialSettings.height }); updateSettings({ width: initialSettings.width, height: initialSettings.height });
toast.info("All images cleared."); toast.info("All images cleared.");
}, [updateSettings]); }, [images, updateSettings]);
const handleFilenameChange = useCallback((index: number, newName: string) => { const handleFilenameChange = useCallback((index: number, newName: string) => {
setImages(prev => { setImages(prev => {