-
Notifications
You must be signed in to change notification settings - Fork 945
Description
Description
I have originally posted this as a comment here but I received no response from the maintainers. So I'm reposting this as an issue for visibility.
For context, there are currently two icon systems in nuxt/ui. One is based on tailwind css and the other is based on nuxt-icon. The user may switch between the two using a dynamic attribute.
This is a very bad design decision. Quoting @benjamincanac here for the original reasoning behind this design decision:
It's a tiny bit more work as you have to install the iconify packages for the collections you want to use but this makes icons instantly load as they are bundled in your css instead of fetching them from the Iconify API when rendering the page the first time.
So the problem we're trying to solve here is that "nuxt-icon causes icons to not instantly load", right?
And I would agree that it's a pretty bad problem. The iconify API is not the most reliable, and occasionally icons don't render on the Nuxt UI official website.
This is caused by a known issue in nuxt-icon, nuxt/icon#34 or nuxt/icon#99
Basically, nuxt-icon doesn't load the icon on the server side, and instead opt to call the iconify API from the client at all times.
So the reasonable solution to the problem of "nuxt-icon icons doesn't instantly load" would be "fix nuxt-icon so that icons can be injected and bundled at build time".
Instead of doing that, here we introduced another dependency so that icons can be injected by tailwind as a CSS icon.
What's the problem with that?
- Dynamic icons, which was partially addressed in feat(Icon): switch to nuxt-icon with dynamic prop or app config feat(Icon): switch to
nuxt-iconwithdynamicprop or app config #862. feat(Icon): switch to nuxt-icon with dynamic prop or app config feat(Icon): switch tonuxt-iconwithdynamicprop or app config #862 basically falls back to the nuxt-icon component when dynamic = true. But then with that, you once again lose the ability to allow icons to load instantly, which was why egoist/tailwindcss-icons was introduced in the first place. - Behavior consistency. nuxt-icon allows you to define custom Icon API sources using addIconProvider. egoist/tailwindcss-icons expect you to provide them in nuxt.config.ts. I can use bundle:name as the name property in "static" icons but not dynamic icons. That means for any custom icons I have to package them twice, once for static icons as an npm package and once for dynamic icons on my custom iconify server.
- Implementation discrepancy. nuxt-icon embeds the SVG into the DOM. egoist/tailwindcss-icons uses CSS icons. monotone icons are image-mask. Image icons are background-image. That means if I want to style a subset of the paths in the SVG, I can do that with nuxt-icon, but not egoist/tailwindcss-icons.
What I'm trying to say here is that by introducing egoist/tailwindcss-icons you're significantly complicating an otherwise simple problem. Just go into nuxt-icon, help out @atinux, and fix nuxt-icon so that it can preload icons. Call useAsyncData to fetch the icons on the server side so they're available as soon as the page loads. That way you have one unified method of loading icons, instead of introducing a whole lot of mental overload for a problem as trivial as showing icons.