histoire-dev / histoire

⚡ Fast and beautiful interactive component playgrounds, powered by Vite
https://histoire.dev
MIT License
3.16k stars 186 forks source link

[Nuxt] useState crashes histoire - nuxt is undefined #197

Open Rigo-m opened 2 years ago

Rigo-m commented 2 years ago

Describe the bug

When using useState, histoire crashes

image

Reproduction

https://stackblitz.com/edit/nuxt-starter-szzksv?file=package.json,components%2FHello.vue,components%2FHello.story.vue

System Info

Stackblitz

Used Package Manager

npm

Validations

Akryum commented 2 years ago

We probably need to mock this nuxt object? @danielroe

Rigo-m commented 2 years ago

This is a quick mock for useState that I've internally used in some storybook projects:

import { computed, ref, reactive } from "vue"

const globalState = reactive({})

export const useState = (key, initial) => {
  if (!globalState[key]) {
    globalState[key] = initial()
  }

  const computedState = computed({
    get: () => {
      // force reactivity
      return globalState[key]
    },
    set: (value) => {
      globalState[key] = value
    },
  })

  return computedState
}

Although, the problem is broader, because everything that uses some nuxt runtime (useNuxtApp alike) crashes histoire.

agritheory commented 2 years ago

@Rigo-m I am also having this issue. Could you help me understand how to use the useState mock you provided?

Rigo-m commented 2 years ago

@agritheory you can put this mock useState file somewhere in your project and auto-import it by adding this vite plugin to histoire vite configuration

alxshell commented 2 years ago

Hi @Akryum are there any plans to fix this issue or do you have any instructions for a workaround or something like that? Would be very appreciated. Thx.

Lyokolux commented 1 year ago

Histoire using Nuxt related stuff is also an issue in #300

Rigo-m commented 1 year ago

@danielroe @Akryum is there any thoughts/progress on this?

Archetipo95 commented 1 year ago

Any update on this issue/bug?

LuciaFe commented 1 year ago

i also have the same problem. Any update?

Akryum commented 1 year ago

@danielroe is working on stuff to simplify the nuxt integration https://twitter.com/danielcroe/status/1590490011501142017

Akryum commented 1 year ago

Please give [v0.15.0] a try and report back if your issue is solved or not :pray:

agritheory commented 1 year ago

@Akryum We've focused on the Vue-only part of the component library we're building with the help of Histoire and have slotted a Nuxt integration for Q3 this year. We won't be able to provide feedback on this specific issue until we pick that up again.

Archetipo95 commented 1 year ago

Please give [v0.15.0] a try and report back if your issue is solved or not 🙏

I think that is still broken, I'm not sure if I'm doing everything right. Maybe it's not related problem, but it's giving me 404 on a story with a bunch of links made with NuxtLink.

My Repository is public here: https://github.com/Archetipo95/nuxt-histoire/tree/testing-nuxt

And you can also see a deply on netlify: https://deploy-preview-11--nuxt-histoire.netlify.app/

LoMonacoSalvatore commented 7 months ago

any news?