question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue3 component can no longer be used directly in another component

See original GitHub issue

Describe the bug When using the <font-awesome-icon> as a direct child in your template, it will throw an error when its state should be changed.

Tagging @otijhuis here has #250 seems to be the root cause.

Reproducible test case This is my wrapper component, which includes the :key workaround:

<template>
  <font-awesome-icon
    :key="version"
    :fixed-width="!noFixedWidth"
    :icon="icon"
    :spin="spin"
    v-bind="$attrs"/>
</template>

<script lang="ts">
import {defineComponent, ref, watch} from 'vue';

export default defineComponent({
  name: 'SimpleIcon',
  props: {
    icon: {
      type: [String, Array],
      required: true,
    },
    spin: Boolean,
    noFixedWidth: Boolean,
  },
  setup(props) {
    const version = ref(0);
    watch(props, () => version.value++, {deep: true});

    return {
      version,
    };
  },
});
</script>

It triggers the following error whenever I update any prop of the SimpleIcon property: image

When I change my component to have a wrapper element around the font-awesome-icon, such as a simple span, the error disappears and it works as expected. It also no longer needs the :key hack for the reactivity to work.

Expected behavior There shouldn’t be an error.

Desktop (please complete the following information):

  • Edge 91 (Windows)
  • 3.0.0-4

Additional context This error didn’t happen with 3.0.0-3

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
otijhuiscommented, Jun 5, 2021

Seems that was indeed the issue.

Not sure if it’s the best solution but this works:

return () => h(() => vnode.value)

Something like that is probably what happens when font-awesome-icon is wrapped by SimpleIcon. Tried it in my test application and both SimpleIcon and font-awesome-icon work with v-show now.

FontAwesomeLayersText.js had the same issue as well.

I’ll see if I can add a few v-show tests and create a PR with the fix.

EDIT:

Might be best to change the title of the issue to include v-show so it’s easier to find.

0reactions
otijhuiscommented, Jun 5, 2021

I couldn’t create a failing test. Maybe the issue was introduced after 3.0.0 which is the current dev dependency.

Created a PR (#315) which should fix the issue.

Maybe you could test the PR by checking out the code from my repo, switch to the 3.x branch, and setting the vue-fontawesome version to “file:…/some/location/vue-fontawesome”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vuejs3 extend another component or methods - Stack Overflow
So I have one or more methods in a component. How can I use these methods in another component? vue.js · vuejs3.
Read more >
Components Basics - Vue.js
Components allow us to split the UI into independent and reusable pieces, and think about each piece in isolation. It's common for an...
Read more >
Components | Introduction to Vue.js
Like any other HTML element, Vue components can receive arguments, called props or properties. Props are used to convey information from a parent...
Read more >
Rendering a list of Vue components - Learn web development
To do that, we'll add a data property to the App.vue component object, ... there's one other piece of syntax to know about...
Read more >
Why Your Vue Component Isn't Updating (and how to fix it)
Check that variables are reactive; Make sure to update Arrays and Objects correctly (only in Vue 2); Use props directly; Always use computed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found