Skip to content

Core: Ignore story-like directories in indexer#34806

Merged
valentinpalkovic merged 2 commits into
storybookjs:nextfrom
MukundaKatta:codex/storybook-ignore-story-directories
May 19, 2026
Merged

Core: Ignore story-like directories in indexer#34806
valentinpalkovic merged 2 commits into
storybookjs:nextfrom
MukundaKatta:codex/storybook-ignore-story-directories

Conversation

@MukundaKatta
Copy link
Copy Markdown
Contributor

@MukundaKatta MukundaKatta commented May 15, 2026

What I did

  • Prevented StoryIndexGenerator.findMatchingFiles from returning files nested inside directories whose names match the configured story glob.
  • Preserved the existing shared glob options, including the node_modules ignore.
  • Added a regression fixture for a screenshot directory named Button.stories.tsx and assert neither the directory nor its nested Primary.png file is indexed.

Fixes #28954.

Testing

  • git diff --check
  • yarn oxfmt --check code/core/src/core-server/utils/StoryIndexGenerator.ts code/core/src/core-server/utils/StoryIndexGenerator.test.ts
  • node --input-type=module globby check confirming **/*.stories.tsx/** ignores nested files under Button.stories.tsx/

Local test note

I installed dependencies with yarn install --immutable, then tried the focused Vitest file. The root config failed locally because @storybook/addon-vitest/dist/vitest-plugin/index.js was not resolvable, and the direct core config failed to resolve storybook/internal/common from the unbuilt workspace. I did not claim the full Vitest suite as passing locally.

Summary by CodeRabbit

  • Bug Fixes

    • Matching now returns only file paths (not directories), preventing directory names from being treated as story files during index generation.
  • Tests

    • Added a test to ensure story-like directories and screenshot files are excluded from matched results.

Review Change Stack

@valentinpalkovic valentinpalkovic marked this pull request as ready for review May 15, 2026 20:03
@valentinpalkovic valentinpalkovic self-assigned this May 15, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 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: 3380d3ab-62ba-4b50-bb24-08ffa22f1c04

📥 Commits

Reviewing files that changed from the base of the PR and between 5ee7e9a and c7958d6.

📒 Files selected for processing (1)
  • code/core/src/core-server/utils/StoryIndexGenerator.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/core/src/core-server/utils/StoryIndexGenerator.ts

📝 Walkthrough

Walkthrough

findMatchingFiles now passes onlyFiles: true to globby so directories are excluded from matches; a new test verifies story-like directories (and their artifacts) are not returned by the function.

Changes

Story File Indexing

Layer / File(s) Summary
Core behavior: globby onlyFiles configuration
code/core/src/core-server/utils/StoryIndexGenerator.ts
findMatchingFiles now uses onlyFiles: true when calling globby, ensuring only file paths are returned and directories are excluded.
Test coverage: directory exclusion validation
code/core/src/core-server/utils/StoryIndexGenerator.test.ts
Adds existsSync import and a Vitest case that asserts a story-like directory artifact exists and verifies findMatchingFiles does not include the directory or artifact as keys.

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant FS
  participant StoryIndexGenerator
  participant globby
  Test->>FS: ensure Primary.png exists at src/__screenshots__/Button.stories.tsx/Primary.png
  Test->>StoryIndexGenerator: invoke findMatchingFiles('stories.tsx')
  StoryIndexGenerator->>globby: call globby(...) with onlyFiles: true
  globby-->>StoryIndexGenerator: returns file-only paths
  StoryIndexGenerator-->>Test: returns files map (no directory or Primary.png keys)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • storybookjs/storybook#33241: Modifies StoryIndexGenerator.findMatchingFiles's globby invocation related to negated globs handling in the same code area.
  • storybookjs/storybook#32990: Also changes StoryIndexGenerator.findMatchingFiles's globby call/options for CWD/pattern handling, affecting the same function.

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.

@MukundaKatta MukundaKatta changed the title fix: ignore story-like directories in indexer Core: Ignore story-like directories in indexer May 15, 2026
@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented May 19, 2026

Package Benchmarks

Commit: c7958d6, ran on 19 May 2026 at 14:04:33 UTC

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

storybook

Before After Difference
Dependency count 72 60 🎉 -12 🎉
Self size 20.30 MB 20.52 MB 🚨 +221 KB 🚨
Dependency size 36.17 MB 32.84 MB 🎉 -3.34 MB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 536 536 0
Self size 662 KB 651 KB 🎉 -12 KB 🎉
Dependency size 61.20 MB 61.20 MB 🎉 -103 B 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 203 194 🎉 -9 🎉
Self size 908 KB 908 KB 0 B
Dependency size 87.59 MB 84.57 MB 🎉 -3.02 MB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 196 187 🎉 -9 🎉
Self size 32 KB 32 KB 0 B
Dependency size 86.08 MB 83.06 MB 🎉 -3.02 MB 🎉
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 73 61 🎉 -12 🎉
Self size 1.08 MB 1.08 MB 🎉 -2 KB 🎉
Dependency size 56.48 MB 53.36 MB 🎉 -3.12 MB 🎉
Bundle Size Analyzer node node

The original PR added `${globPattern}/**` as a globby ignore pattern to
prevent story-like directories from being indexed. However, micromatch's
`/**` suffix can match zero-length trailing paths, causing the pattern to
also match the story files themselves. This caused ALL stories to be
ignored, resulting in 44 test failures and all sandbox dev/e2e/chromatic
CI failures.

The correct fix is to rely on globby's `onlyFiles: true` option (which is
the fast-glob default but is now explicit) to prevent directories from
being returned. This correctly excludes the `Button.stories.tsx` directory
from being indexed while keeping all legitimate story files.

Note: A secondary attempt with `${globPattern}/**/*` also failed because
globby tries to stat() the ignore pattern path and throws ENOTDIR when
the pattern resolves through an actual file (e.g., errors/A.mdx/**/*).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@valentinpalkovic valentinpalkovic merged commit 1880dba into storybookjs:next May 19, 2026
132 of 134 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Storybook index crashes when directories match glob as stories

3 participants