Skip to content

Commit 17d9348

Browse files
mukundshahatinux
andauthored
fix: scope per-instance customize to unique CSS selector (#483)
Co-authored-by: Sébastien Chopin <[email protected]>
1 parent 4502522 commit 17d9348

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/runtime/components/css.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { PropType } from 'vue'
55
import type { IconifyIcon } from '@iconify/types'
66
import type { NuxtIconRuntimeOptions, NuxtIconRuntimeServerOptions } from '../../types'
77
import type { IconifyIconCustomizeCallback } from './shared'
8+
import { hash } from 'ohash'
89
import { loadIcon, resolveCustomizeFn } from './shared'
910
import { useAppConfig, useNuxtApp, useHead, useRuntimeConfig, onServerPrefetch } from '#imports'
1011

@@ -81,7 +82,16 @@ export const NuxtIconCss = /* @__PURE__ */ defineComponent({
8182
setup(props) {
8283
const nuxt = useNuxtApp()
8384
const options = useAppConfig().icon as NuxtIconRuntimeOptions
84-
const cssClass = computed(() => props.name ? options.cssSelectorPrefix + props.name : '')
85+
const cssClass = computed(() => {
86+
if (!props.name) return ''
87+
const base = options.cssSelectorPrefix + props.name
88+
// When a per-instance customize function is provided, append a hash of its source
89+
// so that distinct customizations get their own selector and CSS rule.
90+
if (typeof props.customize === 'function') {
91+
return base + '--customized-' + hash(props.customize.toString())
92+
}
93+
return base
94+
})
8595

8696
function getIcon(name: string) {
8797
if (!name)
@@ -191,10 +201,10 @@ export const NuxtIconCss = /* @__PURE__ */ defineComponent({
191201
})
192202
})
193203
}
194-
// Dedupe CSS
195-
if (props.name && !ssrCSS.has(props.name)) {
204+
// Dedupe CSS (use cssClass as key to support per-instance customization)
205+
if (cssClass.value && !ssrCSS.has(cssClass.value)) {
196206
const css = getCSS(icon, false)
197-
ssrCSS.set(props.name, css)
207+
ssrCSS.set(cssClass.value, css)
198208
}
199209
return null
200210
}

0 commit comments

Comments
 (0)