-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(plugin-nuxt): remove useNuxtApp mock in nuxt plugin preventing some behaviors (fix #703) #710
base: main
Are you sure you want to change the base?
Conversation
…viors remove useNuxtApp mock since it prevents some plugins to run (e.g. @nuxtjs/i18n). It fixes the issue histoire-dev#703 .
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Run & review this pull request in StackBlitz Codeflow. |
✅ Deploy Preview for histoire-examples-svelte3 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for histoire-controls ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for histoire-examples-vue3 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for histoire-site ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hey there ! I believe there must be a reason why the author decided to entirely mock the useNuxtApp (altough I don't understand it). Maybe a better solution might be to just inline the actual nuxt config in the useNuxtApp composable ? diff --git a/packages/histoire-plugin-nuxt/runtime/composables.mjs b/packages/histoire-plugin-nuxt/runtime/composables.mjs
deleted file mode 100644
index 9b9a4d8..0000000
--- a/packages/histoire-plugin-nuxt/runtime/composables.mjs
+++ /dev/null
@@ -1 +0,0 @@
-export const useNuxtApp = () => ({ runWithContext: async fn => await fn() })
diff --git a/packages/histoire-plugin-nuxt/src/index.ts b/packages/histoire-plugin-nuxt/src/index.ts
index b284eea..ca3cc8f 100644
--- a/packages/histoire-plugin-nuxt/src/index.ts
+++ b/packages/histoire-plugin-nuxt/src/index.ts
@@ -135,7 +135,17 @@ async function useNuxtViteConfig() {
}
const runtimeDir = fileURLToPath(new URL('../runtime', import.meta.url))
nuxt.options.build.templates.push(
- { src: join(runtimeDir, 'composables.mjs'), filename: 'histoire/composables.mjs' },
+ {
+ async getContents() {
+ return `
+ export const useNuxtApp = () => ({
+ runWithContext: async (fn) => await fn(),
+ $config: ${JSON.stringify(nuxt.options.runtimeConfig)},
+ })
+ `
+ },
+ filename: "histoire/composables.mjs",
+ },
{ src: join(runtimeDir, 'components.mjs'), filename: 'histoire/components.mjs' },
)
|
Hey @gjeusel, |
#666 is another related discussion. @juleshry I implemented your solution and it worked for me on Nuxt 3.10.3 with Histoire 0.17.15 @gjeusel I think you're right to point out that there must be a good reason it was stubbed. But just copying the config in to the stub doesn't solve the problem completely either. (See #666) Until we completely understand the intention behind the stub it's hard to propose a fix. |
I wonder why the tests don't run on this PR 🤔 |
anything new? i try to render https://nuxt.com/modules/icon in histoire but it is not working |
Description
This PR fixes the issue #703. This bug comes from the useNuxtApp that is mocked in /packages/histoire-plugin-nuxt/runtime/composables.mjs
It just removes this mock to use the useNuxtApp version from Nuxt. It allows some plugins that requires data from useNuxtApp to run correctly (e.g. @nuxtjs/i18n).
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).