Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when duplicate icon names are included in config #237

Closed
maxchang3 opened this issue Aug 20, 2024 · 0 comments · Fixed by #245
Closed

Error when duplicate icon names are included in config #237

maxchang3 opened this issue Aug 20, 2024 · 0 comments · Fixed by #245
Labels
bug Something isn't working

Comments

@maxchang3
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants