Skip to content

Commit

Permalink
fix: show skeleton when fetch image (#118)
Browse files Browse the repository at this point in the history
* fix: show skeleton when fetch image

* chore: resolve Webpack`s AutoPublicPathRuntimeModule has a DOM Clobbering Gadget that leads to XSS
  • Loading branch information
poiu694 authored Sep 2, 2024
1 parent 8f007ec commit 18773d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
27 changes: 12 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/components/common/proxy-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ interface ProxyImageProps extends ImgHTMLAttributes<HTMLImageElement> {

const ProxyImage = ({ src, ...props }: ProxyImageProps) => {
const [url, setUrl] = useState('')
const [isFetch, setIsFetch] = useState(false)
const { ref, inView, isLoading } = useLazyImage({ src: url, options: {} })

useEffect(() => {
const convertImage = async () => {
try {
setIsFetch(true)
const response = await api.proxy.get(src)
const blob = await response.blob()
const objectURL = URL.createObjectURL(blob)
setUrl(objectURL)
} catch {}
} finally {
setIsFetch(false)
}
}

if (!url && inView && src.startsWith('http')) {
Expand All @@ -36,7 +40,7 @@ const ProxyImage = ({ src, ...props }: ProxyImageProps) => {
}
}, [inView, src, url])

if (isLoading) {
if (isLoading || isFetch) {
return (
<div className={cn('animate-pulse', props.className)}>
<div
Expand Down

0 comments on commit 18773d5

Please sign in to comment.