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

the icon component that integrated in nuxt-ui by default is not shown at first loading #2195

Closed
gaomingzhao666 opened this issue Sep 13, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@gaomingzhao666
Copy link

Environment

Nuxt project info: 12:26:48 PM



Version

v2.18.4

Reproduction

the online address: https://nano-portfolio-ruby.vercel.app/
the repo: https://github.com/gaomingzhao666/nano-portfolio

Description

Hey, I don't install nuxt-icon module and I can use icons directly in nuxt-ui, because I think the nuxt-ui already integrated nuxt-icon module.

The problem is: that the icon is empty when users first enter the page that shows icons, and when I turn off the computer and open it in next day, the bug is reproduced.

I think the server cache is not working properly, should I install nuxt-icon module manually or it's just a bug to nuxt-ui

Additional context

No response

Logs

No response

@gaomingzhao666 gaomingzhao666 added bug Something isn't working triage labels Sep 13, 2024
@Tragio
Copy link
Contributor

Tragio commented Sep 13, 2024

Hi @gaomingzhao666 👋

Take a look at: #2124 (comment)

@gaomingzhao666
Copy link
Author

gaomingzhao666 commented Sep 13, 2024

Hi @gaomingzhao666 👋

Take a look at: #2124 (comment)

Thank you so much!! That's what I want

@benjamincanac benjamincanac removed the triage label Sep 18, 2024 — with Volta.net
gaomingzhao666 added a commit to gaomingzhao666/nano-portfolio that referenced this issue Sep 19, 2024
@gaomingzhao666
Copy link
Author

Hi @gaomingzhao666 👋

Take a look at: #2124 (comment)

Thank you so much for your help, but the issue is still here in my case so I decided to reopen this issue.

I tried to add serverBundle: 'local' in nuxt.config.ts, and installed the icon-set locally, everything is fined in dev mode locally, but the issue that icons component can't load properly when users first load icons component is still here on deployed vercel server.

Also, I tried to install nuxt-icon@latest module independently from nuxt-ui, but the problem is still here.

@gaomingzhao666 gaomingzhao666 changed the title the icon component that integrated in nuxt-ui by default is not cached the icon component that integrated in nuxt-ui by default is not shown at first loading Sep 25, 2024
@gAlleb
Copy link

gAlleb commented Sep 25, 2024

Hi! I can confirm this behavior but starting from nuxt 3.13.0

I have also recently upgraded to nuxt 3.13.2 and icons have broken a bit more:

  1. Navigate to webpage (generated by npm run generate, incognito mode, no cache): no icons.
  2. Refresh page: sometimes there are icons, sometimes not, sometimes only half of them.

I've tried @nuxt/[email protected] - @nuxt/[email protected] - same result. However downgrading to nuxt 3.12.4 fixes the issue.

Icons work ok when you have a simple page with no additional modules or stores. But when you add stores (pinia), persistency, onMounted hooks - it seems like something messing with the icons. Everything else works great.

@gAlleb
Copy link

gAlleb commented Sep 25, 2024

little update to the previous post.

Finally managed to make it work (both ssr and ssg) with:

  1. Installed locally all icons (@iconify-json/***).
export default defineNuxtConfig({
  modules: [
    '@nuxt/ui'
  ],
  icon: {
clientBundle: {
      // scan all components in the project and include icons 
      scan: true,
      // guard for uncompressed bundle size, will fail the build if exceeds
      sizeLimitKb: 256,
    },
  },
})

@gaomingzhao666, I think you should include clientBundle. It does fix it for nuxt 3.12.4 and 3.13.2 and for nuxt/ui also.

Howewer one question still bothers me. Same nuxt/ui, same tailwind. 3.12.4 without the above settings works like a charm, but 3.13.2 barely loads icons. Just changing nuxt 3.12.4 to 3.13.2 and the necessity of the the above arises. But why?

Also I've noticed that if 3.12.4 and nuxt/[email protected] together result in the same issue without the above settings (with nuxt/[email protected] everything works fine).

With the minimal amount of site payload (one page - 2-3 icons) - 3.13.2 works fine without the above changes. When full project is in place - icons without the above changes stop working. I'm talking about npm run generate with ssr:true. npm run build works in every case.

Can someone elaborate?

@gaomingzhao666
Copy link
Author

@gAlleb, Thank you so much for your help with the detailed and patient interpretation.😊

I added the code that you mentioned, the problem is solved.

@gaomingzhao666
Copy link
Author

@gAlleb, Thank you so much for your help with the detailed and patient interpretation.😊

I added the code that you mentioned, the problem is solved.

I would sad to say that the problem is still here but barely better, there are still a couple of icons can not load when I leave for a long time and then access the website again, but at least most of icons can load.😂

I guess it is just too many icons on this page.

@gAlleb
Copy link

gAlleb commented Sep 26, 2024

maybe

Scanning is relying on static analysis, which means only literal usages will be detected. Avoid constructing the icon name dynamically whenever possible.

<template>
  <!-- Avoid this -->
  <Icon :name="`carbon:${dark ? 'moon' : 'sun'}`" />

  <!-- Prefer this -->
  <Icon :name="dark ? 'carbon:moon' : 'carbon:sun'" />
</template>

Also with clientBundle it should work. You can try and explicitly set icons that do not show:

icon: {
    clientBundle: {

      // list of icons to include in the client bundle
      icons: [
        'uil:github',
        'logos:vitejs'

      // here

      ],

      scan: true,
      includeCustomCollections: true, 
      sizeLimitKb: 256,
    },
  },

@gaomingzhao666
Copy link
Author

@gAlleb Thanks again for your help.

The official documentation said that it would find icons and automatically import from iconify if installed icon-set locally, explicitly specifying the icon-set array in nuxt.config.ts may be a great method to solve it.

Thank you so much for your detailed explanation and continual help!!

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

No branches or pull requests

4 participants