Skip to content

[Storybook 11] - BREAKING: Resolve the story index in-process via presets#256

Open
yannbf wants to merge 3 commits into
mainfrom
yann/story-index-via-preset
Open

[Storybook 11] - BREAKING: Resolve the story index in-process via presets#256
yannbf wants to merge 3 commits into
mainfrom
yann/story-index-via-preset

Conversation

@yannbf

@yannbf yannbf commented Jun 2, 2026

Copy link
Copy Markdown
Member

Replace the loopback fetch(${origin}/index.json) with an in-process lookup through options.presets.apply('storyIndexGenerator').getIndex(). The dev server registers and memoises a single StoryIndexGenerator, so this returns the live, HMR-fresh index with no network round-trip.

  • add utils/get-story-index.ts (getStoryIndex(options)) + tests
  • migrate get-changed-stories, preview-stories and run-story-tests from fetchStoryIndex(origin) to getStoryIndex(options)
  • remove utils/fetch-story-index.ts and update test mocks

…IndexGenerator preset

Replace the loopback `fetch(${origin}/index.json)` with an in-process lookup
through `options.presets.apply('storyIndexGenerator').getIndex()`. The dev
server registers and memoises a single StoryIndexGenerator, so this returns the
live, HMR-fresh index with no network round-trip.

- add utils/get-story-index.ts (getStoryIndex(options)) + tests
- migrate get-changed-stories, preview-stories and run-story-tests from
  fetchStoryIndex(origin) to getStoryIndex(options)
- remove utils/fetch-story-index.ts and update test mocks
Copilot AI review requested due to automatic review settings June 2, 2026 06:51
@changeset-bot

changeset-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0a454ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@storybook/addon-mcp Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Jun 2, 2026

Copy link
Copy Markdown

Deploy Preview for storybook-mcp-self-host-example canceled.

Name Link
🔨 Latest commit 0a454ae
🔍 Latest deploy log https://app.netlify.com/projects/storybook-mcp-self-host-example/deploys/6a1ebd531c075f00089d52f4

@pkg-pr-new

pkg-pr-new Bot commented Jun 2, 2026

Copy link
Copy Markdown
npx https://pkg.pr.new/storybookjs/mcp/@storybook/addon-mcp@256
npx https://pkg.pr.new/storybookjs/mcp/@storybook/mcp@256
npx https://pkg.pr.new/storybookjs/mcp/@storybook/mcp-proxy@256

commit: 0a454ae

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Bundle Report

Changes will decrease total bundle size by 77.75kB (-47.83%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@storybook/addon-mcp-esm* 5.05kB -77.75kB (-93.9%) ⬇️

ℹ️ *Bundle size includes cached data from a previous commit

Affected Assets, Files, and Routes:

view changes for bundle: @storybook/addon-mcp-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
preview-*.js (New) 5.05kB 5.05kB 100.0% 🚀
preset.js (Deleted) -82.8kB 0 bytes -100.0% 🗑️

Files in preview-*.js:

  • ./package.json → Total Size: 59 bytes

Copilot AI 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.

Pull request overview

Replaces the loopback HTTP fetch of /index.json with an in-process resolution of the story index via the storyIndexGenerator Storybook preset. The new helper applies the preset to retrieve Storybook's memoised, HMR-aware StoryIndexGenerator and calls getIndex() directly, eliminating a network round-trip and a source of out-of-sync results.

Changes:

  • Add utils/get-story-index.ts with getStoryIndex(options) and accompanying unit tests.
  • Migrate get-changed-stories, preview-stories, and run-story-tests from fetchStoryIndex(origin) to getStoryIndex(options), adding options presence checks where needed.
  • Remove utils/fetch-story-index.ts and its tests; update test mocks to spy on the new module.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/addon-mcp/src/utils/get-story-index.ts New helper that resolves the index via options.presets.apply('storyIndexGenerator').
packages/addon-mcp/src/utils/get-story-index.test.ts Unit tests for success, missing-generator, and propagated-error paths.
packages/addon-mcp/src/utils/fetch-story-index.ts Removed legacy loopback fetch utility.
packages/addon-mcp/src/utils/fetch-story-index.test.ts Removed tests for the legacy utility.
packages/addon-mcp/src/tools/run-story-tests.ts Switch to getStoryIndex(options).
packages/addon-mcp/src/tools/run-story-tests.test.ts Update mock to target get-story-index module.
packages/addon-mcp/src/tools/preview-stories.ts Switch to getStoryIndex(options), add options guard while retaining origin for URL building.
packages/addon-mcp/src/tools/preview-stories.test.ts Update spies/assertions to the new module and call signature.
packages/addon-mcp/src/tools/get-changed-stories.ts Switch to getStoryIndex(options), replace origin guard with options guard.
packages/addon-mcp/src/tools/get-changed-stories.test.ts Update spies and assertions to use the new module.

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.41176% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.03%. Comparing base (c26899b) to head (0a454ae).
⚠️ Report is 23 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/addon-mcp/src/mcp-handler.ts 40.00% 3 Missing ⚠️
...ackages/addon-mcp/src/tools/get-changed-stories.ts 25.00% 1 Missing and 2 partials ⚠️
packages/addon-mcp/src/tools/preview-stories.ts 25.00% 1 Missing and 2 partials ⚠️
packages/addon-mcp/src/tools/run-story-tests.ts 25.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #256      +/-   ##
==========================================
- Coverage   78.12%   78.03%   -0.10%     
==========================================
  Files          57       56       -1     
  Lines        1550     1566      +16     
  Branches      430      435       +5     
==========================================
+ Hits         1211     1222      +11     
- Misses        203      207       +4     
- Partials      136      137       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread packages/addon-mcp/src/utils/get-story-index.ts Outdated

@JReinhold JReinhold 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.

You have to bump the peer dependency range of Storybook packages to 10.2.0 and above, as that's where the story index generator was introduced: https://github.com/storybookjs/storybook/releases/tag/v10.2.0-alpha.9

Via a minor version changeset.

@ghengeveld ghengeveld left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Besides Jeppe's versioning concern, LGTM.

Requires Storybook >= 10.2.0

- Drop utils/get-story-index.ts. The addon resolves the dev server's memoised
  StoryIndexGenerator once and exposes a thin getStoryIndex() on the server
  context (AddonContext), so tools call ctx.getStoryIndex() instead of receiving
  `options` and resolving the generator themselves.
- Bump the `storybook` peer dependency to >= 10.2.0, where the story index
  generator was introduced. Minor changeset added.
@yannbf yannbf added this to the Storybook 11 milestone Jun 2, 2026
@yannbf yannbf changed the title Refactor: Resolve the story index in-process via presets STORYBOOK 11 - Refactor: Resolve the story index in-process via presets Jun 2, 2026
@yannbf yannbf changed the title STORYBOOK 11 - Refactor: Resolve the story index in-process via presets [Storybook 11] - BREAKING: Resolve the story index in-process via presets Jun 2, 2026
@yannbf

yannbf commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

@JReinhold I made the changes and this is now a breaking release PR. Let's leave this for the future, once we prepare Storybook 11.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants