Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index: Fix MDX to override project-level autodocs #28461

Merged
merged 2 commits into from
Jul 5, 2024

Conversation

shilman
Copy link
Member

@shilman shilman commented Jul 5, 2024

Closes N/A

What I did

Fixed a regression introduced by the 8.1 tags work. Previously, you could set docsOptions.autodocs = true in main.js and then override the autodocs at a component level by adding MDX.

Starting in 8.1, we deprecated docsOptions.autodocs and converted to tags. We automigrated docsOptions.autodocs = true to tags: ['autodocs'] in .storybook/preview.js, which is the new equivalent. However, the code to allow overriding project-level autodocs with MDX was not updated.

I also updated all the docsOptions.autodocs = true tests to have tags = ['autodocs'] equivalents. We can delete the old ones in 9.0.

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

In a sandbox, write MDX for the button component:

{/* stories/Button.mdx */}
import { Meta, Canvas } from '@storybook/blocks';
import * as ButtonStories from './Button.stories';

<Meta of={ButtonStories} />

# Button

<Canvas of={ButtonStories.Primary} />
  • In the old code this will crash with an error You created a component docs page for '${worseEntry.title}', but also tagged the CSF file with '${AUTODOCS_TAG}'. This is probably a mistake.,
  • In the new code this will also error, because the user has explicitly tagged the component with autodocs.

Now set tags: ['autodocs'] in .storybook/preview.ts

  • In the old code this will also error.
  • In the new code, this will override the component's autodocs with MDX.

🦋 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 canary-release-pr.yml --field pr=<PR_NUMBER>

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Updated chooseDuplicate method in /code/core/src/core-server/utils/StoryIndexGenerator.ts to handle project-level autodocs tags.
  • Enhanced getProjectTags method in /code/core/src/core-server/utils/StoryIndexGenerator.ts to correctly parse and include autodocs tags.
  • Added test cases in /code/core/src/core-server/utils/StoryIndexGenerator.test.ts for scenarios with 'autodocs' tags at project and component levels.
  • Verified that MDX files can override project-level autodocs settings in new tests.
  • Ensured autogenerated docs entries correctly include 'autodocs' tags.

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

@@ -709,7 +712,7 @@ export class StoryIndexGenerator {
}

getProjectTags(previewCode?: string) {
let projectTags = [];
let projectTags = [] as Tag[];
Copy link
Contributor

Choose a reason for hiding this comment

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

🪶 style: Explicitly typed projectTags as Tag[].

@shilman shilman self-assigned this Jul 5, 2024
Copy link

nx-cloud bot commented Jul 5, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 14ef5cc. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@@ -506,7 +506,7 @@ export class StoryIndexGenerator {
}
}

chooseDuplicate(firstEntry: IndexEntry, secondEntry: IndexEntry): IndexEntry {
chooseDuplicate(firstEntry: IndexEntry, secondEntry: IndexEntry, projectTags: Tag[]): IndexEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

Adjustment in src/core-server/utils/StoryIndexGenerator.test.ts:1530:21 also necessary

@shilman shilman merged commit d956ca6 into next Jul 5, 2024
54 checks passed
@shilman shilman deleted the shilman/fix-mdx-autodocs-conflict branch July 5, 2024 11:16
@github-actions github-actions bot mentioned this pull request Jul 5, 2024
9 tasks
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.

None yet

2 participants