-
-
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
Docgen: Only add react-docgen info when a component is defined in the file #26967
Docgen: Only add react-docgen info when a component is defined in the file #26967
Conversation
This avoids errors when a component is being imported and re-exported under a different name via a barrel file or similar.
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d80070b. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
|
Currently, we have a feature freeze. As soon as Storybook 8.1 is published next week, we will unfreeze next and we will be able to merge this PR. |
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.
LGTM!
@glenjamin Thank you so much for your contribution. Amazing work. I've added another commit to actually also apply your changes to the react-vite framework.
Thanks! will this be backported to v7, or is it v8 only? |
Separately, I would also like to see this included in the next patch release (8.1.x) if possible! This bug has been a blocker for my team upgrading to Storybook 8. And many thanks for the fix @glenjamin! This bug has been on my list to look into, but you got to it first :) |
It will not be backported to 7. it will be part of the next patch release 8.1.1 :) |
Docgen: Only add react-docgen info when a component is defined in the file (cherry picked from commit 691069c)
Docgen: Only add react-docgen info when a component is defined in the file (cherry picked from commit 691069c)
Docgen: Only add react-docgen info when a component is defined in the file (cherry picked from commit 691069c)
This avoids errors when a component is being imported and re-exported under a different name via a barrel file or similar.
Closes #26074
What I did
The issue occurs when the react-docgen plugin is attempting to add the additional metadata into a file that exports the component, but doesn't contain the definition or a local with the same name.
I couldn't see enough information in the
react-docgen
handlers to distinguish between a re-export and a definition, so I've made the extra docgen handler already defined in this loader make a note of the filename from the component definition.When modifying the AST to add the docgen info, we only assign the info if the definition file is the same as the file we're transforming. This could potentially lead to other scenarios no longer adding the docgen info, but I believe that as long as the file containing the definition is still being processed by the loader, it should only be removing redundant re-assignments.
I'm not especially precious about taking this approach to resolve the issue, so please let me know if an alternative approach is preferred and I can give that a go instead.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
While I was able to to add a story to the sandbox which reproduced the issue, I struggled to see how this is executed as part of the testing/CI process, so I'd appreciate any pointers if there's something I've missed.
Manual testing
react-webpack-18-ts
renderers/react/js-argtypes
storyDocumentation
I don't believe any documentation is required.
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>