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

Don't allow setting Meta of={X} if X is tagged with 'autodocs' #20373

Merged
merged 4 commits into from
Dec 22, 2022

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Dec 22, 2022

Telescoping on #20364

What I did

Throw an error if you use <Meta of={} for autodocs-tagged CSF file.

I'm not 100% sure this should be an error while other "mistakes" are just warnings. WDYT @shilman?

// This shouldn't be possible, but double check and use for typing
if (worseEntry.type === 'story')
throw new DuplicateEntriesError(`Duplicate stories with id: ${firstEntry.id}`, [
firstEntry,
secondEntry,
]);
if (betterEntry.type === 'story') {
const worseDescriptor = worseEntry.standalone
? `component docs page`
: `automatically generated docs page`;
if (betterEntry.name === this.options.docs.defaultName) {
logger.warn(
`🚨 You have a story for ${betterEntry.title} with the same name as your default docs entry name (${betterEntry.name}), so the docs page is being dropped. Consider changing the story name.`
);
} else {
logger.warn(
`🚨 You have a story for ${betterEntry.title} with the same name as your ${worseDescriptor} (${worseEntry.name}), so the docs page is being dropped. ${changeDocsName}`
);
}
} else if (betterEntry.standalone) {
// Both entries are standalone but pointing at the same place
if (worseEntry.standalone) {
logger.warn(
`🚨 You have two component docs pages with the same name ${betterEntry.title}:${betterEntry.name}. ${changeDocsName}`
);
}
// If you link a file to a tagged CSF file, you have probably made a mistake
if (worseEntry.tags?.includes('autodocs'))
throw new Error(
`You created a component docs page for ${betterEntry.title}:${betterEntry.name}, but also tagged the CSF file with 'autodocs'. This is probably a mistake.`
);
// Otherwise the existing entry is created by `autodocs=true` which allowed to be overridden.
} else {

How to test

  • Create a MDX file with <Meta of={..} an autodocs-tagged CSF File.
  • Check it doesn't break in other allowed circumstances (no tag, or autodocs=true)

@tmeasday tmeasday added maintenance User-facing maintenance tasks addon: docs labels Dec 22, 2022
@tmeasday tmeasday marked this pull request as ready for review December 22, 2022 02:51
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

@tmeasday We have another issue to make index errors crash Storybook so I think this is in line with that direction

Base automatically changed from rename-docspage-autodocs to next December 22, 2022 05:45
@tmeasday tmeasday merged commit 485b776 into next Dec 22, 2022
@tmeasday tmeasday deleted the tom/sb-1032-warn-if-setting-tags-docspage-and-then branch December 22, 2022 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: docs maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants