fix: handle invalid URL in hostname extraction
This commit is contained in:
parent
ab285b0e97
commit
ed0dd76a5b
1 changed files with 7 additions and 1 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue