docz icon indicating copy to clipboard operation
docz copied to clipboard

Bugs and bugs around react-docgen

Open tadeuszwojcik opened this issue 8 years ago • 30 comments

Question

How to pass custom config to react-docgen-typescript-loader ? Description Hi, First of all, I love the project, much nicer experience than with styleguidist!

I'm trying to use it with typescript, which is working fine except PropsTable which renders empty. I had similar issue when working with styleguidist, and solution for that was to pass my custom tsconfig.json to do react-docgen-typescript . Unfortunately I don't know how to do that with docz, I made changes locally inside docz code so react-docgen-typescript-loader reads my config and it works perfectly, but it's not a solution :) Is there a way to do that via modifyBundlerConfig ? Thanks!

tadeuszwojcik avatar Aug 21 '18 12:08 tadeuszwojcik

I was able to apply custom config via docrc:

modifyBundlerConfig: config => {
    const jsxPluginIndex = config.plugins.findIndex(plugin => plugin.config.id === 'jsx');
    const { loaders } = config.plugins[jsxPluginIndex].config;
    const docGenLoaderIndex = loaders.findIndex(loader => /react-docgen-typescript-loader/.test(loader.loader));
    const docGenLoader = loaders[docGenLoaderIndex];

    docGenLoader.options = {
      tsconfigPath: './tsconfig.json'
    };

    return config;
  }

That's good, but unfortunately it's only working with react-docgen-typescript-loader 3.0.0-rc.0 as v2 does not parse options correctly .

Would you consider updating react-docgen-typescript-loader to ^3.0.0-rc.0 ? I think that would solve many issues for typescript users when props table renders empty (as they need to provide their own tsconfig not use default one from react-docgen-typescript)

tadeuszwojcik avatar Aug 24 '18 08:08 tadeuszwojcik

I chose to leave only this issue since it is related to the configuration of the react docgen. The idea is don't use plugins/loaders anymore and put all process related to docgen in the DataServer, with this in mind we can solve all issue marked here and get an awesome performance boost since we don't need to parse the entire code anymore.

pedronauck avatar Sep 11 '18 04:09 pedronauck

I am also being affected by this issue when using an external library of react components (same issue as #253 @itReverie). Is there any quick solution available? :pray:

itsdanielmatos avatar Oct 04 '18 11:10 itsdanielmatos

@tadeuszwojcik Great find! By passing my own tsconfig I'm now getting the propstable rendered with the latest version of Docz as well!

@pedronauck Might be a 'simple' fix now to get this working again? Seems like the quick solutions for now would be to make an easy option to pass a custom config to React Docgen (instead of the 5 lines of ugly JS in the config), and we're good to go?

JeroenReumkens avatar Oct 13 '18 20:10 JeroenReumkens

@JeroenReumkens react-docgen-typescript-loader has released v3.0.0.

when I change

export class Button

to

class Button
export default Button

It works as described in the document

lwxyfer avatar Oct 21 '18 14:10 lwxyfer

@boostio funded this issue with $40. See it on IssueHunt

IssueHuntBot avatar Nov 06 '18 03:11 IssueHuntBot

I'm looking for this feature as well. I'm retrofitting Docz into an existing TS project (hoping to merge our old docs site and Styleguidist together) and PropsTable is showing up empty. Definitely not able to migrate yet. Hopefully soon!

mattfelten avatar Dec 12 '18 04:12 mattfelten

The solution given above seems to be broken in the latest release of Docz. @pedronauck Do you remember changing anything related to the way docgen is added to the webpack config?

JeroenReumkens avatar Dec 19 '18 13:12 JeroenReumkens

Hey guys I had the same problem with the react-docgen-typescript-loader passing all the props of react on docz because I'm using styled-components. I searched a bit and found a config for this. And because docz is extensible as f I could update the bundler config. Top @pedronauck 🚀 .

  modifyBundlerConfig: config => ({
    ...config,
    module: {
      ...config.module,
      rules: config.module.rules.map(rule => ({
        ...rule,
        use: rule.use.map(ruleUse =>
          ruleUse.loader.includes('react-docgen-typescript-loader')
            ? {
                ...ruleUse,
                options: {
                  propFilter: prop => {
                    if (prop.parent == null) return true
                    return !prop.parent.fileName.includes('node_modules')
                  },
                },
              }
            : ruleUse,
        ),
      })),
    },
  }),

guilhermedecampo avatar Dec 19 '18 16:12 guilhermedecampo

Hey guys, I put the @guilhermedecampo solution inside docz, see if is good now 🙏

pedronauck avatar Dec 19 '18 19:12 pedronauck

Hey @pedronauck You mean Docz should do this by itself now? If so, can you tell me in what version I can find the fix?

The solution given above doesn't look that easy a first glance. So if that is the way forward, I'll try to implement it in my project to see if it works. But if it does work, I'll try to make the above code a bit more simple / readable.

JeroenReumkens avatar Dec 20 '18 07:12 JeroenReumkens

@pedronauck has submitted a pull request. See it on IssueHunt

IssueHuntBot avatar Dec 21 '18 21:12 IssueHuntBot

@pedronauck has rewarded $28.00 to @pedronauck. See it on IssueHunt

  • :moneybag: Total deposit: $40.00
  • :tada: Repository reward(20%): $8.00
  • :wrench: Service fee(10%): $4.00

IssueHuntBot avatar Dec 21 '18 21:12 IssueHuntBot

In the next release (v0.14) I'll introduce a new way to parse props using react-docgen. Instead of using a babel plugin for prop-types and a loader for typescript, everything now is centralized in a process using data server:

https://github.com/pedronauck/docz/blob/v0.14/core/docz-core/src/states/props.ts

With these changes, I think that we will improve a lot the performance since all props extracting logic will not belong to webpack anymore.

I'll finish the v0.14 that will have some other improvements, then I came back here to test and close this issue 🙏

pedronauck avatar Dec 21 '18 21:12 pedronauck

@pedronauck Hi when do you think you will be releasing v0.14?

ondrejbartas avatar Jan 16 '19 13:01 ondrejbartas

Pretty sure these updates are coming in v1! https://github.com/pedronauck/docz/pull/656

New docgen parse using DataServer instead of babel plugin and loader (85499a8)

mgallagher avatar Mar 04 '19 17:03 mgallagher

Is this in v1? I just tried out v1 and Props are still not working with Styled Components.

glockjt avatar Mar 22 '19 17:03 glockjt

@glockjt Check if this line helps you.

Instead of exporting the styled-component directly, try to make a new component using the styled-component. And declare the prop types in the new component like the example.

rfoel avatar Mar 24 '19 16:03 rfoel

Can the Props component accept something besides a static prop-types object? I have a function that generates props types for my component, that I reuse across many components, and if it's not a exact prop-types object it won't render in the Props component.

rfoel avatar Mar 24 '19 16:03 rfoel

@rfoel that doesn't work either. Even if it did, this is still an issue, you shouldn't have to change the way you create your styled components just for documentation to work.

glockjt avatar Mar 25 '19 16:03 glockjt