-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
React: Switch react-docgen-typescript-loader to react-docgen-typescript-plugin #11106
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks amazing, I can't wait to kick the tires.
This is is a pretty big change so expect some back and forth before we get it merged. First question: what about these:
cc @mrmckeb |
Both of those options will be respected. https://www.npmjs.com/package/react-docgen-typescript-plugin The only thing I changed with the options for the plugin are
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions @hipstersmoothie, but looks good overall.
I can add this in if everyone wants it, but it seems way simpler to me to just point at a tsconfig in the repo.
You mean you would look for a root config?
@@ -43,8 +43,7 @@ export const convert = (type: PTType): SBType | any => { | |||
case 'elementType': | |||
default: { | |||
if (name?.indexOf('|') > 0) { | |||
// react-docgen-typescript-loader doesn't always produce proper | |||
// enum types, possibly due to https://github.com/strothj/react-docgen-typescript-loader/issues/81 | |||
// react-docgen-typescript-plugin doesn't always produce proper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to have only been partially removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment relates to the issue @shilman commented on. Will try to resolve this in the underlying library and remove this comment entirely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, but one line was removed and now it doesn't make sense, right?
// react-docgen-typescript-plugin doesn't always produce proper
// this hack tries to parse out values from the string and should be
// removed when RDTL gets a little smarter about this
@@ -27,24 +30,13 @@ export function babel(config: TransformOptions, { typescriptOptions }: Storybook | |||
|
|||
export function webpackFinal(config: Configuration, { typescriptOptions }: StorybookOptions) { | |||
const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions; | |||
if (reactDocgen !== 'react-docgen-typescript') return config; | |||
|
|||
if (reactDocgen !== 'react-docgen-typescript') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer the new code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change it back but one line if statement throw me for a loop. the function above this one also had this style of if statement. Can change back if wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more pointing out that this change isn't related to any of the work. I think it's good practice to try to only change things related to the task at hand, unless something is being improved. But if you think the change is meaningful, then I'm OK with that.
@shilman when this merges, we can make this change in CRA too. |
The chromatic snapshots look pretty good. ❤️ @hipstersmoothie please take a look at the "enum"-related snapshot diffs. My enum handling code for RDTL is a hack, and it got "slightly worse" in your version. I'm not concerned about the regressions since it didn't work well in the first place. But I wanted to point it out because if you're going to do more hacking on |
Previously with |
@shilman you're talking about how You'd rather it output to be an |
@shilman Opened a PR on styleguidist/react-docgen-typescript#261 Previously the following example would output With the new option the package will now expand the above to |
I've added the |
@hipstersmoothie that was fast! and awesome!! I'll try to kick the tires on this today and hopefully merge. |
Looking fantastic!! 🔥 Here are the numbers I'm seeing for
|
@hipstersmoothie It looks like this has introduced a regression, as You can see here that we used to only target |
I actually just released an update with this functionality. 0.3.0 should only include tsx files. |
That's great news, and I'm guessing it only loads TypeScript as a dependency when |
Are you asking if I can conditionally require typescript if it’s installed? I’m assuming the loader only ever got loaded if a typescript file was found |
Yes, that was the previous behaviour. With this change, the plugin is always invoked - but we know that TypeScript may not be installed at all times. Do you conditionally require TypeScript now? If not, we may need to revert this temporarily, as it will break in any projects that don't have a |
What I did
Typescript docgen for react was super slow!
This pull request switches from
react-docgen-typescript-loader
toreact-docgen-typescript-plugin
Differences:
In my own project this resulted in a huge speed boost:
Before:
After:
How to test
If your answer is yes to any of these, please make sure to include it in your PR.