docz: Props components not working since 1.0.0-rc.8
Bug Report
The Props components don’t render props since rc8 (working in rc7).
There is our folders structure:
📂 src
↳ 📂 docs (our documentation with MDX files)
↳ 📂 saagie-ui (our React components)
📄 doczrc.js
// doczrc.js
export default {
title: 'Saagie Design System',
description: 'Documentation from the Saagie Design Team',
src: './src',
public: './src/docs/public',
files: '**/*.mdx',
ignore: ['docs-versions'],
wrapper: 'src/docs/Wrapper',
codeSandbox: false,
}
No idea why, we investigate on it. Any idea?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 17
- Comments: 83 (15 by maintainers)
Commits related to this issue
- Fix props table not showing See https://github.com/doczjs/docz/issues/777 — committed to cdfa/react-turn-reveal by cdfa 5 years ago
@dusty Your components not named for the default pattern
/\/[A-Z]\w*\.(js|jsx|ts|tsx)
(#779), you will need to define filterComponents in yourdoczrc.js
, eg:I’m having the same issue with props not displaying. I’m running on docz 1.0.4.
The interesting thing is if I touch the file that mdx file is importing, then it rebuilds and the props show up. They are never there on the initial load.
At first I thought I’d just write a script that touches all my js files, but that doesn’t seem work. It seems I need to do that one at a time.
PS.
eg
It works, thank you very much! The props components has displayed in my site now.
I’m using 1.04 (latest version) of docz with typescript and I found a workaround for this,
edit .docz/cache/propsParser.json and paste you components’s corresponding json as this:
the key of the json object is the path to your components, then edit your components props: e.g: add/edit a comment of your component’s props. and The props table will show
I’ve found a cause of the Props not working on Windows in version 1.0.3. The
__filemeta.filename
uses backward slashes (windows style) and thestateProps
contain forward slashes, making the find-method not find anything.using 1.2.0
add a prop to doczrc.js
write the regex you want to include your target component
is is confirmed that adding:
to the docz config allows props to be generated for ts projects? it’s not working for me.
code here: https://github.com/madou/yubaba/pull/110
edit: clearing
.docz
folder and then re-running produces the error:will dig into it.
anyone know why
defaultProps.initializer
might be undefined? if i guard against it inparser.js
in react-docgen-typescript i can get props being generated.edit again:
it was picking up my built type defs! ignoring them fixes the problem. ended up using the regex
/([^d]\.tsx?)$/
@JackCuthbert Your problem is similar.
/\/[A-Z]\w*\.(js|jsx|ts|tsx)
(#779), you will need to define filterComponents in yourdoczrc.js
, eg:tsconfig.json
required.I think I found the source of the problem (at least in my case).
TLDR; Always use direct import for all documented components.
Theory
The Props component uses
__filemeta.filename
property of a passed component (source) to get component’s prop types.The list of all components’ info (I guess that it gets resolved by findAllExportedComponentDefinitions from react-docgen) is in
stateProps
variable (source). Every item has a path to the component file, e.g.:And everything goes normal when we import a component directly:
And crashes when we do it through an
index.js
file:That’s because in the second case we have
__filemeta.filename
equal tocomponents/Button/index.js
. ThestateProps
doesn’t have an item with the corresponding key, so component’s info is never found.Why it doesn’t work as expected even when I import component directly in my .mdx
Even when I import
ComponentA
in my.mdx
like this:it may not work because it has already been imported in another component through
index.js
:So the workaround I found is to always use direct import for all my documented components. It doesn’t look pretty, but at least it works.
I think that this issue is related to the way react-docgen resolves components. @pedronauck can you provide an idea how it may be possible to import components through
index.js
files? It was possible in 0.13.7, so maybe it has something to do with react-docgen config.UPD: @cupofjoakim I have the same problem. Props doesn’t display in production build, even if I apply the mentioned workaround. For me, docz became so unstable after migration from 0.13.7. Thinking about migration to styleguidist
@yyynnn, my assumption was confirmed. With modifyBabelRc you rewrite original docz config, that disabled
babel-plugin-export-metadata
plugin. There is several ways:babel-plugin-export-metadata
plugin. Then for each documented component you need to setdisplayName
prop, that must equal component name.plugins: [...babelrc.plugins, '@babel/plugin-syntax-dynamic-import']
.modifyBabelRc
in doczrc.js. I seebabel.config.js
, will be added to the docz config.From what I understand, the regex can be simplified to:
I’ve been 👀 -ing this issue as well. I had hoped #836 and the
v1.1.0
release would fix this issue, but it did not for me. I have a branch w/ Netlify preview that’s upgraded to the latest packages where you can see the issue persists:https://github.com/OHIF/react-viewerbase/pull/68
Thanks for your PR’s on this @ejuo. Hoping #849 does the trick ^_^
Just updated to 1.1.0, looks like this includes a PR that attempted to resolve this issue. I’m still not getting any props to render 😦 TS enabled, direct imports, no HOC, the works.
😞
I’ve experienced some version of this problem throughout all the beta releases of Docz w/ Typescript; sad that it continues to be problematic in
v1.0.x
.Environment:
v1.0.2
docz.js
Button/index.mdx
Button/index.tsx
⚠️ Props fail to render
🙏 Prayers out to @pedronauck. Perhaps the typescript example needs to be more robust? Solutions suggested by the community seem to always check:
index.tsx
orComponentName.tsx
?@evosch, for what it’s worth, my dev machine is Windows, and the CI that deploys our production docs is Linux. Both output a
docz
site that does not render props.@mlshv I think your problem is related to https://github.com/pedronauck/docz/pull/779 . Try to change filterComponents. Does it help?
Now that I have PropTypes rendering using the happy path, I’m still finding one use case that I can not get to render.
When leveraging
import { withStyles } from '@material-ui/core/styles';
, it exports this way:export default withStyles(styles)(Component);
. https://material-ui.com/customization/css-in-js/#withstyles-styles-options-higher-order-componentIs there a way to use my
index.js
file in the folder to export it in a way that Props will render? My attempts haven’t been fruitful just yet.Workaround:
It’s not elegant, but this appears to work:
Update for v1.0.0:
This workaround no longer functions and have to maintain using rc.8 for now.
Update for v1.0.4:
The workaround appears to function again and does not appear to function with basic default exports.
@mlshv +1 for the table. Might be a good idea for
docz-theme-default
to presentProps
component as table, like the one in v0.x. But maybe that’s how it’ll be in the final v1 release?I have my components:
exported like this:
And when I import Button in .mdx,
<Props />
doesn’t render:However, if I import Button directly from the Button.js file, it works:
Though it seems like a workaround for this particular case, I still have the same error for some (more complex) components. I haven’t found the reason yet, but these components worked great with good old PropsTable (I really miss it btw)
hi,i check my code lastnight.And find something here.I’m wishing to be helpful. There is my folders structure: 📂 src ↳ 📂 components (documentation with MDX files) ↳ 📂 button
TypeScript solution:
tsconfig.json
configured properlydoczrc.js
Remove your
.docz
before testing itAny news on a bugfix?
Also encountering the same issue with typescript. Logging everything inside the src Props component:
I see that the filename is not matching up, but I’m not sure how to set up the
doczrc.js
for it to work. Currently using:(I should note I’m using
v1.2.0
)Has anyone tested in the linux environment? I have the same problem. Version 1.2.0.
Edit: worked with madou solution
/([^d]\.tsx?)$/
Why not accept both (first letter lower and first letter upper case)? Why it’s filtered by default?
Not fixed in 1.1.0. In
dev
mode, most of can fix with edit the component file(such as addReact.memo
, save then props appears, after that even go back the file, the props still exist), but inbuild
mode it doesn’t work.Not fixed in 1.1.0 for me. Just touching the file on dev build the props appears, but when building again for production, it doesn’t.
@dannyrb, I checked your library with the fix (#849)
notUseSpecifiers: true
. It’s working. I also noticed that not all components are named for the pattern/\/[A-Z]\w*\.(js|jsx|ts|tsx)
(#779), you will need to definefilterComponents
in yourdoczrc.js
.@Hilaker your solution didn’t work for me.
Had a similar issue, what worked for me was adding react-docgen version 4.1.0 to my project.
None of the above config combinations help to render Props component at 1.0.4. Not windows nor macos
I’m seeing this same behaviour. Starting without a
.docz
cache the props are not showing. After formatting the file in VS Code (which doesn’t register any changes in git…) the module reloads with props in place.Is there maybe a difference in how the docs are built when starting the dev-server and when rebuilding a single module?
1.0.0-rc.8
dev
v1.0.x
dev
orprod
buildsIt may be worth nothing that each
.mdx
imports the component it describes from anindex.js
file in the components folder:import { Button } from './../index.js'
. Switching a few files toimport { Button } from './../Button.js'
does not produce different results.UPDATE:
Well. This is interesting. I applied some pretty mundane
prettier
autoformatting, and all of my props are showing again. I’m not 100% sure I know what resolved the issue, but going file by file and applying caused my props to start showing again.This is the commit, for the curious: https://github.com/OHIF/react-viewerbase/pull/66/commits/c0b0ed230639ce13c69e1003b74a9cb76529a948
It could be a change from
CRLF
line endings toLF
line endingsUPDATE 2:
While the above commit allowed docs to render while I was developing locally, the production build did not render docs. Stopping and restarting the dev build locally removes docs until I modify and save a file. Prop docs are then shown again.
Currently at v1.0.0, Props works perfectly for us in dev, but when we build production Props deosn’t render anything From what I can tell in this thread most of you have this issue in dev as well, so maybe it’s a separate issue
Finally figured it out! It was an odd combination of removing the peer dependencies that I thought I had to add to make docz/yarn happy, including react, react-dom. I tried to get my package.json to look as close to this file here: https://github.com/ivan-dalmet/docz-issue-sandbox/tree/master/issue-777
Props components also not working when I set typescript as
true
in doczrc.js config file.@rfoel I just reproduced the bug (this time I hope without typo ^^)
The
<Props of={Component} />
is not working if we import the React component through another file. Example https://github.com/ivan-dalmet/docz-issue-sandbox/tree/master/issue-777