Skip to content

Conversation

@yannbf
Copy link
Member

@yannbf yannbf commented Jan 19, 2026

Closes #

What I did

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

  • 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 pull request has been released as version 0.0.0-pr-33589-sha-f53c2069. Try it out in a new sandbox by running npx storybook@0.0.0-pr-33589-sha-f53c2069 sandbox or in an existing project with npx storybook@0.0.0-pr-33589-sha-f53c2069 upgrade.

More information
Published version 0.0.0-pr-33589-sha-f53c2069
Triggered by @yannbf
Repository storybookjs/storybook
Branch yann/story-creation-docgen-ts-part-2
Commit f53c2069
Datetime Tue Jan 20 13:49:06 UTC 2026 (1768916946)
Workflow run 21173875115

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=33589

Summary by CodeRabbit

  • New Features

    • Docgen now reads and applies TypeScript project configuration for more accurate type extraction.
    • New helper to load component docgen data and select a target component.
  • Refactor

    • Arg-type extraction delegated to a centralized extractor; in-file type-mapping logic removed.
    • Simplified argTypes data flow to return parsed data directly.
  • Bug Fixes

    • Improved dynamic import and parser initialization for docgen tooling.
  • Tests

    • Added tests to validate prop/arg type extraction and output shape.

✏️ Tip: You can customize this high-level summary in your review settings.

@nx-cloud
Copy link

nx-cloud bot commented Jan 19, 2026

View your CI Pipeline Execution ↗ for commit f53c206

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ✅ Succeeded 9m 25s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-20 13:56:03 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

Introduce TS config discovery for react-docgen-typescript, replace in-file docgen->argType mapping with delegation to extractArgTypes, add getComponentDocgen, and add tests validating extraction shapes.

Changes

Cohort / File(s) Summary
Parser integration & argTypes flow
code/renderers/react/src/componentManifest/reactDocgen/extractReactTypescriptDocgenInfo.ts
Use dynamic import of react-docgen-typescript and initialize parser via withCompilerOptions(tsConfig, mergedOptions) where tsConfig comes from getTsConfig; remove mapReactDocgenTypescriptToArgType; return extractArgTypes({ __docgenInfo: targetDocgen }) ?? {}.
Docgen utilities
code/renderers/react/src/componentManifest/reactDocgen/utils.ts
Add getTsConfig to dynamically import TypeScript, locate/read nearest tsconfig.json, and return parsed compilerOptions (or {} on failure).
Higher-level docgen API
code/renderers/react/src/componentManifest/reactDocgen/extractReactDocgenInfo.ts
Add getComponentDocgen(filePath, componentName?); change extractArgTypesFromDocgen to delegate to extractArgTypes({ __docgenInfo }); remove prior internal mapping helpers and related type-mapping logic.
Tests
code/renderers/react/src/componentManifest/reactDocgen/extractReactTypescriptDocgenInfo.test.ts
Add tests for extractProps / extractComponentProps verifying extraction shape for simple and complex docgen inputs (snapshot-based).
Preset adjustment
code/renderers/react/src/preset.ts
Simplify internal_getArgTypesData to return argTypesData unchanged (remove construction of ArgTypes map from argTypesData.props).
Dummy args handling
code/core/src/core-server/utils/get-dummy-args-from-argtypes.ts, .../get-dummy-args-from-argtypes.test.ts
Change default handling for SBType other to return null (tests updated accordingly).

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant getTsConfig as getTsConfig (read tsconfig)
  participant RDTS as react-docgen-typescript
  participant Extract as extractArgTypes

  Caller->>getTsConfig: request TS compilerOptions
  getTsConfig-->>Caller: tsConfig (or {})
  Caller->>RDTS: dynamic import + withCompilerOptions(tsConfig, options)
  RDTS-->>Caller: parser instance
  Caller->>RDTS: parser.parse(filePath) -> docgen results
  RDTS-->>Caller: docgen results (__docgenInfo)
  Caller->>Extract: extractArgTypes({ __docgenInfo })
  Extract-->>Caller: argTypes result (or {})
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

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

@storybook-app-bot
Copy link

storybook-app-bot bot commented Jan 19, 2026

Package Benchmarks

Commit: f53c206, ran on 20 January 2026 at 13:54:31 UTC

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

storybook

Before After Difference
Dependency count 49 49 0
Self size 20.30 MB 20.32 MB 🚨 +21 KB 🚨
Dependency size 16.52 MB 16.52 MB 🎉 -4 B 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 538 538 0
Self size 646 KB 646 KB 🎉 -130 B 🎉
Dependency size 59.22 MB 59.73 MB 🚨 +503 KB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 127 127 0
Self size 1.12 MB 1.12 MB 🚨 +14 B 🚨
Dependency size 21.82 MB 22.32 MB 🚨 +494 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 159 159 0
Self size 30 KB 30 KB 🚨 +8 B 🚨
Dependency size 23.00 MB 23.61 MB 🚨 +609 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 117 117 0
Self size 35 KB 35 KB 🎉 -8 B 🎉
Dependency size 19.62 MB 20.11 MB 🚨 +494 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 278 278 0
Self size 24 KB 24 KB 🚨 +2 B 🚨
Dependency size 44.13 MB 44.64 MB 🚨 +503 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 183 183 0
Self size 775 KB 775 KB 🚨 +219 B 🚨
Dependency size 67.38 MB 67.47 MB 🚨 +90 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 176 176 0
Self size 30 KB 30 KB 🎉 -4 B 🎉
Dependency size 65.95 MB 66.04 MB 🚨 +91 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 50 50 0
Self size 1000 KB 999 KB 🎉 -48 B 🎉
Dependency size 36.82 MB 36.84 MB 🚨 +21 KB 🚨
Bundle Size Analyzer node node

@storybook/react

Before After Difference
Dependency count 57 57 0
Self size 732 KB 1.23 MB 🚨 +494 KB 🚨
Dependency size 12.94 MB 12.94 MB 🚨 +403 B 🚨
Bundle Size Analyzer Link Link
@yannbf yannbf force-pushed the yann/story-creation-docgen-ts-part-2 branch from 61e987b to 6c23861 Compare January 20, 2026 11:07
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In
`@code/renderers/react/src/componentManifest/reactDocgen/extractReactTypescriptDocgenInfo.test.ts`:
- Line 7: Replace the non-actionable personal TODO comment in
extractReactTypescriptDocgenInfo.test.ts with a clear, actionable note or an
issue reference: remove "TODO: Norbert figure this out thank you" and either add
a short task describing what's missing (e.g., "TODO: implement X behavior for Y
edge case" or "TODO: update test to cover Z scenario") or replace it with a link
to the tracking issue (e.g., "See issue `#1234`") so future contributors know what
to do and where to follow up.

In `@code/renderers/react/src/componentManifest/reactDocgen/utils.ts`:
- Around line 129-134: In getTsConfig, remove the direct console.log({
tsconfigPath }) to avoid leaking paths at runtime; instead either drop the log
entirely or replace it with the project's logger (use the existing logger
instance/function if available) so the function (getTsConfig) no longer uses
console directly and logs via the repo's logging utilities with appropriate
context.

import { extractProps } from '../../extractProps';

// TODO: Norbert figure this out thank you
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Replace the TODO with an actionable note or issue reference.

The current TODO isn’t actionable and includes a personal note. Please remove it or replace it with a clear task and an issue link.

🤖 Prompt for AI Agents
In
`@code/renderers/react/src/componentManifest/reactDocgen/extractReactTypescriptDocgenInfo.test.ts`
at line 7, Replace the non-actionable personal TODO comment in
extractReactTypescriptDocgenInfo.test.ts with a clear, actionable note or an
issue reference: remove "TODO: Norbert figure this out thank you" and either add
a short task describing what's missing (e.g., "TODO: implement X behavior for Y
edge case" or "TODO: update test to cover Z scenario") or replace it with a link
to the tracking issue (e.g., "See issue `#1234`") so future contributors know what
to do and where to follow up.
Comment on lines +129 to +134
export const getTsConfig = async () => {
try {
const ts = await import('typescript');
const tsconfigPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
console.log({ tsconfigPath });
if (tsconfigPath === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove direct console logging in runtime utility.

console.log here will leak paths and violates the repo logging guideline. Please remove it or replace with the project logger (if needed). As per coding guidelines, avoid direct console usage.

🔧 Suggested change
-    console.log({ tsconfigPath });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getTsConfig = async () => {
try {
const ts = await import('typescript');
const tsconfigPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
console.log({ tsconfigPath });
if (tsconfigPath === undefined) {
export const getTsConfig = async () => {
try {
const ts = await import('typescript');
const tsconfigPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists);
if (tsconfigPath === undefined) {
🤖 Prompt for AI Agents
In `@code/renderers/react/src/componentManifest/reactDocgen/utils.ts` around lines
129 - 134, In getTsConfig, remove the direct console.log({ tsconfigPath }) to
avoid leaking paths at runtime; instead either drop the log entirely or replace
it with the project's logger (use the existing logger instance/function if
available) so the function (getTsConfig) no longer uses console directly and
logs via the repo's logging utilities with appropriate context.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
code/renderers/react/src/componentManifest/reactDocgen/extractReactDocgenInfo.ts (1)

67-78: Pass raw docgen data to extractArgTypes, not the wrapper object.

Line 77 passes docgen.reactDocgen (a { type: 'success', data } wrapper) to extractArgTypes, but it expects raw docgen data. This is inconsistent with extractReactTypescriptDocgenInfo.ts:71, which correctly passes the raw data directly. The wrapper prevents extractComponentProps from accessing the props field, resulting in empty ArgTypes.

-  return extractArgTypes({ __docgenInfo: docgen.reactDocgen }) ?? {};
+  return extractArgTypes({ __docgenInfo: docgen.reactDocgen.data }) ?? {};
🤖 Fix all issues with AI agents
In
`@code/renderers/react/src/componentManifest/reactDocgen/extractReactTypescriptDocgenInfo.ts`:
- Around line 43-51: The getTsConfig() helper currently emits console.log output
which causes noisy console output when extractReactTypescriptDocgenInfo (which
calls getTsConfig) runs; update the logging inside getTsConfig (in the
reactDocgen utils) to use the project logger (e.g., processLogger or the
existing logger used across renderers) or remove the console.log entirely so no
console output is produced when extractReactTypescriptDocgenInfo calls
getTsConfig; ensure the replacement preserves the original message/context and
uses the same logging level convention as other renderer utilities.
Comment on lines 43 to 51
const tsConfig = await getTsConfig();

const mergedOptions = {
...defaultOptions,
...reactDocgenTypescriptOptions,
// Always ensure savePropValueAsString is true for consistency
savePropValueAsString: true,
};

const parser = withCompilerOptions(
{ esModuleInterop: true, jsx: 2 /* React */ },
mergedOptions
);

const parser = withCompilerOptions(tsConfig, mergedOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Avoid console output from getTsConfig path.

getTsConfig() currently logs via console.log (code/renderers/react/src/componentManifest/reactDocgen/utils.ts:128-146). Calling it here will now emit console output during docgen runs. Please switch that log to the appropriate logger or remove it.

🔧 Suggested fix in utils.ts
+import { logger } from 'storybook/internal/node-logger';
 ...
-    console.log({ tsconfigPath });
+    logger.debug({ tsconfigPath });
As per coding guidelines, avoid `console.log` in renderers code.
🤖 Prompt for AI Agents
In
`@code/renderers/react/src/componentManifest/reactDocgen/extractReactTypescriptDocgenInfo.ts`
around lines 43 - 51, The getTsConfig() helper currently emits console.log
output which causes noisy console output when extractReactTypescriptDocgenInfo
(which calls getTsConfig) runs; update the logging inside getTsConfig (in the
reactDocgen utils) to use the project logger (e.g., processLogger or the
existing logger used across renderers) or remove the console.log entirely so no
console output is produced when extractReactTypescriptDocgenInfo calls
getTsConfig; ensure the replacement preserves the original message/context and
uses the same logging level convention as other renderer utilities.
@ndelangen
Copy link
Member

releasing a canary now

@ndelangen ndelangen merged commit a2ed88e into next Jan 20, 2026
125 checks passed
@ndelangen ndelangen deleted the yann/story-creation-docgen-ts-part-2 branch January 20, 2026 14:00
@github-actions github-actions bot mentioned this pull request Jan 20, 2026
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants