CSF: Deprecate duplicate titles rather than forbid it

This commit is contained in:
Michael Shilman 2020-07-09 15:00:04 +08:00
parent be810ddbe6
commit a01e55460f
4 changed files with 21 additions and 14 deletions

View File

@ -19,7 +19,7 @@
- [Removed renderCurrentStory event](#removed-rendercurrentstory-event)
- [Removed hierarchy separators](#removed-hierarchy-separators)
- [Client API changes](#client-api-changes)
- [Removed support for duplicate kinds](#removed-support-for-duplicate-kinds)
- [Deprecated support for duplicate kinds](#deprecated-support-for-duplicate-kinds)
- [Removed Legacy Story APIs](#removed-legacy-story-apis)
- [Can no longer add decorators/parameters after stories](#can-no-longer-add-decoratorsparameters-after-stories)
- [Changed Parameter Handling](#changed-parameter-handling)
@ -401,11 +401,11 @@ addons.setConfig({
### Client API changes
#### Removed support for duplicate kinds
#### Deprecated support for duplicate kinds
In 6.0 we removed the ability to split a kind's (component's) stories into multiple files because it was causing issues in hot module reloading (HMR).
In 6.0 we deprecated the ability to split a kind's (component's) stories into multiple files because it was causing issues in hot module reloading (HMR). It will likely be removed completely in 7.0.
If you had N stories that contained `export default { title: 'foo/bar' }` (or the MDX equivalent `<Meta title="foo/bar">`), Storybook will now throw the error `Duplicate title '${kindName}' used in multiple files`.
If you had N stories that contained `export default { title: 'foo/bar' }` (or the MDX equivalent `<Meta title="foo/bar">`), Storybook will now raise the warning `Duplicate title '${kindName}' used in multiple files`.
To split a component's stories into multiple files, e.g. for the `foo/bar` example above:

View File

@ -9,4 +9,4 @@ import { Button } from '@storybook/react/demo';
// component: Button,
// };
export const basic = () => <Button>Basic</Button>;
export const Basic = () => <Button>Basic</Button>;

View File

@ -1,5 +1,5 @@
import { Meta, Story } from '@storybook/addon-docs/blocks';
import * as stories from './csf-with-mdx-docs.stories';
import { Basic } from './csf-with-mdx-docs.stories';
<Meta title="Addons/Docs/csf-with-mdx-docs" />
@ -7,4 +7,6 @@ import * as stories from './csf-with-mdx-docs.stories';
I can define a story with the function imported from CSF:
<Story name="basic">{stories.basic}</Story>
<Story name="Basic button">
<Basic />
</Story>

View File

@ -16,6 +16,17 @@ const deprecatedStoryAnnotationWarning = deprecate(
`
);
const duplicateKindWarning = deprecate(
(kindName: string) => {
logger.warn(`Duplicate title: '${kindName}'`);
},
dedent`
Duplicate title used in multiple files; use unique titles or a primary file for a component with re-exported stories.
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#removed-support-for-duplicate-kinds
`
);
let previousExports = new Map<any, string>();
const loadStories = (
loadable: Loadable,
@ -111,13 +122,7 @@ const loadStories = (
} = meta;
if (loadedKinds.has(kindName)) {
throw new Error(
dedent`
Duplicate title '${kindName}' used in multiple files; use unique titles or a primary file for '${kindName}' with re-exported stories.
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#removed-support-for-duplicate-kinds
`
);
duplicateKindWarning(kindName);
}
loadedKinds.add(kindName);