[Storybook 11] - BREAKING: Resolve the story index in-process via presets#256
[Storybook 11] - BREAKING: Resolve the story index in-process via presets#256yannbf wants to merge 3 commits into
Conversation
…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
🦋 Changeset detectedLatest commit: 0a454ae The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
✅ Deploy Preview for storybook-mcp-self-host-example canceled.
|
commit: |
Bundle ReportChanges will decrease total bundle size by 77.75kB (-47.83%) ⬇️. This is within the configured threshold ✅ Detailed changes
ℹ️ *Bundle size includes cached data from a previous commit Affected Assets, Files, and Routes:view changes for bundle: @storybook/addon-mcp-esmAssets Changed:
Files in
|
There was a problem hiding this comment.
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.tswithgetStoryIndex(options)and accompanying unit tests. - Migrate
get-changed-stories,preview-stories, andrun-story-testsfromfetchStoryIndex(origin)togetStoryIndex(options), addingoptionspresence checks where needed. - Remove
utils/fetch-story-index.tsand 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 Report❌ Patch coverage is 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. |
JReinhold
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
@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. |
Replace the loopback
fetch(${origin}/index.json)with an in-process lookup throughoptions.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.