fix: filter empty URLs in image gallery to prevent browser reload

- Add validation to filter out empty and whitespace-only image URLs
- Return null when no valid images exist
- Prevents console errors and browser reload issues from empty img src

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
lyzno1
2025-09-10 23:56:22 +08:00
parent 7a07e8d56b
commit 532aba026a

View File

@ -32,12 +32,15 @@ const ImageGallery: FC<Props> = ({
}) => {
const [imagePreviewUrl, setImagePreviewUrl] = useState('')
const imgNum = srcs.length
const validSrcs = srcs.filter(src => src && src.trim() !== '')
const imgNum = validSrcs.length
const imgStyle = getWidthStyle(imgNum)
if (imgNum === 0) { return null }
return (
<div className={cn(s[`img-${imgNum}`], 'flex flex-wrap')}>
{/* TODO: support preview */}
{srcs.map((src, index) => (
{validSrcs.map((src, index) => (
<img
key={index}
className={s.item}