Open CIB opened 6 months ago
Start a new pull request in StackBlitz Codeflow.
Same issue when using nuxtApp.provide('helpers', helpers);
(which I guess has the same logic under the hood.
This is because Histoire/plugin-next stub out useNuxtApp?
This is because Histoire/plugin-next stub out useNuxtApp?
That's the problem.
The stub could replicate a simple provide
by doing something like this:
const nuxtApp = {
runWithContext: async fn => await fn(),
provide(key, value) {
const propertyName = '$' + key;
nuxtApp[propertyName] = value;
}
}
export const useNuxtApp = () => nuxtApp
However, this doesn't completely solve the issue, because I'm seeing that plugins don't get access to the stubbed nuxtApp. So anything they provide still won't be available to components in histoire.
export default defineNuxtPlugin(async (nuxtApp) => {
// nuxtApp here is not the stubbed one
})
export default defineNuxtPlugin(() => {
return {
// This is not going to interact with the stubbed nuxtApp
provide: {
img: useImage(),
},
}
})
I don't fully understand the context around why the decision was made to stub nuxtApp.
If I disable it (by removing the imports:sources
hook) here: https://github.com/histoire-dev/histoire/blob/main/packages/histoire-plugin-nuxt/src/index.ts#L147, histoire is able render all of my components as expected without any noticeable issue.
@Akryum, @danielroe, or others. Some additional high-level info may help someone address the issue.
Describe the bug
When using
provide
from a nuxt plugin, and inserting the provided value into a component usinguseNuxtApp
, the provided value will not be available, and an error will be thrown.Reproduction
Stackblitz: https://stackblitz.com/edit/nuxt-starter-7avtmp?file=components%2Ftest.vue
In
plugins/example.ts
:In
components/test.vue
Then try to start
histoire dev
with a story that includes<Test />
, and an error will be thrown thatnuxtApp.$example
isundefined
.System Info
Used Package Manager
npm
Validations