Skip to content

Commit 065e8ee

Browse files
authoredApr 10, 2025··
fix: apply hydration mismatch bug fix to SVG icons (#377)
1 parent 0c6b1d6 commit 065e8ee

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed
 

Diff for: ‎src/runtime/components/svg.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { h } from 'vue'
33
import type { PropType } from 'vue'
44
import type { NuxtIconRuntimeOptions, IconifyIconCustomizeCallback } from '../../types'
55
import { initClientBundle, loadIcon, useResolvedName } from './shared'
6-
import { useAsyncData, useNuxtApp, defineComponent, useAppConfig } from '#imports'
6+
import { useAsyncData, useNuxtApp, defineComponent, useAppConfig, onServerPrefetch } from '#imports'
77

88
export 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

Comments
 (0)
Please sign in to comment.