Repository navigation
Svelte: Support meta.type<>() in Svelte CSF files - #36693
Conversation
…F files
A Svelte CSF file can destructure more `Story` components from
`meta.type<…>()`, to add args that the component doesn't declare:
const { Story: IconStory } = meta.type<{ args: { icon: string } }>();
The parser, the compiler and the indexer now track the names of all `Story`
components, also through chains of `.type()` calls, so a file can mix `Story`
and `IconStory`. `meta.type()` returns the same meta at runtime, so the
compiled stories still call `meta.story()`. The types already supported it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cases that show what the previous commit does: - Compiler: the full compiled module for `preview.type<>().meta()`, and for a file that mixes `Story` and `IconStory` (`compiler/post-transform/index.test.ts`). - Vitest transform: a test for each story of `Story` and `IconStory` (`compiler/vitest-transform.test.ts`). - Indexer and parsers: the index entries and the `Story` names of a mixed file. - Runtime: `meta-type.stories.svelte` renders and runs both kinds of stories. - Types: `type-checks-meta-type.svelte` has the `meta.type<>()` cases of the CSF4 tests as `Story` components, checked by `svelte-check`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@coderabbitai review |
|
@codex review |
✅ Action performedReview finished.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (14)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. WalkthroughThe Svelte CSF parser and indexer now support multiple story component names, including names declared through ChangesSvelte CSF meta.type support
Possibly related PRs
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The supported mixed-declaration form retains both stories. No actionable merge-blocking issue remains in the reviewed changes. ✨ Finishing Touches 💡 1📝 Generate docstrings
🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b707ad855b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
3ff3eeb
into
jeppe/sb-2212-svelte-csf-accept-previewmeta-and-compile-to-csf4-factories
Closes #
What I did
A Svelte CSF file can now destructure more
Storycomponents frommeta.type<…>(), to add args that the component doesn't declare. A file can mix them with the plainStory. Linear: SB-2214. This PR is stacked on #36691.Before and after
The same stories file, compiled before this PR (the tip of #36691) and with this PR. This is the real output of the Svelte compiler (production mode) followed by the Svelte CSF transform, from the meta down. I replaced the compiled Svelte component with a comment.
Source (
Button.stories.svelte):Before:
<IconStory>renders at runtime, but the compiler and the indexer don't know it, so theIconstory is dropped without an error:After:
meta.type()returns the same meta at runtime, so the stories still callmeta.story(), and core'sCsfFileneeds no change.How to review
feat(svelte): find the Story components of meta.type<>() in Svelte CSF files. You can skim this one. The parser, the compiler and the indexer now track a list ofStorynames in place of oneStoryidentifier.skipTypeCallsinutils/import-source.tsfollows chains of.type()calls, for bothmeta.type<…>()andpreview.type<…>().meta().test: the test cases for meta.type<>() in Svelte CSF files. Review this one. It has the compiler, Vitest-transform and indexer snapshots of a file that mixesStoryandIconStory, a runtime stories file, and the type fixtures.Choices to review:
SvelteMeta.type<S>()from Svelte: Add CSF factories with definePreview #36669 already returns a meta whoseStoryhas the args ofS, with the coreTypedMetaArgKeysrule.type-checks-meta-type.svelteports themeta.type<>()cases of the CSF4 type tests toStorycomponents, andsvelte-checkpasses.const { Story: IconStory } = meta.type<…>(), chains such asmeta.type<A>().type<B>(), and more than one declarator in aconst. Not supported: a typed meta in its own variable (const typed = meta.type<…>(); const { Story: X } = typed;), andpreview.meta(…).type<…>()directly in the meta declaration. The issue doesn't list them.preview.type<…>().meta()was already found in Svelte: Accept preview.meta() in Svelte CSF files #36691. This PR adds its full compiler snapshot.templatesnippet must set every required arg of the component, also a requiredchildren. This holds forStoryandIconStoryalike.Evidence
StoryandIconStory. The Vitest transform makes a test for each story.meta-type.stories.svelteruns both stories withStory.run(), and a test checks that both are exported.type-checks-meta-type.sveltecovers a required extra arg, a meta arg thattype<>()declares again, optional args, the inferredtemplateandplayargs,Args<typeof IconStory>, and the composition withpreview.type<>(), decorators and a chainedtype<>()..stories.sveltefiles in the repo compile byte-identically and give the same index entries before and after this PR. All 6 orders of threeStorycomponents give matching index entries, export order, exports and Vitest tests. The hunt found that aStorycomponent in the second declarator of aconstwas dropped, and this PR fixes that.svelte-kit/skeleton-ts, withdefinePreview): anIconStoryin a factory.stories.sveltefile is in the index, renders, and passes its play function in the UI and in addon-vitest (Chromium).Merge Danger
Door: two-way. The change adds support for more
Storycomponents. Files withoutmeta.type<>()compile as before.Blast Radius: small. Only the Svelte CSF parser, compiler and indexer change, and the hunt shows byte-identical output for every existing
.stories.sveltefile in the repo.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!
Set up the sandbox from the manual testing steps of Svelte: Accept preview.meta() in Svelte CSF files #36691.
In
src/factories/Button.stories.svelte, changeconst { Story } = preview.meta(…)toconst meta = preview.meta(…)andconst { Story } = meta;. Then add:Run
yarn storybook. Check that the sidebar has the "Icon" story, and that its Controls panel shows theiconarg with the value ★.Run
yarn vitest --run --project storybook. The Icon story passes.Remove
iconfrom the args and runyarn check.svelte-checkreports thaticonis missing.Documentation
MIGRATION.MD
The docs for Svelte factories come with SB-2215.
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.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake 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 - 🚫 Not run
This PR does not have a canary release associated.
In-repo PRs: add the
ci:canarylabel. Later pushes republish while the label remains.Fork PRs: the label does nothing (a later push must not auto-publish). A maintainer publishes from this repository with Run workflow and the
prinput.branchandshaare optional; if more than one is set, they must be the same commit. The fork author does not need to do anything.🤖 Generated with Claude Code