nuxt / icon

The <Icon> component, supporting Iconify, Emojis and custom components.
https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue
MIT License
864 stars 37 forks source link

fix(icon): use optional chaining to fix 'undefined' error in Histoire #147

Closed RobertHaba closed 3 months ago

RobertHaba commented 3 months ago

Problem

When using the NuxtIcon (Icon) component in Histoire stories, an error occurs: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'component') at Icon.vue:71:49 obraz

Solution

Added optional chaining (?.) to component computed: ...nuxtApp.vueApp?.component...

Changes

Test

clone: https://github.com/RobertHaba/icon/tree/feature/histoire-example or add Histoire package

package.json

"devDependencies": {
    "@histoire/plugin-nuxt": "^0.17.14",
    "@histoire/plugin-vue": "^0.17.14",
    "histoire": "^0.17.14",
    ...
  }

histoire.config.ts

import { defineConfig } from "histoire"
import { HstVue } from "@histoire/plugin-vue"
import { HstNuxt } from "@histoire/plugin-nuxt"
export default defineConfig({
  plugins: [
    HstVue()
    HstNuxt()
  ]
})

Icon.story.vue

<template>
  <Story>
    <Icon name="uil:github" />
  </Story>
</template>

obraz