Skip to content

Commit

Permalink
fix: init client bundle for svg icons, close #228
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 1, 2024
1 parent 77391db commit f433863
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/runtime/components/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { loadIcons, getIcon as _getIcon } from '@iconify/vue'
import type { IconifyIcon } from '@iconify/types'
import type { NuxtIconRuntimeOptions } from '../../types'
import { useAppConfig } from '#imports'
import { init } from '#build/nuxt-icon-client-bundle'
import { init as initClientBundle } from '#build/nuxt-icon-client-bundle'

export { initClientBundle }

export async function loadIcon(name: string): Promise<Required<IconifyIcon> | null> {
if (!name)
return null
init()
initClientBundle()
await new Promise(resolve => loadIcons([name], () => resolve(true)))
.catch(() => null)
return _getIcon(name)
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/components/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Icon as Iconify, addIcon } from '@iconify/vue'
import { h } from 'vue'
import type { PropType } from 'vue'
import type { NuxtIconRuntimeOptions, IconifyIconCustomizeCallback } from '../../types'
import { loadIcon, useResolvedName } from './shared'
import { initClientBundle, loadIcon, useResolvedName } from './shared'
import { useAsyncData, useNuxtApp, defineComponent, useAppConfig } from '#imports'

export const NuxtIconSvg = /* @__PURE__ */ defineComponent({
Expand Down Expand Up @@ -40,6 +40,9 @@ export const NuxtIconSvg = /* @__PURE__ */ defineComponent({
if (payload) {
addIcon(name.value, payload)
}
else {
initClientBundle()
}
}
}

Expand Down

0 comments on commit f433863

Please sign in to comment.