Skip to content

Commit f5e74f5

Browse files
committedDec 6, 2024··
fix(css): consistent server prefetch for stable useId
1 parent 6fcd8e0 commit f5e74f5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
 

‎src/runtime/components/css.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ export const NuxtIconCss = /* @__PURE__ */ defineComponent({
156156
)
157157
}
158158

159-
if (import.meta.server) {
160-
const configs = (useRuntimeConfig().icon || {}) as NuxtIconRuntimeServerOptions
161-
if (!configs?.serverKnownCssClasses?.includes(cssClass.value)) {
162-
onServerPrefetch(async () => {
159+
// We need to always call this hook to make use Vue correctly detect this component as async
160+
// This makes sure `useId` is consistent across server and client
161+
// @see https://github.com/nuxt/icon/issues/310
162+
onServerPrefetch(async () => {
163+
// For dead code elimination
164+
if (import.meta.server) {
165+
const configs = (useRuntimeConfig().icon || {}) as NuxtIconRuntimeServerOptions
166+
if (!configs?.serverKnownCssClasses?.includes(cssClass.value)) {
163167
const icon = await loadIcon(props.name, options.fetchTimeout).catch(() => null)
164168
if (!icon)
165169
return null
@@ -190,9 +194,9 @@ export const NuxtIconCss = /* @__PURE__ */ defineComponent({
190194
ssrCSS.set(props.name, css)
191195
}
192196
return null
193-
})
197+
}
194198
}
195-
}
199+
})
196200

197201
return () => h('span', { class: ['iconify', cssClass.value] })
198202
},

0 commit comments

Comments
 (0)
Please sign in to comment.