natemoo-re/astro-icon

Error when duplicate icon names are included in config

maxchang3 opened this issue · 0 comments

What version of astro-icon are you using?

v1.1.1

Astro Info

Astro                    v4.14.2
Node                     v20.10.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             astro-expressive-code
                         astro-icon
                         @astrojs/mdx
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When using the include option to filter specific icons, providing duplicate icon names causes an error.

import { defineConfig } from 'astro/config';
import icon from 'astro-icon';

// https://astro.build/config
export default defineConfig({
  integrations: [
    icon({
      include: {
        mdi: ['account', 'account'],
      },
    }),
  ],
});
[astro-icon] "mdi" failed to load at least one of the specified icons! Verify the icon names are included in the icon collection.

This issue occurs because in packages/core/src/loaders/loadIconifyCollections.ts, the code checks if all icons are loaded by comparing Object.keys(reducedCollection.icons).length with requestedIcons.length. When icon names are duplicated, the length of requestedIcons does not match the length of reducedCollection.icons, leading to a false error.

What's the expected result?

Although duplicate icon names are unnecessary, the current error message is misleading, as no icons are actually missing. Additionally, when working with large quantities of icons, it’s easy to accidentally include duplicates.

The error message could be improved to indicate the presence of duplicate icon names, or the requestedIcons could be deduplicated automatically. (Like const requestedIcons = Array.from(new Set(include[name]));)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-eafrz4?file=astro.config.mjs&on=stackblitz