Skip to content

Conversation

@kroeder
Copy link
Member

@kroeder kroeder commented Jan 19, 2026

Closes N/A
Created from #26531

What I did

I started #26531 from scratch since it was hard to merge next into the original PR.

This PR adds docs-mode headings to the search results and makes it possible to not only search for the main title of a docs story. This aims to improve UX

Example

Given a story with the title "Table" and a docs heading "## Filtering", today it's not possible to search for "Filtering" or "Table Filtering".

With this PR, it should be possible to search for exactly that.

Checklist for Contributors

Todo's

  • Add docs-mode headings available in search results
  • Fix auto-gen docs behavior
  • Fix broken navigation after search menu click
  • Being on the same story as an anchor you click in the search bar does not trigger scrolling
  • Add tests
  • Add feature flag to make this opt-in
  • Make heading-level configurable (e.g. "only include ## and ### headings")
  • Add "scrollIntoView()" behavior
  • Add documentation

Testing

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

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

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

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

    • Documentation headings are now searchable through the sidebar search, enabling quick navigation to specific sections within documents.
    • Search results for documentation entries now display relevant headings alongside document names for easier section discovery.
  • Improvements

    • Search algorithm weights have been refined to improve result relevance and ranking.

✏️ Tip: You can customize this high-level summary in your review settings.

@nx-cloud
Copy link

nx-cloud bot commented Jan 19, 2026

View your CI Pipeline Execution ↗ for commit a72e7f4

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 10m 13s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-19 21:22:14 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

This change introduces searchable document headings throughout the story system. Headings are extracted from story names during indexing, propagated through API and manager types, and integrated into the sidebar search functionality with separate weighting. Search results display headings alongside story names, with a new heading variant added for UI rendering.

Changes

Cohort / File(s) Summary
Package Dependencies
code/core/package.json
Updated @storybook/docs-mdx devDependency from "4.0.0-next.3" to "3.1.1--canary.16.129f63c.0"
Type Definitions
code/core/src/types/modules/api-stories.ts, code/core/src/types/modules/indexer.ts
Added optional headings: string[] property to API_DocsEntry and DocsIndexEntry; updated StatusByTypeId import source
Indexing & Data Extraction
code/core/src/core-server/utils/StoryIndexGenerator.ts, code/core/src/manager/utils/tree.ts
StoryIndexGenerator now computes and attaches headings collection from story names to docs entries; tree.ts adds name property to SearchItem objects
Search Implementation
code/core/src/manager/components/sidebar/Search.tsx
Refactored Fuse search configuration: reduced name weight (0.7→0.6), added headings key (0.1); reworked fuse list construction with explicit iteration; expanded results to include per-heading search entries with anchor-style IDs for docs items
UI Components
code/core/src/manager/components/sidebar/SearchResults.tsx, code/core/src/manager/components/sidebar/TreeNode.tsx
SearchResults displays heading alongside item name for docs entries; TreeNode extends TypeIcon with new 'heading' type variant and maps it to secondary theme color

Sequence Diagram

sequenceDiagram
    participant IndexGen as Indexing Engine
    participant API as API Types
    participant Search as Search Component
    participant UI as UI Renderer
    
    Note over IndexGen,UI: Document Heading Search Feature
    
    IndexGen->>API: Extract & attach headings from story names
    API->>Search: Provide DocsIndexEntry with headings
    
    Search->>Search: Initialize Fuse with expanded keys<br/>(name: 0.6, headings: 0.1)
    
    Note over Search: User enters search query
    
    Search->>Search: Match against index +<br/>generate per-heading results
    Search->>UI: Return results (docs items + heading variants)
    
    UI->>UI: Render heading-typed icons &<br/>display heading text in results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing touches
  • 📝 Generate docstrings

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
code/core/src/manager/components/sidebar/SearchResults.tsx (1)

181-211: Avoid rendering the entire headings array (and duplicates) in search results.

Line 185 uses item.headings directly, which is likely an array; this renders a comma-joined list and can duplicate text for heading-specific results where item.name already contains the heading. Consider rendering only the matched heading and skipping if already present in the name.

🔧 Suggested adjustment
-  const [icon] = item.status ? getStatus(theme, item.status) : [];
-  const heading = item.type === 'docs' && item.headings ? ` ${item.headings}` : undefined;
+  const [icon] = item.status ? getStatus(theme, item.status) : [];
+  const headingMatch = matches.find((match: Match) => match.key === 'headings');
+  const heading =
+    item.type === 'docs' && headingMatch?.value && !item.name.includes(headingMatch.value)
+      ? ` ${headingMatch.value}`
+      : undefined;
🤖 Fix all issues with AI agents
In `@code/core/src/manager/components/sidebar/Search.tsx`:
- Around line 212-220: Search.tsx is generating heading anchor IDs with
heading.replaceAll(' ', '-').toLowerCase(), which diverges from Heading.tsx's
github-slugger logic and breaks navigation for punctuation/special chars and
duplicate headings; fix by using the same slugger used in Heading.tsx (import
and call slugs.slug(heading.toLowerCase())) when building the id in the
headings.forEach block (or alternatively use a precomputed heading ID from the
indexer), ensuring the id format matches Heading.tsx so anchors resolve
correctly.
🧹 Nitpick comments (1)
code/core/src/manager/utils/tree.ts (1)

67-69: Redundant name property assignment.

The name property is already included in the spread of ...item. Adding name: item.name explicitly is redundant since Item already contains name.

🔧 Suggested simplification
 export const searchItem = (item: Item, ref: Parameters<typeof getPath>[1]): SearchItem => {
-  return { ...item, refId: ref.id, name: item.name, path: getPath(item, ref) };
+  return { ...item, refId: ref.id, path: getPath(item, ref) };
 };

@storybook-app-bot
Copy link

Package Benchmarks

Commit: a72e7f4, ran on 19 January 2026 at 21:20:07 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 49 49 0
Self size 20.30 MB 20.36 MB 🚨 +60 KB 🚨
Dependency size 16.52 MB 16.52 MB 🎉 -4 B 🎉
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 159 159 0
Self size 30 KB 30 KB 🚨 +8 B 🚨
Dependency size 23.00 MB 23.12 MB 🚨 +115 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 183 183 0
Self size 775 KB 775 KB 🚨 +139 B 🚨
Dependency size 67.38 MB 67.51 MB 🚨 +130 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 176 176 0
Self size 30 KB 30 KB 🎉 -4 B 🎉
Dependency size 65.95 MB 66.08 MB 🚨 +130 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 50 50 0
Self size 1000 KB 1000 KB 🎉 -6 B 🎉
Dependency size 36.82 MB 36.88 MB 🚨 +60 KB 🚨
Bundle Size Analyzer node node

@ndelangen
Copy link
Member

Hey @kroeder Do you want to schedule a pairing session about this?
https://scheduler.zoom.us/norbert-de-langen

@storybookjs storybookjs deleted a comment from coderabbitai bot Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants