Skip to content

Core: Extract React CSF tools into Core - #35766

Merged
huang-julien merged 12 commits into
nextfrom
julien/story-docs-1-csf-shape-utils
Aug 7, 2026
Merged

huang-julien merged 12 commits into
nextfrom
julien/story-docs-1-csf-shape-utils

Conversation

@huang-julien

Copy link
Copy Markdown
Contributor

What I did

This PR moves the CSF-interpretation helpers used by React's component manifest ( for story snippet generation) into a new csf-tools/story-shape module in core, so other frameworks can reuse them instead of re-implementing the same AST logic.

  • normalizeStoryDeclaration: resolves a story export across CSF versions (CSF2 Template.bind({}), CSF3 objects, satisfies/as, CSF4 factories) into a classified result: { type: 'config' | 'fn' | 'emptyConfig', path }
  • args helpers: extract and merge meta/story args records with CSF precedence
  • collectImportBindings: map local identifiers to their import sources (skipping type-only imports)
  • extractStoryJSDocInfo :story description/summary from JSDoc tag

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

Manual testing


Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • 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-storybook/src/sandbox-templates.ts

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

  • 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 publish.yml --field pr=<PR_NUMBER>

@huang-julien
huang-julien requested review from a team and valentinpalkovic August 5, 2026 11:40
@huang-julien huang-julien added react ci:normal Run our default set of CI jobs (choose this for most PRs). refactoring qa:skip Pull Requests that do not need any QA. (e.g. documentation) labels Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e46d13e-2b7d-4adc-a5b2-ea299cb082f6

📥 Commits

Reviewing files that changed from the base of the PR and between 295d826 and b3f8b20.

📒 Files selected for processing (5)
  • code/core/src/csf-tools/story-shape/args.test.ts
  • code/core/src/csf-tools/story-shape/imports.test.ts
  • code/core/src/csf-tools/story-shape/jsdoc.test.ts
  • code/core/src/csf-tools/story-shape/normalize-story.test.ts
  • code/core/src/csf-tools/story-shape/utils.test.ts

Walkthrough

Changes

CSF story-shape tooling

Layer / File(s) Summary
Shared AST utilities
code/core/src/csf-tools/story-shape/*, code/core/src/csf-tools/index.ts
Adds shared utilities for CSF arguments, runtime imports, JSDoc metadata, object keys, identifier initializers, and metadata paths. Adds Vitest coverage.
Story declaration normalization
code/core/src/csf-tools/story-shape/normalize-story.ts, code/core/src/csf-tools/story-shape/normalize-story.test.ts
Normalizes object stories, function stories, bound templates, factory calls, and TypeScript-wrapped declarations.
Component manifest integration
code/renderers/react/src/componentManifest/*
Uses the shared utilities for story normalization, argument merging, import collection, and JSDoc extraction. Removes duplicate local implementations.

Sequence Diagram(s)

sequenceDiagram
  participant ComponentManifest
  participant normalizeStoryDeclaration
  participant metaObjectPath
  participant collectImportBindings
  ComponentManifest->>normalizeStoryDeclaration: normalize story declaration
  ComponentManifest->>metaObjectPath: resolve CSF metadata object
  ComponentManifest->>collectImportBindings: collect runtime import bindings
  normalizeStoryDeclaration-->>ComponentManifest: return story shape
  metaObjectPath-->>ComponentManifest: return metadata path
  collectImportBindings-->>ComponentManifest: return import map
Loading

Possibly related PRs

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@code/core/src/csf-tools/story-shape/utils.ts`:
- Around line 6-7: Update keyOf to return null when the ObjectProperty key is
computed, including computed identifier keys such as {[render]: value}; only
return identifier names for non-computed keys. Preserve the existing support for
non-computed string literal keys such as {"render": value}.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 90be1f34-b097-4652-aab7-237e280d2641

📥 Commits

Reviewing files that changed from the base of the PR and between 086c98e and 6e44c3c.

📒 Files selected for processing (10)
  • code/core/src/csf-tools/index.ts
  • code/core/src/csf-tools/story-shape/args.ts
  • code/core/src/csf-tools/story-shape/imports.ts
  • code/core/src/csf-tools/story-shape/index.ts
  • code/core/src/csf-tools/story-shape/jsdoc.ts
  • code/core/src/csf-tools/story-shape/normalize-story.ts
  • code/core/src/csf-tools/story-shape/utils.ts
  • code/renderers/react/src/componentManifest/generateCodeSnippet.ts
  • code/renderers/react/src/componentManifest/getComponentImports.ts
  • code/renderers/react/src/componentManifest/resolveComponents.ts

Comment thread code/core/src/csf-tools/story-shape/utils.ts Outdated
@huang-julien huang-julien added the cleanup Minor cleanup style change that won't show up in release changelog label Aug 5, 2026
@huang-julien
huang-julien marked this pull request as draft August 5, 2026 12:00
@huang-julien
huang-julien marked this pull request as ready for review August 5, 2026 13:01
Comment thread code/core/src/csf-tools/index.ts
@valentinpalkovic

Copy link
Copy Markdown
Contributor

I think some of the helpers deserve some unit tests :)

@huang-julien huang-julien added ci:normal Run our default set of CI jobs (choose this for most PRs). and removed ci:normal Run our default set of CI jobs (choose this for most PRs). labels Aug 5, 2026
@huang-julien
huang-julien enabled auto-merge August 6, 2026 07:59
@storybook-app-bot

storybook-app-bot Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Package Benchmarks

Commit: b4323fb, ran on 6 August 2026 at 13:35:16 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 73 73 0
Self size 21.45 MB 21.46 MB 🚨 +11 KB 🚨
Dependency size 31.21 MB 31.21 MB 0 B
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 205 205 0
Self size 831 KB 831 KB 🎉 -84 B 🎉
Dependency size 86.14 MB 86.15 MB 🚨 +11 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 198 198 0
Self size 32 KB 32 KB 0 B
Dependency size 84.62 MB 84.63 MB 🚨 +11 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 74 74 0
Self size 1.09 MB 1.09 MB 0 B
Dependency size 52.66 MB 52.67 MB 🚨 +11 KB 🚨
Bundle Size Analyzer node node

@huang-julien
huang-julien disabled auto-merge August 6, 2026 12:56
@huang-julien
huang-julien enabled auto-merge August 6, 2026 12:57
@huang-julien
huang-julien disabled auto-merge August 7, 2026 08:27
@huang-julien
huang-julien merged commit b3263a1 into next Aug 7, 2026
132 of 141 checks passed
@huang-julien
huang-julien deleted the julien/story-docs-1-csf-shape-utils branch August 7, 2026 08:27
@github-actions github-actions Bot mentioned this pull request Aug 7, 2026
2 tasks done
@ndelangen

Copy link
Copy Markdown
Member

@huang-julien This broke windows, I fixed it here:
#35800

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal Run our default set of CI jobs (choose this for most PRs). cleanup Minor cleanup style change that won't show up in release changelog qa:skip Pull Requests that do not need any QA. (e.g. documentation) react refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants