Skip to content

CLI: Update AI setup instructions to msw-storybook-addon v3 - #35512

Merged
ndelangen merged 4 commits into
nextfrom
yann/ai-setup-msw-v3
Jul 27, 2026
Merged

ndelangen merged 4 commits into
nextfrom
yann/ai-setup-msw-v3

Conversation

@yannbf

@yannbf yannbf commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

What I did

The storybook ai setup prompts teach the msw-storybook-addon v2 API. Under the upcoming v3 (mswjs/msw-storybook-addon#193), that preview snippet crashes at module load: initialize no longer exists, and mswLoader moved to the msw-storybook-addon/csf3 subpath. Since the install step is unpinned, the moment v3 becomes latest, every fresh setup run would produce instructions that make agents scaffold broken previews.

Changes, across all prompt variants (the shipping pattern-copy-play default plus the other variants via the shared partials):

  • Register the addon with storybook add msw-storybook-addon@3 so it also lands in the main.* addons field. Pinning the major means the snippets and the installed API can't drift apart.
  • CSF3 previews: loaders: [mswLoader()] imported from msw-storybook-addon/csf3, with handlers wired in beforeEach({ msw }) instead of the deprecated parameters.msw (merged into the existing beforeEach the example already had).
  • CSF factories previews: branch on hasCsfFactoryPreview and wire via addonMsw() in definePreview({ addons }).
  • The msw-handlers example exports a flat array now that it's spread into msw.use(...).
  • For CSF factories projects, the msw step now warns that storybook add may inject a mswStorybookAddon namespace entry into definePreview.addons and instructs removing it in favor of addonMsw() — a single namespace entry collapses the whole preview's type inference to never (CSF factories codemod injects incompatible addon namespaces into definePreview, collapsing all preview types to never #35571).

How to test

  • Go to a project that could use MSW but doesn't have it yet, e.g. MealDrop + Removing its storybook with npx @hipster/sb-utils uninstall --yes
  • Run the Storybook AI setup
  • If the generated code includes MSW and its addon, make sure that it works as intended

Summary by CodeRabbit

  • New Features

    • Updated generated MSW setup guidance for modern Storybook workflows, including explicit MSW addon registration.
    • Enhanced CSF factory preview support with definePreview, mswHandlers, and session provider wiring.
    • Refreshed examples to match current MSW addon usage and handler-array patterns.
  • Bug Fixes

    • Adjusted generated install commands to include only the necessary MSW-related packages (removing extra addon installation from the install step).
    • Corrected preview/MSW configuration to avoid incorrect definePreview injection and mismatched initialization style.

@yannbf
yannbf force-pushed the yann/ai-setup-msw-v3 branch from f23f705 to 2557210 Compare July 16, 2026 08:23
@yannbf yannbf self-assigned this Jul 16, 2026
@yannbf yannbf added bug ci:normal Run our default set of CI jobs (choose this for most PRs). qa:needed Pull Requests that will need manual QA prior to release. labels Jul 16, 2026
yannbf and others added 2 commits July 23, 2026 19:17
The setup prompts taught the v2 API, which crashes at module load under
v3: `initialize` no longer exists and `mswLoader` moved to the
`msw-storybook-addon/csf3` subpath.

- register the addon via `storybook add msw-storybook-addon@3` so it
  lands in the main config (and the install command is pinned to the
  major the snippets teach, so they cannot drift apart)
- CSF3 previews: `loaders: [mswLoader()]` from `/csf3`, handlers wired
  in `beforeEach({ msw })` instead of the deprecated `parameters.msw`
- CSF factories previews (`hasCsfFactoryPreview`): `addonMsw()` in
  `definePreview({ addons })`
- handlers file example is a flat array now that it is spread into
  `msw.use(...)`

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
`storybook add` syncs third-party addons into `definePreview` as
namespace imports, which the factories types reject — a single such
entry collapses the whole preview's inference to `never` (#35571).
When the project uses CSF factories, the msw setup step now tells the
agent to remove the injected `mswStorybookAddon` entry and register
`addonMsw()` instead.
@yannbf
yannbf force-pushed the yann/ai-setup-msw-v3 branch from 2557210 to 9200c8d Compare July 23, 2026 17:19
@yannbf
yannbf marked this pull request as ready for review July 23, 2026 17:21
@yannbf
yannbf requested a review from a team July 23, 2026 17:21
@coderabbitai

coderabbitai Bot commented Jul 23, 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

Run ID: 0354e530-d6ef-4268-8136-24e076571099

📥 Commits

Reviewing files that changed from the base of the PR and between 9200c8d and 80148d8.

📒 Files selected for processing (4)
  • code/core/src/cli/ai/setup-prompts/monorepo-optimized-tests-relaxed-limits-no-story-deletion.ts
  • code/core/src/cli/ai/setup-prompts/monorepo.ts
  • code/core/src/cli/ai/setup-prompts/optimized-tests.ts
  • code/core/src/cli/ai/setup-prompts/relaxed-limits.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • code/core/src/cli/ai/setup-prompts/relaxed-limits.ts
  • code/core/src/cli/ai/setup-prompts/monorepo-optimized-tests-relaxed-limits-no-story-deletion.ts
  • code/core/src/cli/ai/setup-prompts/monorepo.ts
  • code/core/src/cli/ai/setup-prompts/optimized-tests.ts

📝 Walkthrough

Walkthrough

MSW setup prompts now install msw separately from msw-storybook-addon, provide addon v3 guidance, use array-based handlers, and generate CSF3 or CSF factory preview examples with mswLoader(), beforeEach, and addonMsw().

Changes

MSW v3 setup prompts

Layer / File(s) Summary
MSW installation and setup guidance
code/core/src/cli/ai/setup-prompts/monorepo*.ts, code/core/src/cli/ai/setup-prompts/optimized-tests.ts, code/core/src/cli/ai/setup-prompts/relaxed-limits.ts, code/core/src/cli/ai/setup-prompts/partials/steps.ts, code/core/src/cli/ai/setup-prompts/pattern-copy-play.ts
MSW install commands now exclude msw-storybook-addon; setup instructions add the addon separately and include CSF factory guidance.
Handler and preview integration
code/core/src/cli/ai/setup-prompts/partials/examples.ts, code/core/src/cli/ai/setup-prompts/partials/steps.ts, code/core/src/cli/ai/setup-prompts/pattern-copy-play.ts
Generated handlers use arrays, while preview examples use mswLoader(), beforeEach({ msw }), msw.use(...mswHandlers), and addonMsw() for CSF factory previews.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StorybookPreview
  participant mswLoader
  participant beforeEach
  participant MSWHandlers
  StorybookPreview->>mswLoader: load mswLoader()
  StorybookPreview->>beforeEach: invoke async beforeEach({ msw })
  beforeEach->>MSWHandlers: msw.use(...mswHandlers)
Loading

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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/cli/ai/setup-prompts/pattern-copy-play.ts`:
- Line 147: Update the preview import snippets to include the generated
handler-file extension, using .ts for TypeScript output and .js for JavaScript
output. Apply this to both imports in pattern-copy-play.ts (lines 147-147 and
164-164) and all three imports in partials/examples.ts (lines 19-19, 48-48, and
79-79), preserving the existing generated-output language distinction.
🪄 Autofix (Beta)

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

Run ID: 950d56b7-03cf-472b-9d99-f45aefe6eb7c

📥 Commits

Reviewing files that changed from the base of the PR and between e615c99 and 9200c8d.

📒 Files selected for processing (7)
  • code/core/src/cli/ai/setup-prompts/monorepo-optimized-tests-relaxed-limits-no-story-deletion.ts
  • code/core/src/cli/ai/setup-prompts/monorepo.ts
  • code/core/src/cli/ai/setup-prompts/optimized-tests.ts
  • code/core/src/cli/ai/setup-prompts/partials/examples.ts
  • code/core/src/cli/ai/setup-prompts/partials/steps.ts
  • code/core/src/cli/ai/setup-prompts/pattern-copy-play.ts
  • code/core/src/cli/ai/setup-prompts/relaxed-limits.ts

Comment thread code/core/src/cli/ai/setup-prompts/pattern-copy-play.ts
@coderabbitai coderabbitai Bot mentioned this pull request Jul 23, 2026
4 of 5 tasks
@shilman shilman added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jul 26, 2026
@ndelangen
ndelangen merged commit 95efa3d into next Jul 27, 2026
139 checks passed
@ndelangen
ndelangen deleted the yann/ai-setup-msw-v3 branch July 27, 2026 08:11
@github-actions github-actions Bot mentioned this pull request Jul 27, 2026
2 tasks done
@ndelangen ndelangen added patch:done Patch/release PRs already cherry-picked to main/release branch and removed patch:yes Bugfix & documentation PR that need to be picked to main branch labels Jul 27, 2026
@github-actions github-actions Bot mentioned this pull request Jul 28, 2026
2 tasks done
unpunnyfuns pushed a commit to unpunnyfuns/storybook that referenced this pull request Aug 5, 2026
…sw-v3

CLI: Update AI setup instructions to msw-storybook-addon v3
(cherry picked from commit 95efa3d)
@yannbf yannbf added qa:success Pull Requests that were successfully QA'ed by the release team. and removed qa:needed Pull Requests that will need manual QA prior to release. labels Aug 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor
Fails
🚫

node failed.

Log

Details
Error:  Error: Could not find the Dangerfile at scripts/dangerfile.ts - if it is local, perhaps you have a typo? If it's using a remote file, it doesn't have a repo reference.
    at /usr/src/danger/dist/platforms/GitHub.js:161:27
    at step (/usr/src/danger/dist/platforms/GitHub.js:44:23)
    at Object.next (/usr/src/danger/dist/platforms/GitHub.js:25:53)
    at /usr/src/danger/dist/platforms/GitHub.js:19:71
    at new Promise (<anonymous>)
    at __awaiter (/usr/src/danger/dist/platforms/GitHub.js:15:12)
    at Object.executeRuntimeEnvironment (/usr/src/danger/dist/platforms/GitHub.js:144:88)
    at /usr/src/danger/dist/commands/danger-runner.js:101:47
    at step (/usr/src/danger/dist/commands/danger-runner.js:34:23)
    at Object.next (/usr/src/danger/dist/commands/danger-runner.js:15:53)
danger-results://tmp/danger-results-47315686.json

Generated by 🚫 dangerJS against 11e627e

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

Labels

bug ci:normal Run our default set of CI jobs (choose this for most PRs). patch:done Patch/release PRs already cherry-picked to main/release branch qa:success Pull Requests that were successfully QA'ed by the release team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants