Skip to content

Add Stories block support for of and docs.stories options#34775

Open
kalinco-glitch wants to merge 3 commits into
storybookjs:nextfrom
kalinco-glitch:codex/stories-block-of-parameters
Open

Add Stories block support for of and docs.stories options#34775
kalinco-glitch wants to merge 3 commits into
storybookjs:nextfrom
kalinco-glitch:codex/stories-block-of-parameters

Conversation

@kalinco-glitch
Copy link
Copy Markdown

@kalinco-glitch kalinco-glitch commented May 12, 2026

Closes #22490

What I did

Added v7-style API support to the Stories docs block.

  • Added of support so Stories can render stories from a specified CSF file
  • Added includePrimaryStory, while preserving the legacy includePrimary prop
  • Added forceInitialArgs support instead of always forcing initial args
  • Read default title, includePrimaryStory, and forceInitialArgs from parameters.docs.stories
  • Added docs.stories typing, including the existing filter option
  • Added Storybook examples covering the new Stories block behavior

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Validated locally with:

  1. git diff --check
  2. oxfmt --check code/addons/docs/src/blocks/blocks/Stories.tsx code/addons/docs/src/blocks/blocks/Stories.stories.tsx code/addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx code/addons/docs/src/types.ts
  3. A surgical TypeScript check on the changed files with docs/react package typings included

I was not able to run the full local ESLint suite because this checkout requires built Storybook core output for the internal eslint-plugin-storybook workspace package.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features

    • Stories docs block can reference story modules via an of prop and now supports options to include/exclude the primary story, filter which stories show, set a title, and force initial args.
    • Added several example story variants demonstrating these behaviors.
  • Documentation

    • Docs parameters/types updated to expose story-block configuration (filtering, primary visibility, title, and force-initial-args).
  • Bug Fixes

    • Improved validation and clearer handling when a docs file lacks an attached story/meta.

Review Change Stack

@kalinco-glitch kalinco-glitch marked this pull request as ready for review May 12, 2026 19:45
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

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: 0cd2d806-d4d6-4e08-b2ba-8a3def2e8526

📥 Commits

Reviewing files that changed from the base of the PR and between 65100ea and 67a828c.

📒 Files selected for processing (4)
  • code/addons/docs/src/blocks/blocks/Stories.tsx
  • code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.test.ts
  • code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.ts
  • code/core/src/preview-errors.ts
✅ Files skipped from review due to trivial changes (1)
  • code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/addons/docs/src/blocks/blocks/Stories.tsx

📝 Walkthrough

Walkthrough

The Stories docs block gains an of prop and a StoriesBlockParameters type. The block resolves of with useOf, validates of (throws NoMetaAttachedError for missing meta), derives title/showPrimary/forceInitialArgs from prepared meta or props, forwards __forceInitialArgs to DocsStory, and adds example CSF stories demonstrating the new args/parameters.

Changes

Stories Block Module Resolution and Configuration

Layer / File(s) Summary
Configuration types and contracts
code/addons/docs/src/types.ts
StoriesBlockParameters type defines optional fields for filtering stories, including primary story inclusion, forced initial args, and title override. DocsParameters now optionally includes docs.stories?: StoriesBlockParameters.
Stories block implementation with of prop support
code/addons/docs/src/blocks/blocks/Stories.tsx
Stories accepts of, includePrimaryStory, and forceInitialArgs (keeps deprecated includePrimary). It resolves of with useOf (handles missing attached meta via NoMetaAttachedError), reads preparedMeta.parameters.docs.stories for title/showPrimary/forceInitialArgs, forwards __forceInitialArgs to DocsStory, and updates primary-story suppression and rendering.
Example stories demonstrating Stories block features
code/addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx, code/addons/docs/src/blocks/blocks/Stories.stories.tsx
Adds an example CSF file exporting meta and three stories, and updates Stories.stories to export WithoutPrimaryStory, OfCSFFile, and WithDocsStoriesParameters that use relativeCsfPaths and args.of referencing example modules.
Core missing-meta error and tests
code/core/src/preview-errors.ts, code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.ts, code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.test.ts
Adds NoMetaAttachedError and makes DocsContext throw it when no CSF/meta is attached; updates the test to expect that specific error type.

Sequence Diagram(s)

sequenceDiagram
  participant DocsPage
  participant StoriesBlock
  participant useOf
  participant PreparedMeta
  participant DocsStory
  DocsPage->>StoriesBlock: render Stories block (props: of, includePrimaryStory, forceInitialArgs)
  StoriesBlock->>useOf: resolve `of` module
  useOf->>PreparedMeta: return prepared meta / stories
  StoriesBlock->>DocsStory: render each story with __forceInitialArgs and showPrimaryStory decision
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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: 3

🧹 Nitpick comments (4)
code/addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx (1)

1-27: ⚡ Quick win

Run the linter on the new file.

Please run the linter to ensure the new file follows all linting rules:

cd code && yarn lint:js:cmd addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx --fix

As per coding guidelines: "Lint with yarn --cwd code lint:js:cmd <file-relative-to-code-folder> --fix after changing files".

🤖 Prompt for 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.

In `@code/addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx`
around lines 1 - 27, Run the project linter on the new story file and apply
fixes: execute yarn --cwd code lint:js:cmd
addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx --fix, then
commit any changes; ensure the exported consts (Primary, Secondary, Tertiary),
the meta constant (meta) and the import of EmptyExample follow the repo lint
rules (formatting, ordering, and unused/import rules) and that the file
satisfies Meta<typeof EmptyExample> typing without lint errors.
code/addons/docs/src/types.ts (1)

36-36: ⚡ Quick win

Use proper Storybook types instead of any for the filter function.

The filter function signature uses any for both story and context parameters, which degrades type safety. Storybook's type system includes proper types for stories and story contexts that should be used here (e.g., from storybook/internal/types).

♻️ Suggested improvement

Consider using proper types like PreparedStory and StoryContext or similar types from Storybook's internal type system:

 type StoriesBlockParameters = {
   /** Filter which stories are rendered by the Stories block */
-  filter?: (story: any, context: any) => boolean;
+  filter?: (story: PreparedStory, context: StoryContext) => boolean;
   /** When rendering stories, whether the first story should be included */
   includePrimaryStory?: boolean;
🤖 Prompt for 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.

In `@code/addons/docs/src/types.ts` at line 36, The filter property in types.ts
currently uses broad any types; update the signature of filter (the exported
type/interface that defines filter) to use Storybook's specific story and
context types (e.g., PreparedStory and StoryContext or the equivalent types from
Storybook's type package) and add the appropriate import from Storybook (e.g.,
import { PreparedStory, StoryContext } from the Storybook types module). Ensure
the filter signature becomes (story: PreparedStory, context: StoryContext) =>
boolean (or the exact names provided by the Storybook version in use) so the
types align with the rest of the codebase.
code/addons/docs/src/blocks/blocks/Stories.tsx (1)

43-115: ⚡ Quick win

Run the linter after making changes.

The coding guidelines require running the linter on changed TypeScript files. Please run the following command to ensure the code follows all linting rules:

cd code && yarn lint:js:cmd addons/docs/src/blocks/blocks/Stories.tsx --fix

As per coding guidelines: "Lint with yarn --cwd code lint:js:cmd <file-relative-to-code-folder> --fix or cd code && yarn lint:js:cmd <file-relative-to-code-folder> after changing files".

🤖 Prompt for 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.

In `@code/addons/docs/src/blocks/blocks/Stories.tsx` around lines 43 - 115, The
linter must be run to fix styling/TS issues introduced in the StoriesImpl
component; run the project's lint command targeting the changed file (e.g. from
the repo root run the equivalent of cd code && yarn lint:js:cmd
addons/docs/src/blocks/blocks/Stories.tsx --fix) and re-run tests, then commit
the autofixed changes that affect the StoriesImpl component (and any other files
modified by the fixer) before pushing.
code/addons/docs/src/blocks/blocks/Stories.stories.tsx (1)

1-70: ⚡ Quick win

Run the linter after making changes.

Please run the linter to ensure the code follows all linting rules:

cd code && yarn lint:js:cmd addons/docs/src/blocks/blocks/Stories.stories.tsx --fix

As per coding guidelines: "Lint with yarn --cwd code lint:js:cmd <file-relative-to-code-folder> --fix after changing files".

🤖 Prompt for 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.

In `@code/addons/docs/src/blocks/blocks/Stories.stories.tsx` around lines 1 - 70,
Run the JS linter with autofix on the Stories.stories.tsx changes: from the repo
root execute the provided lint command to fix style/format issues in the Stories
component and its exports (meta, Default, WithoutPrimary, WithoutPrimaryStory,
OfCSFFile, WithDocsStoriesParameters, DifferentToolbars, NoAutodocs,
SomeAutodocs); specifically run: yarn --cwd code lint:js:cmd
addons/docs/src/blocks/blocks/Stories.stories.tsx --fix, then commit any
formatting/lint fixes.
🤖 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/addons/docs/src/blocks/blocks/Stories.tsx`:
- Around line 57-64: The current catch in the Stories component relies on
matching an error.message string from useOf, which is brittle; change the flow
to use a dedicated error class or code instead: update the implementation that
throws in useOf to throw a specific class (e.g., MissingMetaError) or attach a
distinct error.code like 'MISSING_META', then in the Stories.tsx catch block
check error instanceof MissingMetaError or error.code === 'MISSING_META'
(instead of message.includes(...)) and only suppress/recover for that
class/code; any other errors should continue to be re-thrown as they are now.
- Around line 13-14: The imports for the Of type and useOf hook in Stories.tsx
lack explicit file extensions; update both import statements (the named type Of
and the useOf import) to reference the actual file extension (e.g., change
'./useOf' to './useOf.ts' or './useOf.tsx' depending on the module) so the
imports read './useOf.ts' (or './useOf.tsx') for both the type import and the
hook import.

In `@code/addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx`:
- Line 3: Update the relative import of EmptyExample in
StoriesBlockParameters.stories.tsx to include an explicit file extension; change
the import that references ./EmptyExample to point to the actual module file
(e.g., ./EmptyExample.tsx) so the EmptyExample symbol is resolved with a
concrete TSX/TS extension per repo guidelines.

---

Nitpick comments:
In `@code/addons/docs/src/blocks/blocks/Stories.stories.tsx`:
- Around line 1-70: Run the JS linter with autofix on the Stories.stories.tsx
changes: from the repo root execute the provided lint command to fix
style/format issues in the Stories component and its exports (meta, Default,
WithoutPrimary, WithoutPrimaryStory, OfCSFFile, WithDocsStoriesParameters,
DifferentToolbars, NoAutodocs, SomeAutodocs); specifically run: yarn --cwd code
lint:js:cmd addons/docs/src/blocks/blocks/Stories.stories.tsx --fix, then commit
any formatting/lint fixes.

In `@code/addons/docs/src/blocks/blocks/Stories.tsx`:
- Around line 43-115: The linter must be run to fix styling/TS issues introduced
in the StoriesImpl component; run the project's lint command targeting the
changed file (e.g. from the repo root run the equivalent of cd code && yarn
lint:js:cmd addons/docs/src/blocks/blocks/Stories.tsx --fix) and re-run tests,
then commit the autofixed changes that affect the StoriesImpl component (and any
other files modified by the fixer) before pushing.

In `@code/addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx`:
- Around line 1-27: Run the project linter on the new story file and apply
fixes: execute yarn --cwd code lint:js:cmd
addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx --fix, then
commit any changes; ensure the exported consts (Primary, Secondary, Tertiary),
the meta constant (meta) and the import of EmptyExample follow the repo lint
rules (formatting, ordering, and unused/import rules) and that the file
satisfies Meta<typeof EmptyExample> typing without lint errors.

In `@code/addons/docs/src/types.ts`:
- Line 36: The filter property in types.ts currently uses broad any types;
update the signature of filter (the exported type/interface that defines filter)
to use Storybook's specific story and context types (e.g., PreparedStory and
StoryContext or the equivalent types from Storybook's type package) and add the
appropriate import from Storybook (e.g., import { PreparedStory, StoryContext }
from the Storybook types module). Ensure the filter signature becomes (story:
PreparedStory, context: StoryContext) => boolean (or the exact names provided by
the Storybook version in use) so the types align with the rest of the codebase.
🪄 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: 250472f4-063f-43c4-87d9-75a40fad8939

📥 Commits

Reviewing files that changed from the base of the PR and between 065291f and 5e08f2e.

📒 Files selected for processing (4)
  • code/addons/docs/src/blocks/blocks/Stories.stories.tsx
  • code/addons/docs/src/blocks/blocks/Stories.tsx
  • code/addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx
  • code/addons/docs/src/types.ts

Comment thread code/addons/docs/src/blocks/blocks/Stories.tsx Outdated
Comment thread code/addons/docs/src/blocks/blocks/Stories.tsx Outdated
Comment thread code/addons/docs/src/blocks/examples/StoriesBlockParameters.stories.tsx Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: On Hold

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Upgrade Primary, Title, Subtitle and Stories blocks to the new v7 blocks API

3 participants