fix: handle invalid URL in hostname extraction

This commit is contained in:
codytseng
2024-11-29 15:50:10 +08:00
parent ab285b0e97
commit ed0dd76a5b

View File

@@ -13,7 +13,13 @@ export default function WebPreview({
size?: 'normal' | 'small'
}) {
const { title, description, image } = useFetchWebMetadata(url)
const hostname = useMemo(() => new URL(url).hostname, [url])
const hostname = useMemo(() => {
try {
return new URL(url).hostname
} catch {
return ''
}
}, [url])
if (!title) {
return null