@@ -3,7 +3,7 @@ import { h } from 'vue'
33import type { PropType } from 'vue'
44import type { NuxtIconRuntimeOptions , IconifyIconCustomizeCallback } from '../../types'
55import { initClientBundle , loadIcon , useResolvedName } from './shared'
6- import { useAsyncData , useNuxtApp , defineComponent , useAppConfig } from '#imports'
6+ import { useAsyncData , useNuxtApp , defineComponent , useAppConfig , onServerPrefetch } from '#imports'
77
88export const NuxtIconSvg = /* @__PURE__ */ defineComponent ( {
99 name : 'NuxtIconSvg' ,
@@ -26,13 +26,17 @@ export const NuxtIconSvg = /* @__PURE__ */ defineComponent({
2626
2727 if ( name . value ) {
2828 // 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 , options . fetchTimeout ) ,
33- { deep : false } ,
34- )
35- }
29+ // Apply server prefetch function used for CSS icons.
30+ // @See https://github.com/nuxt/icon/issues/356
31+ onServerPrefetch ( async ( ) => {
32+ if ( import . meta. server ) {
33+ await useAsyncData (
34+ storeKey ,
35+ async ( ) => await loadIcon ( name . value , options . fetchTimeout ) ,
36+ { deep : false } ,
37+ )
38+ }
39+ } )
3640
3741 // On client side, we feed Iconify we the data we have from server side to avoid hydration mismatch
3842 if ( import . meta. client ) {
0 commit comments