Skip to content

[Bug]: CSF Next codemod incorrectly handles spread operators #33710

@jonniebigodes

Description

@jonniebigodes

Describe the bug

When a user runs the CSF Next codemod on code that contains spread operators, it yields incorrect results and invalid code. I noticed this issue when I was testing the codemod on a codebase that spread the parameters object within their stories. This can also be applied to any other object that is spread within a story.
This pattern may be common in codebases that use Storybook, as spreading parameters can be used to share common configurations across multiple stories or to override specific settings for individual stories.

Per my testing, I found that this pattern applies to the supported CSF Next frameworks (e.g., React, Vue, Angular, Web Components) and yields the same incorrect results across all of them, as observed in the following recording.

csf-next-codemod-incorrect-conversion.mp4

cc @kasperpeulen

Reproduction link

N/A

Reproduction steps

  1. Create a new Storybook project using a supported framework (e.g., React, Vue, Angular, Web Components).
  2. Add a story that uses the spread operator to include parameters or other objects within the story.
  3. Run the CSF Next codemod on the project.
  4. Observe the output code for incorrect handling of the spread operator and leftover types from the original code (e.g., StoryObj) in the transformed stories
  5. Observe that imported stories that use the spread operator are not correctly transformed.

System

│  Storybook Environment Info:
│

│  System:
│  OS: macOS 15.0.1
│  CPU: (8) arm64 Apple M3
│  Shell: 5.9 - /bin/zsh
│  Binaries:
│  Node: 20.19.2 - /Users/joaocardoso/.nvm/versions/node/v20.19.2/bin/node
│  Yarn: 1.22.22 - /Users/joaocardoso/.nvm/versions/node/v20.19.2/bin/yarn
│  npm: 10.8.2 - /Users/joaocardoso/.nvm/versions/node/v20.19.2/bin/npm <-----
│  active
│  pnpm: 9.12.3 - /Users/joaocardoso/.nvm/versions/node/v20.19.2/bin/pnpm
│  Browsers:
│  Chrome: 144.0.7559.109
│  Edge: 144.0.3719.92
│  Firefox: 136.0
│  Safari: 18.0.1
│  npmPackages:
│  @storybook/addon-a11y: ^10.2.1 => 10.2.1
│  @storybook/addon-docs: ^10.2.1 => 10.2.1
│  @storybook/addon-vitest: ^10.2.1 => 10.2.1
│  @storybook/preact-vite: ^10.2.1 => 10.2.1
│  storybook: ^10.2.1 => 10.2.1

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions