CSF-Factories: Skip non-factory exports instead of throwing error#33550
Conversation
📝 WalkthroughWalkthroughCSF parsing now skips non-factory exports when a file contains factory stories instead of throwing MixedFactoryError. Tests updated to assert non-factory exports are ignored and that excludeStories continues to exclude specified factory exports. Changes
Sequence Diagram(s)(omitted — changes are internal to CSF parsing and do not introduce a multi-component sequential flow that requires diagramming) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (8)**/*.{test,spec}.{ts,tsx}📄 CodeRabbit inference engine (.cursorrules)
Files:
**/*.test.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/spy-mocking.mdc)
Files:
**/*.{js,jsx,ts,tsx,json,md,html,css,scss}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{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:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{test,spec}.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
code/{core,lib,addons,builders,frameworks,presets}/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧠 Learnings (4)📚 Learning: 2025-12-22T22:03:40.123ZApplied to files:
📚 Learning: 2025-12-22T22:03:40.123ZApplied to files:
📚 Learning: 2025-11-24T17:49:59.279ZApplied to files:
📚 Learning: 2025-09-24T09:39:39.233ZApplied to files:
🧬 Code graph analysis (1)code/core/src/csf-tools/CsfFile.test.ts (2)
🔇 Additional comments (3)
✏️ Tip: You can disable this entire section by setting Comment |
Previously, CSF factory files would throw a `MixedFactoryError` if any named export was not a factory story (e.g., `meta.story()`). This caused issues when: - Files had helper exports that were excluded via `excludeStories` - Files had utility functions or constants exported alongside stories Now, non-factory exports in factory files are simply skipped during indexing. This means: - Helper exports no longer need `excludeStories` to avoid errors - `excludeStories`/`includeStories` still work for factory stories - Only actual factory stories (`meta.story()` / `meta.extend()`) are indexed Fixes #33549 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
02dfa84 to
eb657fd
Compare
|
View your CI Pipeline Execution ↗ for commit bd64274
☁️ Nx Cloud last updated this comment at |
…ies-exclude-stories
| ) | ||
| ).toThrowErrorMatchingInlineSnapshot(` | ||
| [MixedFactoryError: CSF: expected factory story (line 4, col 17) | ||
| export const someHelper = () => {} |
There was a problem hiding this comment.
What happens if this is a CSF1 story, e.g.:
export const MyStory = () => <Component />I suspect this means the story gets lost in the void (no longer indexed)?
Probably we can't fix this without considering includeStories/excludeStories.
There was a problem hiding this comment.
In CSF4 this must be:
export const MyStory = meta.story(() => );
Closes #33549
What I did
Previously, CSF factory files would throw a
MixedFactoryErrorif any named export was not a factory story. This caused issues when files had helper exports or utility functions alongside stories.Now, non-factory exports in factory files are simply skipped during indexing. This means:
excludeStoriesto avoid errorsexcludeStories/includeStoriesstill work for factory storiesmeta.story()/meta.extend()) are indexedChecklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
yarn task --task sandbox --start-from auto --template react-vite/default-tsyarn storybookCSF: expected factory storyerrorDocumentation
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 pull request has been released as version
0.0.0-pr-33550-sha-bd642744. Try it out in a new sandbox by runningnpx storybook@0.0.0-pr-33550-sha-bd642744 sandboxor in an existing project withnpx storybook@0.0.0-pr-33550-sha-bd642744 upgrade.More information
0.0.0-pr-33550-sha-bd642744kasper/fix-csf-factories-exclude-storiesbd6427441768485197)To request a new release of this pull request, mention the
@storybookjs/coreteam.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=33550