Skip to content

Search: show Docs icon for standalone docs pages in search results#34311

Open
mixelburg wants to merge 1 commit intostorybookjs:nextfrom
mixelburg:fix/search-docs-icon-34288
Open

Search: show Docs icon for standalone docs pages in search results#34311
mixelburg wants to merge 1 commit intostorybookjs:nextfrom
mixelburg:fix/search-docs-icon-34288

Conversation

@mixelburg
Copy link
Copy Markdown
Contributor

@mixelburg mixelburg commented Mar 24, 2026

Closes #34288

What I did

Standalone MDX docs pages (e.g. Configure.mdx, any page without <Meta of={SomeComponent} />) were showing the Component icon in search results instead of the Docs icon.

Root cause: transformStoryIndexToStoriesHash creates an intermediate type: 'component' parent entry for docs pages that stand alone (not attached to a component). When a user searched for such a page, Fuse.js matched both the parent component entry and the docs entry. The deduplication filter passed the component entry first (better score / processed first), then blocked the docs entry because its parent ID was already in resultIds.

Fix: In getResults, before adding a component entry to resultIds, check if all its children are docs entries. If so, skip the component entry entirely — the docs child then passes through the filter and is rendered with the correct Docs (document) icon.

Also adds a SearchingDocPage story in SearchResults.stories.tsx to provide visual regression coverage for this case.

Checklist for Contributors

Testing

  • stories

Manual testing

To reproduce before this fix: in a default Storybook sandbox (react-vite/default-ts), search for "Configure your". The result shows a Component icon. After the fix, it shows the Docs icon.

Summary by CodeRabbit

  • Bug Fixes

    • Updated search results filtering to exclude components that contain exclusively documentation entries, preventing unwanted docs-only components from appearing in search results. Also updated filtering dependencies for consistency and accuracy.
  • Tests

    • Added new Storybook test coverage for documentation-only search results, ensuring proper rendering and icon/label behavior for search items containing documentation content.

Standalone MDX docs pages (e.g. Configure.mdx) were being shown with the
Component icon in search results. The root cause: transformStoryIndexToStoriesHash
creates an intermediate 'component' entry as the parent of the docs entry.
When both entries matched a search query, the component entry won the deduplication
filter (by scoring higher), blocking the docs entry via the parent-ID check.

The fix skips docs-only component entries (those whose children are exclusively
docs entries) so their docs child passes through the filter instead, correctly
rendering with the Docs (document) icon.

Also adds a SearchingDocPage story to prevent regression.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

This PR updates search results filtering logic to exclude components whose children are exclusively docs entries, preventing docs-only items from appearing in results. The getResults hook dependencies are expanded to include dataset. Additionally, a new Storybook story is added to test docs-only search result rendering.

Changes

Cohort / File(s) Summary
Search Filtering Logic
code/core/src/manager/components/sidebar/Search.tsx
Updated filtering to exclude "component" items whose children are all "docs" entries. Expanded getResults hook dependencies to include dataset for proper reactivity with dataset changes.
Storybook Test Story
code/core/src/manager/components/sidebar/SearchResults.stories.tsx
Added new story export SearchingDocPage that renders SearchResults with a docs-only search item (type: 'docs', refId: 'internal') to provide test coverage for MDX page result rendering.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes


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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/core/src/manager/components/sidebar/Search.tsx`:
- Around line 225-231: The docs-only guard in Search.tsx incorrectly treats an
empty children array as docs-only because item.children.every(...) is true for
[]; update the condition in the component filtering block (the if that checks
item.type === 'component' and 'children' in item) to require a non-empty
children array (e.g., item.children.length > 0) before evaluating
dataset.hash[item.refId]?.index and index[childId]?.type === 'docs', so only
components with at least one child are considered for the docs-only exclusion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4ea928ea-ca99-4a02-a781-d859823e8ab5

📥 Commits

Reviewing files that changed from the base of the PR and between 09a3460 and bc28cac.

📒 Files selected for processing (2)
  • code/core/src/manager/components/sidebar/Search.tsx
  • code/core/src/manager/components/sidebar/SearchResults.stories.tsx

Comment on lines +225 to +231
// Skip docs-only components so their docs child can show the Docs icon instead
if (item.type === 'component' && 'children' in item && Array.isArray(item.children)) {
const index = dataset.hash[item.refId]?.index;
if (index && item.children.every((childId) => index[childId]?.type === 'docs')) {
return false;
}
}
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.

⚠️ Potential issue | 🟡 Minor

Guard the docs-only check against empty children.

At Line 228, item.children.every(...) is vacuously true for [], so a component with zero children would be filtered out even though it is not “docs-only.” Add a non-empty guard.

💡 Suggested patch
-          if (index && item.children.every((childId) => index[childId]?.type === 'docs')) {
+          if (
+            index &&
+            item.children.length > 0 &&
+            item.children.every((childId) => index[childId]?.type === 'docs')
+          ) {
             return false;
           }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Skip docs-only components so their docs child can show the Docs icon instead
if (item.type === 'component' && 'children' in item && Array.isArray(item.children)) {
const index = dataset.hash[item.refId]?.index;
if (index && item.children.every((childId) => index[childId]?.type === 'docs')) {
return false;
}
}
// Skip docs-only components so their docs child can show the Docs icon instead
if (item.type === 'component' && 'children' in item && Array.isArray(item.children)) {
const index = dataset.hash[item.refId]?.index;
if (
index &&
item.children.length > 0 &&
item.children.every((childId) => index[childId]?.type === 'docs')
) {
return false;
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/manager/components/sidebar/Search.tsx` around lines 225 - 231,
The docs-only guard in Search.tsx incorrectly treats an empty children array as
docs-only because item.children.every(...) is true for []; update the condition
in the component filtering block (the if that checks item.type === 'component'
and 'children' in item) to require a non-empty children array (e.g.,
item.children.length > 0) before evaluating dataset.hash[item.refId]?.index and
index[childId]?.type === 'docs', so only components with at least one child are
considered for the docs-only exclusion.

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.

[Bug]: Searching docs stories renders the wrong icon type

1 participant