fix: handle invalid URL in hostname extraction
This commit is contained in:
@@ -13,7 +13,13 @@ export default function WebPreview({
|
|||||||
size?: 'normal' | 'small'
|
size?: 'normal' | 'small'
|
||||||
}) {
|
}) {
|
||||||
const { title, description, image } = useFetchWebMetadata(url)
|
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) {
|
if (!title) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user