@@ -3,7 +3,7 @@ import { h } from 'vue'
3
3
import type { PropType } from 'vue'
4
4
import type { NuxtIconRuntimeOptions , IconifyIconCustomizeCallback } from '../../types'
5
5
import { initClientBundle , loadIcon , useResolvedName } from './shared'
6
- import { useAsyncData , useNuxtApp , defineComponent , useAppConfig } from '#imports'
6
+ import { useAsyncData , useNuxtApp , defineComponent , useAppConfig , onServerPrefetch } from '#imports'
7
7
8
8
export const NuxtIconSvg = /* @__PURE__ */ defineComponent ( {
9
9
name : 'NuxtIconSvg' ,
@@ -26,13 +26,17 @@ export const NuxtIconSvg = /* @__PURE__ */ defineComponent({
26
26
27
27
if ( name . value ) {
28
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 , 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
+ } )
36
40
37
41
// On client side, we feed Iconify we the data we have from server side to avoid hydration mismatch
38
42
if ( import . meta. client ) {
0 commit comments