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

Vuetify + NuxtIcon: Vue warn Slot "default" invoked outside of the render function: #89

Open
alniv94 opened this issue Jun 29, 2023 · 9 comments

Comments

@alniv94
Copy link

alniv94 commented Jun 29, 2023

I'm using nuxt-icon and vuetify, got this warnings when using the nuxt-icon inside the vTabs and vMenu of vuetify. The warnings are produced when the icons are hidden then display like in vTabs and vMenu.
Here is the link to reproduce what I encounter:
https://stackblitz.com/edit/nuxt-starter-fnzdtw?file=app.vue

image

@stephenjason89
Copy link

I experience this as well. Same goes for V-Tooltip

@niko-chaffinchicas
Copy link

I've found that there are a variety of contexts where Vuetify prefers to have the <Icon> component placed in the default slot of the <v-icon> component. There's still some funky stuff you have to do, like use a blank icon attribute on <v-btn> if you want an icon button, and so on:

<v-btn icon="">
  <v-icon>
    <Icon name="mdi:vuetify" />
  </v-icon>
</v-btn>

But from what I can see in the playground, wrapping the <Icon> component in a <v-icon> component does resolve the warning that you're seeing.

@stephenjason89
Copy link

stephenjason89 commented Jul 14, 2023

I've found that there are a variety of contexts where Vuetify prefers to have the <Icon> component placed in the default slot of the <v-icon> component. There's still some funky stuff you have to do, like use a blank icon attribute on <v-btn> if you want an icon button, and so on:

<v-btn icon="">
  <v-icon>
    <Icon name="mdi:vuetify" />
  </v-icon>
</v-btn>

But from what I can see in the playground, wrapping the <Icon> component in a <v-icon> component does resolve the warning that you're seeing.

I made a component that wraps Icon with v-icon
image

Then tried using it like
image

Still getting
image

But even this causes that error
image

@niko-chaffinchicas
Copy link

@stephenjason89 Could you share a stackblitz link demonstrating the issue you're running into? I wasn't able to replicate that issue from the snippets you posted.

@stephenjason89
Copy link

stephenjason89 commented Jul 15, 2023

Hello @niko-chaffinchicas, It seems like, i was getting this error on Icon.
Upon trying IconCSS every error went away.
I end up creating an Icon component

image

This solved all the errors I had

You can use it like
image
Other attrs like color, size, etc. will be inherited by v-icon

@OriaBiton
Copy link

I experienced this as well.
What seemed to work best for me was a combination of the suggestions above: Only using IconCSS.

<template>
  <!-- Regular <Icon> (+Vuetify) causes "Vue warn Slot "default" invoked outside of the render function" -->
  <!-- https://github.com/nuxt-modules/icon/issues/89 -->
  <IconCSS
    :name="icon"
    :size="sizeInUnits"
    :class="{ start, end }"
    :style="{ color: resolvedColor }"
  />
</template>

<script setup lang="ts">
import { LABEL_COLORS } from '~/assets/constants';

const SIZES = {
  'x-small': '1em',
  'small': '1.25em',
  'default': '1.5em',
  'large': '1.75em',
  'x-large': '2em'
};

const {
  size = 'default',
  color
} = defineProps<{
  icon: string;
  size?: keyof typeof SIZES | number;
  color?: string;
  start?: boolean;
  end?: boolean;
}>();

const sizeInUnits = computed(() => typeof size == 'number' ? size.toString() : SIZES[size]);
const isLabelColor = computed(() => color && LABEL_COLORS.includes(color));
const resolvedColor = computed(() => isLabelColor.value ? `rgb(var(--v-theme-${color}))` : color);
</script>

<style scoped>
.start {
  margin-inline-end: 8px;
}
.end {
  margin-inline-start: 8px;
}
</style>

Since this workaround is based on an experimental feature, a proper fix would be appreciated.

@Me-Phew
Copy link

Me-Phew commented Aug 12, 2023

I've noticed that lazy-loading the icon (prefixing it with Lazy) like this: <LazyIcon :name='name' /> gets rid of the error while everything seems to be working correctly.

In case it is important I was getting the error when using the icon inside the v-autocomplete's #item slot.

I'm not sure if this is a correct workaround but since IconCSS is an experimental feature and doesn't work with some icons that I need I don't see any other solution for now.

@alniv94
Copy link
Author

alniv94 commented Jan 29, 2024

Any updates please ?

@lukatavcer
Copy link

lukatavcer commented Apr 25, 2024

I am having the same issue, none of the solutions above fix the issue... the warning stays.
I get it when I am switching pages and it spams a lot of warnings.

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

6 participants