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

Rendering wrong icon using computed prop #350

Open
josselinonduty opened this issue Feb 2, 2025 · 4 comments
Open

Rendering wrong icon using computed prop #350

josselinonduty opened this issue Feb 2, 2025 · 4 comments

Comments

@josselinonduty
Copy link

Icons an not rendering correctly when using conditional or computed links.

I am creating a conditional horizontal navigation (using Nuxt UI v2.21.0 and Nuxt icon).

session is a ref provided by better auth. It is empty on first load, and is then hydrated.

const links = computed(() => {
  let _links = [
    [
      {
        label: "Home",
        icon: "tabler:home",
        to: "/",
      },
    ],
    [
      !session.value.data?.user && {
        label: "Register",
        icon: "tabler:user-plus",
        to: "/auth/register",
      },
      !session.value.data?.user && {
        label: "Login",
        icon: "tabler:user",
        to: "/auth/login",
      },
      session.value.data?.user && {
        label: "Logout",
        icon: "tabler:logout",
        to: "/auth/logout",
      },
    ],
  ];

  return _links.map((list) => list.filter(Boolean)) as Exclude<
    (typeof _links)[number][number],
    undefined | false
  >[][];
});

Screenshots:

Before login:

Image

After login:

Image

In fact, when I go into iconify css class definition, this is what I get:

:where(.i-tabler\:logout) {
    display: inline-block;
    width: 1em;
    height: 1em;
    background-color: currentColor;
    -webkit-mask-image: var(--svg);
    mask-image: var(--svg);
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    --svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='none' stroke='black' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M8 7a4 4 0 1 0 8 0a4 4 0 0 0-8 0m8 12h6m-3-3v6M6 21v-2a4 4 0 0 1 4-4h4'/%3E%3C/svg%3E");
}

I let you check, but it is the wrong icon. There is some kind of rendering mismatch.

This first issue is not a very good one. I didn't really know what to provide. Please ask me questions if you need more context information.

@josselinonduty
Copy link
Author

josselinonduty commented Feb 3, 2025

I just faced the same issue somewhere else:

<UInput
        v-model="input.email"
        :icon="
          session.data?.user.emailVerified
            ? 'tabler:rosette-discount-check'
            : 'tabler:rosette-discount-check-off'
        "
        :color="session.data?.user.emailVerified ? 'green' : 'red'"
        disabled
      />

It is always showing the first one: 'tabler:rosette-discount-check'

There is definitely a caching or rendering issue with nuxt icon

@noook
Copy link

noook commented Feb 5, 2025

Indeed, just came across this issue @josselinonduty

There is a cache directory.

Run ls -la .nuxt/cache/nuxt/icon and you'll notice every icon cached until now. You can remove the cache manually, I wonder if restarting the server discards the cache

@josselinonduty
Copy link
Author

Did not work for me. I emptied the cache, reloaded the server, the issue is still there

@josselinonduty
Copy link
Author

Fixed it (but seems more like a hack)

nuxt.config.ts

icon: {
    clientBundle: {
      icons: [
        "tabler:home",
        "tabler:list",
        "tabler:user-plus",
        "tabler:user",
        "tabler:logout",
        "tabler:rosette-discount-check",
        "tabler:rosette-discount-check-off",
      ],
    },
  },

I don't like this approach though. Also, the wrong icon flashes before the correct one appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants