Open mimiqkz opened 10 months ago
Themes works, but no docs and no controls from MUI
@mimiqkz In main.ts
you've set typescript.reactDocgen
to react-docgen
. That means that your reactDocgenTypescriptOptions
are being ignored. Try setting typescript.reactDocgen
back to react-docgen-typescript
and see if that fixes the auto-generated ArgTypes/Controls.
@shilman Hi, thank you for the reply. I tried changing back to react-docgen-typescript
, re-run storybook, it doesn't work either :(
Do you a have a reproduction repo you can share? If not, can you create one? Go to https://storybook.new or see repro docs. Thank you! π
@shilman Sorry for a late reply, but here is the repo https://github.com/mimiqkz/storybook-vite-bug
@shilman Hello, any luck regarding to this?
Adding component: Button, in Meta solved the problem for me π Edit: Sometimes it works, sometimes not. Extremely inconsistent
As far as I can see, the react-docgen loader isn't applied for node_modules
components. We do this for performance reasons. I can see that you have resolved the issue by adding the component
field to the meta
. But for everyone who wants to use MUI components directly without a wrapper, this will likely not work since react-docgen
isn't applied on node_module components, if they are the entry point. If a component is not in node_modules, but imports components from node_modules
, react-docgen itself can traverse through the import tree and therefore it works.
So let's try to find a workaround for the case, where the component
defined in the meta comes from node_modules
:
If you use Webpack, we must find the appropriate loader and adjust the exclude
pattern. Something like this:
// .storybook/main.ts
const config = {
webpackFinal: async (config) => {
config.module!.rules!.forEach(
(rule) => {
if(rule.loader?.includes('react-docgen')) {
// the default is: /(\.(stories|story)\.(js|jsx|ts|tsx))|(node_modules)/
rule.exclude = /(\.(stories|story)\.(js|jsx|ts|tsx))/
}
}
);
return config;
}
export default config;
Well, for vite-based projects, it turns out to be more complicated because it isn't possible to change the exclude
pattern by manipulating the config. The exclude pattern automatically excludes files in node_modules
.
Before we make any changes or even allow react-docgen to be applied to node_module files, could you see if the Webpack5 customizations work to confirm the theory?
@valentinpalkovic I'm a bit confused. In the github example and I also stated in the comment above. Changing to react-docgen-typescript
won't work so I don't understand why you are talking about react-docgen
... Is there something that I missed?
When I was talking about react-docgen-loader
, I meant react-docgen
, not react-docgen-typescript
.
You can see here what I meant.
Sorry for the confusion. I was not following the whole thread. What exact inconsistencies do you have?
@valentinpalkovic Hello, thank you for the reply. The inconsistency I have is that sometimes I get the docs + the controls from MUI, sometimes I don't. I just updated my with the example github repo
Edit more info: So from this example, Button works, but not Accordion
@shilman @valentinpalkovic Ok I figured out the problem. Docs seem to not work on export default, which is weird btw, but works on named export. Would love to get some insight on why this is the case
That works @valentinpalkovic π π
Would there be any way to get this working for vite based?
@mimiqkz I'm having the same issue where sometimes I get the docs and sometimes they are missing, even for the same MUI component.
Docs seem to not work on export default, which is weird btw, but works on named export. Would love to get some insight on why this is the case
What do you mean by this? How did you end up changing your stories to work?
Describe the bug
I followed everything instructed in the recipe, nothing works, nothing appeared. Both with Vite and Webpack
To Reproduce
Follow the recipe
System
Additional context
The follow codes are written for my
button.stories.tsx
The
button.component.tsx
(same as in the recipe):Then main.ts
For
preview.ts
:MUI v. 5.15.2 and emotion 11.11.3