File tree 1 file changed +14
-7
lines changed
1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { computed } from 'vue'
2
- import { loadIcons , getIcon as _getIcon } from '@iconify/vue'
2
+ import { getIcon as _getIcon , loadIcon as _loadIcon } from '@iconify/vue'
3
3
import { consola } from 'consola'
4
4
import type { IconifyIcon } from '@iconify/types'
5
5
import type { NuxtIconRuntimeOptions } from '../../types'
@@ -16,14 +16,21 @@ export async function loadIcon(name: string, timeout: number): Promise<Required<
16
16
if ( _icon )
17
17
return _icon
18
18
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 ) )
21
26
22
27
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
+ } ) ] )
27
34
else
28
35
await load
29
36
You can’t perform that action at this time.
0 commit comments