Skip to content

CSF-Factories: Fix ConfigFile parser false warning on definePreview({...}).type<T>() export default#33885

Merged
valentinpalkovic merged 4 commits into
nextfrom
copilot/fix-configfile-parser-warning
Mar 3, 2026
Merged

CSF-Factories: Fix ConfigFile parser false warning on definePreview({...}).type<T>() export default#33885
valentinpalkovic merged 4 commits into
nextfrom
copilot/fix-configfile-parser-warning

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 20, 2026

  • Understand the issue: ConfigFile parser warns on definePreview({...}).type<{...}>() in export default
  • Fix ExportDefaultDeclaration handler in ConfigFile.ts to unwrap chained calls like .type<T>()
  • Add test case for definePreview({...}).type<{...}>() in ConfigFile.test.ts
  • Run tests to verify the fix (126 tests pass)
  • Fix prettier formatting in ConfigFile.ts
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: ConfigFile parser warns on definePreview({...}).type<{...}>() in export default</issue_title>
<issue_description>### Describe the bug

When using .type() chaining on export default definePreview(...), the ConfigFile parser emits:

CSF Parsing error: Expected 'ObjectExpression' but found 'CallExpression' instead in 'CallExpression'.

This happens because the ExportDefaultDeclaration handler in ConfigFile.parse() only unwraps a single level of CallExpression:

// src/csf-tools/CsfFile.ts (ConfigFile class)
let decl = self._resolveDeclaration(node.declaration, parent);
t3.isCallExpression(decl) && t3.isObjectExpression(decl.arguments[0]) && (decl = decl.arguments[0]);
t3.isObjectExpression(decl) ? self._parseExportsObject(decl) : logger2.warn(...)

.type<T>() is a call with zero value arguments (only a TypeScript type parameter), so decl.arguments[0] is undefined, the unwrap fails, and the warning is emitted.

Note: The CallExpression visitor separately catches the nested definePreview({...}) call and parses it correctly, so the build still succeeds — but the warning is confusing and unnecessary.

Reproduction link

https://github.com/yuheiy/storybook-definepreview-type-csf-error

Reproduction steps

// .storybook/preview.tsx
import { definePreview } from '@storybook/react-vite';

export default definePreview({
  parameters: {
    /* ... */
  },
}).type<{
  parameters: {
    customParam?: string;
  };
}>();
storybook build
# or
storybook dev

System

│

│  Storybook Environment Info:
│

│  System:
│  OS: macOS 15.7.3
│  CPU: (10) arm64 Apple M1 Max
│  Shell: 5.9 - /bin/zsh
│  Binaries:
│  Node: 24.13.0 -
│  XXXXXXXX
│  Yarn: 2.4.3 -
│  /Users/yuhei.yasuda/.local/share/mise/installs/node/24.12.0/bin/yarn
│  npm: 11.6.2 -
│  /Users/yuhei.yasuda/.local/share/mise/installs/node/24.12.0/bin/npm
│  pnpm: 10.28.2 - /Users/yuhei.yasuda/Library/pnpm/pnpm <----- active
│  Browsers:
│  Chrome: 144.0.7559.133
│  Firefox: 146.0.1
│  Safari: 26.2
│  npmPackages:
│  @storybook/addon-a11y: ^10.2.4 => 10.2.4
│  @storybook/addon-docs: ^10.2.4 => 10.2.4
│  @storybook/addon-vitest: ^10.2.4 => 10.2.4
│  @storybook/react-vite: ^10.2.4 => 10.2.4
│  storybook: ^10.2.4 => 10.2.4

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Summary by CodeRabbit

  • Bug Fixes

    • Improved parsing of complex factory declaration patterns to ensure more robust configuration file handling.
  • Tests

    • Added test coverage for chained factory declaration patterns.

Co-authored-by: valentinpalkovic <5889929+valentinpalkovic@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ConfigFile parser warning on definePreview chaining Fix ConfigFile parser false warning on definePreview({...}).type<T>() export default Feb 20, 2026
@valentinpalkovic valentinpalkovic moved this to In Progress in Core Team Projects Feb 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 20, 2026

Fails
🚫 PR description is missing the mandatory "#### Manual testing" section. Please add it so that reviewers know how to manually test your changes.

Generated by 🚫 dangerJS against 2bdb54a

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Feb 20, 2026

View your CI Pipeline Execution ↗ for commit 2bdb54a

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 12m 16s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-03 10:09:39 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Feb 20, 2026

View your CI Pipeline Execution ↗ for commit f48a1ae

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 10m 18s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-20 12:01:20 UTC

@valentinpalkovic valentinpalkovic moved this from In Progress to Empathy Queue (prioritized) in Core Team Projects Feb 24, 2026
@valentinpalkovic
Copy link
Copy Markdown
Contributor

@copilot Fix linting issues as described in .github/copilot-instructions.md

@valentinpalkovic valentinpalkovic changed the title Fix ConfigFile parser false warning on definePreview({...}).type<T>() export default CSF-Factories: Fix ConfigFile parser false warning on definePreview({...}).type<T>() export default Mar 3, 2026
@valentinpalkovic valentinpalkovic moved this from Empathy Queue (prioritized) to In Progress in Core Team Projects Mar 3, 2026
@valentinpalkovic valentinpalkovic marked this pull request as ready for review March 3, 2026 09:39
@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Mar 3, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

Enhanced CSF factory declaration parsing by introducing iterative unwrapping logic to handle nested patterns like definePreview({...}).type<T>() in export default statements. Added corresponding test case validating the unwrapping behavior for chained method calls.

Changes

Cohort / File(s) Summary
CSF Factory Unwrapping Logic
code/core/src/csf-tools/ConfigFile.ts, code/core/src/csf-tools/ConfigFile.test.ts
Implemented iterative unwrapping loop in ExportDefaultDeclaration handling to recognize CSF factories wrapped in CallExpression and MemberExpression patterns. Added test case verifying correct parameter extraction from definePreview({...}).type<T>() chains.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/core/src/csf-tools/ConfigFile.test.ts`:
- Around line 296-312: The test must assert that no warning is emitted during
parse for the .type<T>() chaining case: wrap the call to
loadConfig(source).parse() with a spy on the warning emitter (e.g.,
jest.spyOn(console, 'warn') or the test logger used by loadConfig), call parse
via loadConfig(source).parse(), then expect the spy not to have been called, and
finally restore the spy; reference the existing loadConfig(...) and parse()
calls so you add the spy before parse and the expect(spy).not.toHaveBeenCalled()
after.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 558bede and 0e17410.

📒 Files selected for processing (2)
  • code/core/src/csf-tools/ConfigFile.test.ts
  • code/core/src/csf-tools/ConfigFile.ts

Comment on lines +296 to +312
it('parses correctly with .type<T>() chaining on export default', () => {
const source = dedent`
import { definePreview } from '@storybook/react-vite';

export default definePreview({
parameters: {
foo: 'bar',
},
}).type<{
parameters: {
customParam?: string;
};
}>();
`;
const config = loadConfig(source).parse();
expect(config.getFieldValue(['parameters', 'foo'])).toEqual('bar');
});
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.

⚠️ Potential issue | 🟠 Major

Assert warning suppression explicitly in this regression test.

This test only validates parsed data; it can still pass even if the parser logs the false warning again. Please also assert that no warning is emitted during parse for this .type<T>() pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/csf-tools/ConfigFile.test.ts` around lines 296 - 312, The test
must assert that no warning is emitted during parse for the .type<T>() chaining
case: wrap the call to loadConfig(source).parse() with a spy on the warning
emitter (e.g., jest.spyOn(console, 'warn') or the test logger used by
loadConfig), call parse via loadConfig(source).parse(), then expect the spy not
to have been called, and finally restore the spy; reference the existing
loadConfig(...) and parse() calls so you add the spy before parse and the
expect(spy).not.toHaveBeenCalled() after.

Co-authored-by: valentinpalkovic <5889929+valentinpalkovic@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot Fix linting issues as described in .github/copilot-instructions.md

Fixed in 2bdb54a — ran prettier on ConfigFile.ts which reformatted the multi-condition else if clause to split across multiple lines.

Copilot AI requested a review from valentinpalkovic March 3, 2026 09:47
@valentinpalkovic valentinpalkovic merged commit 011e081 into next Mar 3, 2026
121 of 126 checks passed
@valentinpalkovic valentinpalkovic deleted the copilot/fix-configfile-parser-warning branch March 3, 2026 12:40
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects Mar 3, 2026
ghengeveld pushed a commit that referenced this pull request Mar 6, 2026
…ser-warning

CSF-Factories: Fix ConfigFile parser false warning on `definePreview({...}).type<T>()` export default
(cherry picked from commit 011e081)
@github-actions github-actions Bot mentioned this pull request Mar 6, 2026
11 tasks
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal csf factories patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: ConfigFile parser warns on definePreview({...}).type<{...}>() in export default

2 participants