CSF: Fix false positive detection of Zod v4 .meta() as CSF Factory#33666
Conversation
|
View your CI Pipeline Execution ↗ for commit 27badf8
☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit 1c98f99 ☁️ Nx Cloud last updated this comment at |
📝 WalkthroughWalkthroughmeta() handling was narrowed: BadMetaError is now thrown only when the call’s root object is named Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
✨ Finishing touches
Comment |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 49 | 49 | 0 |
| Self size | 20.40 MB | 20.39 MB | 🎉 -10 KB 🎉 |
| Dependency size | 16.52 MB | 16.52 MB | 0 B |
| Bundle Size Analyzer | Link | Link |
@storybook/cli
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 183 | 183 | 0 |
| Self size | 776 KB | 775 KB | 🎉 -830 B 🎉 |
| Dependency size | 67.57 MB | 67.56 MB | 🎉 -10 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/codemod
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 176 | 176 | 0 |
| Self size | 30 KB | 30 KB | 🚨 +63 B 🚨 |
| Dependency size | 66.14 MB | 66.13 MB | 🎉 -10 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
create-storybook
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 50 | 50 | 0 |
| Self size | 1000 KB | 1000 KB | 🚨 +42 B 🚨 |
| Dependency size | 36.92 MB | 36.91 MB | 🎉 -10 KB 🎉 |
| Bundle Size Analyzer | node | node |
The CSF parser was incorrectly identifying Zod v4's `.meta()` method calls as Storybook's CSF Factories `meta()` function when the object calling `.meta()` was a directly imported variable. This caused the error: ``` BadMetaError: CSF: meta() factory must be imported from .storybook/preview configuration ``` The fix changes the detection logic to only throw BadMetaError when the variable calling `.meta()` is specifically named "preview". This is the canonical name used in CSF Factories (`preview.meta()`), so if someone has a variable with this name but imports it from the wrong path, they get a helpful error. For all other variable names (like `mySchema` from Zod), the `.meta()` call is silently ignored since it's clearly not attempting to use CSF Factories. Closes #33654
1c98f99 to
27badf8
Compare
CSF: Fix false positive detection of Zod v4 .meta() as CSF Factory (cherry picked from commit 32ee24e)
Closes #33654
What I did
Fixed a bug where the CSF parser incorrectly identified Zod v4's
.meta()method calls as Storybook's CSF Factoriesmeta()function. This caused aBadMetaErrorwhen using Zod schemas with.meta()in story files:Root cause: The parser was checking if any
.meta()call on an imported variable came from a valid preview path, and throwing an error if not.Fix: Changed the detection logic to only throw
BadMetaErrorwhen the variable calling.meta()is specifically namedpreview. This is the canonical name used in CSF Factories (preview.meta()), so if someone has a variable with this name but imports it from the wrong path, they get a helpful error. For all other variable names (likemySchemafrom Zod), the.meta()call is silently ignored.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
No manual testing required - the fix is fully covered by unit tests that simulate the exact Zod v4 usage patterns from the issue.
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
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.