Skip to content
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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

glenjamin
Copy link

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:

  • stories
  • unit tests
  • integration tests
  • end-to-end 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

  1. Run a sandbox for react-webpack-18-ts
  2. Open Storybook in your browser
  3. Access any renderers/react/js-argtypes story
  4. Without the fix, we see the following error:
    PropsWriter is not defined
    
    ./src/stories/renderers/react/docgen-components/js-re-exported-component/input.jsx@http://localhost:6006/stories-renderers-react-js-argtypes-stories.iframe.bundle.js:4238:1
    
  5. With this change, there is no longer an error

Documentation

I don't believe any documentation is required.

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/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>

This avoids errors when a component is being imported and re-exported under
a different name via a barrel file or similar.
@yannbf yannbf added bug ci:merged Run the CI jobs that normally run when merged. docgen labels Apr 29, 2024
@yannbf yannbf changed the title Only add react-docgen info in the file a component is defined Docgen: Only add react-docgen info when a component is defined in the file Apr 29, 2024
Copy link

nx-cloud bot commented Apr 29, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit cf562cc. 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 target

Sent with 💌 from NxCloud.

@hanshank
Copy link

hanshank commented May 10, 2024

@glenjamin @valentinpalkovic

  • Any idea if this will be merged anytime soon?

@valentinpalkovic
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:merged Run the CI jobs that normally run when merged. docgen
Projects
None yet
4 participants