File tree 3 files changed +26
-19
lines changed
3 files changed +26
-19
lines changed Original file line number Diff line number Diff line change @@ -77,12 +77,14 @@ export const NuxtIconCss = /* @__PURE__ */ defineComponent({
77
77
async setup ( props ) {
78
78
const nuxt = useNuxtApp ( )
79
79
const options = useAppConfig ( ) . icon as NuxtIconRuntimeOptions
80
- const cssClass = computed ( ( ) => options . cssSelectorPrefix + props . name )
80
+ const cssClass = computed ( ( ) => props . name ? options . cssSelectorPrefix + props . name : '' )
81
81
82
82
function getIcon ( name : string ) {
83
- const registry = _getIcon ( name )
84
- if ( registry )
85
- return registry
83
+ if ( ! name )
84
+ return
85
+ const icon = _getIcon ( name )
86
+ if ( icon )
87
+ return icon
86
88
const payload = nuxt . payload . data [ name ]
87
89
if ( payload ) {
88
90
addIcon ( name , payload )
@@ -173,7 +175,7 @@ export const NuxtIconCss = /* @__PURE__ */ defineComponent({
173
175
} )
174
176
}
175
177
// Dedupe CSS
176
- if ( ! ssrCSS . has ( props . name ) ) {
178
+ if ( props . name && ! ssrCSS . has ( props . name ) ) {
177
179
const css = getCSS ( icon , false )
178
180
ssrCSS . set ( props . name , css )
179
181
}
Original file line number Diff line number Diff line change 1
1
import { computed } from 'vue'
2
2
import { loadIcons , getIcon as _getIcon } from '@iconify/vue'
3
+ import type { IconifyIcon } from '@iconify/types'
3
4
import type { NuxtIconRuntimeOptions } from '../../types'
4
5
import { useAppConfig } from '#imports'
5
6
import { init } from '#build/nuxt-icon-client-bundle'
6
7
7
- export async function loadIcon ( name : string ) {
8
+ export async function loadIcon ( name : string ) : Promise < Required < IconifyIcon > | null > {
9
+ if ( ! name )
10
+ return null
8
11
init ( )
9
12
await new Promise ( resolve => loadIcons ( [ name ] , ( ) => resolve ( true ) ) )
10
13
. catch ( ( ) => null )
Original file line number Diff line number Diff line change @@ -24,20 +24,22 @@ export const NuxtIconSvg = /* @__PURE__ */ defineComponent({
24
24
25
25
const storeKey = 'i-' + name . value
26
26
27
- // On server side, we fetch the icon data and store it in the payload
28
- if ( import . meta. server ) {
29
- useAsyncData (
30
- storeKey ,
31
- ( ) => loadIcon ( name . value ) ,
32
- { deep : false } ,
33
- )
34
- }
27
+ if ( name . value ) {
28
+ // On server side, we fetch the icon data and store it in the payload
29
+ if ( import . meta. server ) {
30
+ useAsyncData (
31
+ storeKey ,
32
+ ( ) => loadIcon ( name . value ) ,
33
+ { deep : false } ,
34
+ )
35
+ }
35
36
36
- // On client side, we feed Iconify we the data we have from server side to avoid hydration mismatch
37
- if ( import . meta. client ) {
38
- const payload = nuxt . payload . data [ storeKey ]
39
- if ( payload ) {
40
- addIcon ( name . value , payload )
37
+ // On client side, we feed Iconify we the data we have from server side to avoid hydration mismatch
38
+ if ( import . meta. client ) {
39
+ const payload = nuxt . payload . data [ storeKey ]
40
+ if ( payload ) {
41
+ addIcon ( name . value , payload )
42
+ }
41
43
}
42
44
}
43
45
You can’t perform that action at this time.
0 commit comments