Closed kilab closed 1 year ago
@kilab Hi! The problem is with the Nuxt plugin for Histoire. It's mocking the useNuxtApp
wrong and probably not initializing viewport module correctly.
Here we initialize the manager getting the initial value and provide it to the nuxtApp. https://github.com/mvrlin/nuxt-viewport/blob/main/src/runtime/plugin.ts#L58
Here is the useViewport
composable. It's only returning the manager injected in the nuxt context.
https://github.com/mvrlin/nuxt-viewport/blob/main/src/runtime/composables.ts#L5
Here you can see how Histoire is mocking useNuxtApp
. Just a simple object.
https://github.com/histoire-dev/histoire/blob/main/packages/histoire-plugin-nuxt/runtime/composables.mjs#L1
Try to open an issue there. I can contribute if needed.
@mvrlin Thank you for your quick response and for pointing me in the right direction.
I'll proceed with opening an issue on the respective repositories to address this problem. I'll include the information you provided about the specific files involved, which will be helpful for the developers to understand the root cause.
@kilab If it's not an obligation to stick with Histoire, consider trying https://github.com/nuxt-community/storybook
Hello!
I am facing the same issue and have already written a few stories for histoire. I don't want to switch to storybook again with all its dependencies, etc ...
By the way the error I'm facing is not exactly the same:
I think there is a window object but no matchMedia method on it. would it be possible to fix it with some polyfill or something ?
Thank you in advance for your answers.
@benavern Hi! Can you make an example in Stackblitz or Codesandbox?
For some reason, I can't reproduce the exact error on stackblitz. https://stackblitz.com/edit/histoire-nuxt3-starter-gtvbpp?file=components%2FMeow.story.vue
Here I have the classic "window is not defined" error
For some reason, I can't reproduce the exact error on stackblitz. https://stackblitz.com/edit/histoire-nuxt3-starter-gtvbpp?file=components%2FMeow.story.vue
Here I have the classic "window is not defined" error
Hmm, okay. Can you show me the test itself?
I don't know what do you mean by "the test" ?
I don't know what do you mean by "the test" ?
How are you testing components? Maybe an example file.
Description
When I try to create a story in Histoire for a component that uses
useViewport().isGreaterOrEquals('m')
, I get an error in the browser:Steps to reproduce
Run Histoire and try to show TestComponent story: https://stackblitz.com/edit/nuxt-starter-uoumbe?file=components%2FTestComponent.vue,stories%2FTestComponent.story.vue
Expected Behavior
The component is displayed in the story and its content changes depending on the viewport.