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.

[Documentation] The Example for mdiSvg icons makes the icon variables have unnecessary reactivity.

See original GitHub issue

Environment

Browsers: Chrome 75.0.3770.142 OS: Mac OS 10.14.6

Steps to reproduce

Storing the imported icon value in the component data has several effects. It assumes that we are not making a functional component and it gives the variable storing the icon svg data reactivity to changes which are never going to happen.

Expected Behavior

The svg data for icons should be static and non-reactive. Every attempt should be made to eliminate any data or computational overhead with icons. We shouldn’t just try to make the payload smaller, we should also make it efficient with how it’s used.

Actual Behavior

The example places the icon svg data into the component’s data object. Vue will then add watchers to this data which shouldn’t change in most use cases, adding additional overhead to the component. The means that if the component is making use of many icons, its making many watchers.

Reproduction Link

https://vuetifyjs.com/en/customization/icons#install-material-design-icons-js-svg

Other comments

This is what is in the example:

<!-- Vue Component -->

<template>
  <v-icon>{{ svgPath }}</v-icon>
</template>

<script>
  import { mdiAccount } from '@mdi/js'

  export default {
    data: () => ({
      svgPath: mdiAccount
    }),
  }
</script>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tomparlecommented, Aug 1, 2020

My two cents on this one (after one year). I think a computed property would be the most suited option. Here’s the pattern I use :

<template>
  <v-icon>{{icons.mdiAccount}}</v-icon>
</template>

import { mdiAccount } from '@mdi/js'
...

computed: {
    icons: () => ({
        mdiAccount
    })
}

But I wish there was some kind of smart loader that can automatically detect the used svg icons and import them, without having to do all the hassle to import and define them as properties to use them in the templates, and also avoiding a big initial payload.

2reactions
MajesticPotatoecommented, Aug 2, 2019

well what im saying is something like this.

// src/plugins/vuetify.js

import Vue from 'vue'
import Vuetify from 'vuetify/lib'
import { mdiAccount } from '@mdi/js'

Vue.use(Vuetify)

export default new Vuetify({
  icons: {
    iconfont: 'mdiSvg',
    values: {
      account: mdiAccount,
    },
  },
})

// component.vue
<!-- Vue Component -->

<template>
  <v-icon>$vuetify.icons.account</v-icon>
</template>

<script>
  export default {
    data: () => ({}),
  }
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get vuetify to display 'mdiSvg' icons? - Stack Overflow
you should install the right icon library from the vuetify site then import it on the vuetify plugin folder
Read more >
Icon - Quasar Framework
There are multiple types of icons in Quasar: webfont-based, svg-based and ... they are static values, making them reactive would introduce some unnecessary...
Read more >
Changelog - Material for MkDocs - GitHub Pages
Added Simple Icons to bundled icons (+2,300 icons); Added support for changing edit icon; Moved page actions to separate partial ( actions.html ) ......
Read more >
Icon component — Vuetify
Vuetify is a Material Design component framework for Vue.js. It aims to provide all the tools necessary to create beautiful content rich ...
Read more >
[Solved]-How to use Material Design Icons In Angular 4?
Coding example for the question How to use Material Design Icons In Angular 4?-angular.js. ... Your app's main module will also need the...
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