fix: media preview bug when zero size, close #764 (#765)

* fix: media preview bug when zero size, close #764

* fix: consider NaN case

* fix: add props.style

* chore: style

---------

Co-authored-by: Innei <i@innei.in>
This commit is contained in:
Cesaryuan 2024-10-07 20:25:58 +08:00 committed by GitHub
parent d2b5cc36e9
commit 208d09b8d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 5 deletions

View File

@ -290,6 +290,8 @@ const FallbackableImage: FC<
}
}, [currentSrc, currentState, fallbackUrl, src])
const height = Number.parseInt(props.height as string)
const width = Number.parseInt(props.width as string)
return (
<div className={cn("center flex size-full flex-col", containerClassName)}>
{isLoading && !isAllError && (
@ -317,11 +319,15 @@ const FallbackableImage: FC<
blurhash && !isLoading ? "duration-500 ease-in-out animate-in fade-in-0" : "",
props.className,
)}
style={{
maxHeight: `min(100%, ${Number.parseInt(props.height as string)}px)`,
maxWidth: `min(100%, ${Number.parseInt(props.width as string)}px)`,
...props.style,
}}
style={
Number.isNaN(height) || Number.isNaN(width) || height === 0 || width === 0
? props.style
: {
maxHeight: `min(100%, ${height}px)`,
maxWidth: `min(100%, ${width}px)`,
...props.style,
}
}
/>
)}
{isAllError && (