Skip to content

Commit b6cd843

Browse files
authoredOct 8, 2024··
fix: loadIcon always console warn (#272)
1 parent 2d12da6 commit b6cd843

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed
 

‎src/runtime/components/shared.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed } from 'vue'
2-
import { loadIcons, getIcon as _getIcon } from '@iconify/vue'
2+
import { getIcon as _getIcon, loadIcon as _loadIcon } from '@iconify/vue'
33
import { consola } from 'consola'
44
import type { IconifyIcon } from '@iconify/types'
55
import type { NuxtIconRuntimeOptions } from '../../types'
@@ -16,14 +16,21 @@ export async function loadIcon(name: string, timeout: number): Promise<Required<
1616
if (_icon)
1717
return _icon
1818

19-
const load = new Promise<void>(resolve => loadIcons([name], () => resolve()))
20-
.catch(() => null)
19+
let timeoutWarn: ReturnType<typeof setTimeout>
20+
const load = _loadIcon(name)
21+
.catch(() => {
22+
consola.warn(`[Icon] failed to load icon \`${name}\``)
23+
return null
24+
})
25+
.finally(() => clearTimeout(timeoutWarn))
2126

2227
if (timeout > 0)
23-
await Promise.race([load, new Promise<void>(resolve => setTimeout(() => {
24-
consola.warn(`[Icon] loading icon \`${name}\` timed out after ${timeout}ms`)
25-
resolve()
26-
}, timeout))])
28+
await Promise.race([load, new Promise<void>((resolve) => {
29+
timeoutWarn = setTimeout(() => {
30+
consola.warn(`[Icon] loading icon \`${name}\` timed out after ${timeout}ms`)
31+
resolve()
32+
}, timeout)
33+
})])
2734
else
2835
await load
2936

0 commit comments

Comments
 (0)
Please sign in to comment.