-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
React: Fix several CSF factory bugs #33354
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
Conversation
|
View your CI Pipeline Execution ↗ for commit 02804b5
☁️ Nx Cloud last updated this comment at |
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.
Pull request overview
This PR fixes several CSF (Component Story Format) factory bugs related to type inference and story processing. The changes address three issues: incorrect handling of non-story exports in factory-based CSF files, type inference problems with meta args, and missing access to meta.input.play.
Key changes:
- Fixed CSF file processing to correctly identify story exports instead of assuming the first export is a story
- Improved TypeScript type inference for React meta factory args
- Added new overload to support calling
meta.story()without arguments when all required args are provided in meta
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| code/renderers/react/src/preview.tsx | Improved TypeScript types for ReactPreview meta return type, changed story method signatures from optional to required parameters, and added new overload for parameterless story() calls |
| code/renderers/react/src/csf-factories.test.tsx | Updated test to use meta.story() instead of meta.story({}) to match new API, and added test verifying meta.input.play accessibility |
| code/core/src/preview-api/modules/store/csf/processCSFFile.ts | Fixed bug where first export was assumed to be a story by using find() to locate actual story exports, and added defensive check to ensure exports are Story objects in factory mode |
| const factoryStory = Object.values(namedExports).find((it) => isStory<TRenderer>(it)); | ||
| if (factoryStory) { |
Copilot
AI
Dec 13, 2025
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.
The change from Object.values(namedExports)[0] to Object.values(namedExports).find((it) => isStory<TRenderer>(it)) is a bug fix that ensures the code finds an actual story export rather than assuming the first export is a story. However, there appears to be no test coverage for this scenario in processCSFFile.test.ts. Consider adding a test case where the first named export is not a story (e.g., a helper function or constant) to verify this fix works correctly.
|
|
||
| Object.keys(namedExports).forEach((key) => { | ||
| if (isExportStory(key, meta)) { | ||
| if (isExportStory(key, meta) && isStory<TRenderer>(namedExports[key])) { |
Copilot
AI
Dec 13, 2025
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.
The additional isStory check on line 61 ensures that only actual Story objects (created by meta.story()) are processed in factory-based CSF files, not just any export that passes the isExportStory filter. This is a defensive check that prevents processing non-Story exports as stories. Consider adding test coverage for a scenario where a factory-based CSF file has a named export that passes isExportStory but is not a Story object (e.g., a helper function with a name that looks like a story name).
| }); | ||
| // @ts-expect-error disabled not provided ❌ | ||
| const Basic = meta.story({}); | ||
| const Basic = meta.story(); |
Copilot
AI
Dec 13, 2025
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.
Unused variable Basic.
| const Basic = meta.story(); | |
| meta.story(); |
| }, | ||
| }); | ||
|
|
||
| const ExtendedInteractionsStory = meta.story({ |
Copilot
AI
Dec 13, 2025
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.
Unused variable ExtendedInteractionsStory.
| const ExtendedInteractionsStory = meta.story({ | |
| meta.story({ |
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughSelects the first exported story that satisfies Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (5)**/*.{js,jsx,json,html,ts,tsx,mjs}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
code/**/*.{ts,tsx,js,jsx,mjs}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
code/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
code/**/*.{js,jsx,json,html,ts,tsx,mjs}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧠 Learnings (4)📓 Common learnings📚 Learning: 2025-11-05T09:37:25.920ZApplied to files:
📚 Learning: 2025-09-24T09:39:39.233ZApplied to files:
📚 Learning: 2025-11-05T09:38:47.712ZApplied to files:
🧬 Code graph analysis (1)code/renderers/react/src/preview.tsx (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (4)
Comment |
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
| >; | ||
| }, | ||
| { args: Partial<TArgs> extends TMetaArgs ? {} : TMetaArgs } | ||
| Omit< |
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.
Can you add a comment explaining what's going on?
| /** @ts-expect-error hard */ | ||
| ): ReactStory<T, TInput>; | ||
|
|
||
| story( |
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.
Can you add a comment here to explain what's going on?
Closes #32620, Closes #32831, Closes #33024
What I did
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake 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/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>Summary by CodeRabbit
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.