Skip to content

Manifests: Fix Attached MDX causing wrong component entries#34101

Merged
JReinhold merged 3 commits into
nextfrom
jeppe/fix-manifest-attached-mdx
Mar 11, 2026
Merged

Manifests: Fix Attached MDX causing wrong component entries#34101
JReinhold merged 3 commits into
nextfrom
jeppe/fix-manifest-attached-mdx

Conversation

@JReinhold
Copy link
Copy Markdown
Contributor

@JReinhold JReinhold commented Mar 11, 2026

Closes #

What I did

This PR fixes an issue where attached MDX files would sometimes cause the manifest generator to point component entries to the wrong stories file.

It also fixes a bug in StoryIndexGenerator, where it wouldn't correctly sort storiesImports and put the "primary" story (as defined via <Meta of={PrimaryStoryFile} />) first in the array, even though it should.

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

See unit tests

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 pull request has been released as version 0.0.0-pr-34101-sha-6ae40b39. Try it out in a new sandbox by running npx storybook@0.0.0-pr-34101-sha-6ae40b39 sandbox or in an existing project with npx storybook@0.0.0-pr-34101-sha-6ae40b39 upgrade.

More information
Published version 0.0.0-pr-34101-sha-6ae40b39
Triggered by @JReinhold
Repository storybookjs/storybook
Branch jeppe/fix-manifest-attached-mdx
Commit 6ae40b39
Datetime Wed Mar 11 12:41:35 UTC 2026 (1773232895)
Workflow run 22953067254

To request a new release of this pull request, mention the @storybookjs/core team.

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

Summary by CodeRabbit

  • Bug Fixes

    • Consistently prioritize Meta (CSF) story sources when multiple story files are referenced.
    • Ensure story entries take precedence over attached docs for the same component so the canonical story is used.
  • Tests

    • Added test coverage verifying Meta import/order prioritization.
    • Added test coverage validating story-over-docs precedence in component manifest generation.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 11, 2026

View your CI Pipeline Execution ↗ for commit 6ae40b3

Command Status Duration Result
nx run-many -t compile -c production --parallel=1 ✅ Succeeded 4m 51s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-11 12:55:52 UTC

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes React component manifest generation when attached MDX docs are present, ensuring component entries resolve to the correct CSF stories file and that attached docs storiesImports ordering correctly prioritizes the <Meta of={...} /> target.

Changes:

  • Update React manifest generation to select a single “best” index entry per component id, preferring CSF story entries over attached-MDX docs entries.
  • Fix StoryIndexGenerator dependency ordering so storiesImports[0] is the “primary” CSF file referenced by <Meta of={...} />.
  • Add regression tests + mock MDX fixture covering both failure modes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
code/renderers/react/src/componentManifest/generator.ts Replaces uniqBy selection with deterministic component-entry selection that prefers story entries over attached docs for the same component id.
code/renderers/react/src/componentManifest/generator.test.ts Adds a regression test ensuring story entries win over attached-MDX docs entries when both exist.
code/core/src/core-server/utils/mockdata/complex/MetaOfImportOrder.mdx New fixture where import order differs from <Meta of={...} /> target, to validate storiesImports ordering.
code/core/src/core-server/utils/StoryIndexGenerator.ts Fixes sorting of docs dependencies so the <Meta of={...} /> story file is placed first in storiesImports.
code/core/src/core-server/utils/StoryIndexGenerator.test.ts Adds a regression test asserting the correct storiesImports order for the new MDX fixture.

You can also share your feedback on Copilot code review. Take the survey.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 11, 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: ee2bf45b-feba-40e7-a9aa-35417841fbc6

📥 Commits

Reviewing files that changed from the base of the PR and between 3baeeeb and 6ae40b3.

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

📝 Walkthrough

Walkthrough

Prioritizes CSF (story) files when resolving docs of={} imports by tracking a meta-containing dependency and reordering dependencies; also adds selection logic to prefer story manifest entries over docs-attached entries and includes tests and fixture to validate ordering.

Changes

Cohort / File(s) Summary
Story Index Generator - Core Logic
code/core/src/core-server/utils/StoryIndexGenerator.ts, code/core/src/core-server/utils/StoryIndexGenerator.test.ts
Adds metaDependency tracking during docs extraction and reorders sortedDependencies to place the CSF-containing dependency first; adds a test ensuring Meta CSF import appears first in storiesImports regardless of import order.
Story Index Generator - Test Fixture
code/core/src/core-server/utils/__mockdata__/complex/MetaOfImportOrder.mdx
Adds MDX fixture that imports two story files and asserts A.stories (Meta) must be listed first in storiesImports even if imported second.
Component Manifest - Core Logic & Tests
code/renderers/react/src/componentManifest/generator.ts, code/renderers/react/src/componentManifest/generator.test.ts
Introduces selectComponentEntries helper to aggregate/choose manifest entries by component id, preferring story entries over docs-attached entries; replaces prior deduplication and adds test verifying precedence.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs


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/core-server/utils/__mockdata__/complex/MetaOfImportOrder.mdx`:
- Around line 7-9: The wording in the MDX fixture is incorrect: it currently
says "even when it is not the last import" but since AStories (A.stories) is
imported second it is actually the last import; update the sentence to "even
when it is not the first import" (or alternatively reorder the import statements
so A.stories is first). Locate the text referencing A.stories, AStories and
storiesImports in MetaOfImportOrder.mdx and change the phrase accordingly to
keep the fixture self-explanatory.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5f5e42bf-e7a3-4e75-833a-c42a4c2fbf38

📥 Commits

Reviewing files that changed from the base of the PR and between 2f7360f and 3baeeeb.

📒 Files selected for processing (5)
  • code/core/src/core-server/utils/StoryIndexGenerator.test.ts
  • code/core/src/core-server/utils/StoryIndexGenerator.ts
  • code/core/src/core-server/utils/__mockdata__/complex/MetaOfImportOrder.mdx
  • code/renderers/react/src/componentManifest/generator.test.ts
  • code/renderers/react/src/componentManifest/generator.ts

Comment thread code/core/src/core-server/utils/__mockdata__/complex/MetaOfImportOrder.mdx Outdated
…ortOrder.mdx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@JReinhold JReinhold merged commit 63009c0 into next Mar 11, 2026
122 of 129 checks passed
@JReinhold JReinhold deleted the jeppe/fix-manifest-attached-mdx branch March 11, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal manifest Component manifest generation story index

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants