Avoid re-emitting docgen for re-exported components #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our codebase we will often define a component in one file, then re-export it from
index.ts
. In some cases, the re-export uses a name that does not match the original component. In these cases,react-docgen-loader
emits invalid code that tries to assign docgen info to the actual name from the original component, which fails.Currently invalid code is written into
components/Button/index.ts
andcomponents/Bouton/index.ts
that tries to assign toButton.__docgenInfo
, whenButton
is not a valid identifier in either file.The
react-webpack
implementation ofreact-docgen-loader
avoids this problem by checking that the resolved component definition comes from the initial source file. See https://github.com/storybookjs/storybook/blob/e812f77def55aa7aeda70dddcc378c736412472d/code/presets/react-webpack/src/loaders/react-docgen-loader.ts#L25This PR adds the same logic here, which fixes the issue.