Replies: 5 comments 9 replies
-
Great to see this 😄 I’ve been putting off keeping up with Storybook updates due to the
I think it’s worth mentioning that from the perspective of a
On databases, or API servers – I’ve also raised this on #23176, I think just worth clarifying whether your RFC here proposes a replacement for this fixture data loading at build time only or both build time and runtime in the browser. As far as I understand it’s just build time.
Could you share your implementation of I think this solves the main use case I had for
|
Beta Was this translation helpful? Give feedback.
-
Hi @shilman I understand the issues and limitations that arise due to the current usage of storiesOf API. But my need is very specific. For my current projects, I want to add CSF, test runners, and assertion-based unit testing (with interactions addon). As all these features are available in later versions of Storybook, that run on Node 16, I cannot switch from Node 14 to 16 as of now due to some project concerns. Is there any way to utilize these new features in the Node 14 environment if not by using StoryOf ? |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the great work on Storybook! I would like to share my thoughts about this RFC. export default { title: 'Button' };
export const Combos = () => {
const propsCombos = generate(); // same as above
<Grid>{propsCombos.map(props => <Button {...props} />)}</Grid>
}; It is a good workaround, but as result it is a single story, and not a separated / isolated stories. So it may lead to issues with snapshot tests, and 1 broken variant will break them all. Stories are great because each of them is isolated and does not affect another one. Storybook Variants Addon is good solution for typical use-case when it is just a 1 component with several arguments and you need to view all combinations at glance. I would recommend to build this into an official Storybook feature at some point in the future. Because it will satisfy most users who uses Indexer API is great but it may be hard to debug/maintain and guarantee stability of stories generated during runtime. Taking into consideration the importance of static analysis and desire of developers to automate everything, I would suggest to review code-gen approach:
import { StoryBuilder } from '@storybook/codegen';
import type { Meta, StoryObj } from '@storybook/react';
import MyComponent from './MyComponent';
const meta: Meta<typeof MyComponent> = {
component: MyComponent,
parameters: { layout: 'centered' },
};
type Story = StoryObj<typeof meta>;
fetch('https://my-api.com/emails')
.then(res => res.json())
.then(emailSettings => {
// generic here is just as example
const builder = new StoryBuilder<Meta<typeof MyComponent>>(meta);
for (const email of emailSettings) {
// generic here is just as example
builder.addStory<Story>({
name: email.type,
args: {
email,
},
});
}
builder.generate();
}); Another example, when I am just lazy to write all stories manually and I know that I have enum with all possible values, so I can generate stories based on it. It is similar to Variants, but in this case each "variant" is a separate story. import { StoryBuilder } from '@storybook/codegen';
import type { Meta, StoryObj } from '@storybook/react';
import { MyEnum } from 'enums';
import MyComponent from './MyComponent';
const meta: Meta<typeof MyComponent> = {
component: MyComponent,
parameters: { layout: 'centered' },
};
type Story = StoryObj<typeof meta>;
const builder = new StoryBuilder(meta);
for (const i in MyEnum) {
builder.addStory<Story>({
name: MyEnum[i],
args: {
value: MyEnum[i],
},
});
}
builder.generate(); So user has all benefits of meta / CSF / types, but also can have dynamic stories. It is a good balance between flexibility and compatibility with all other Storybook Addons and features.
In case of any problems with generated stories - developer will have an ability to play around it, because it is just a generated file, and he can always fix it manually, debug, etc.. Important part that generated stories may be committed to the repository, so it will be available for all developers and any changes caused by fixtures/api may be checked during code review process. @shilman what do you think about such code-gen approach? |
Beta Was this translation helpful? Give feedback.
-
The Stackblitz seems broken at the moment -- Any chance it can be updated? |
Beta Was this translation helpful? Give feedback.
-
I don't think this RFC is still "in review" is it? Hasn't Maybe implemented / finished RFCs should be closed, to avoid confusion? |
Beta Was this translation helpful? Give feedback.
-
Status: in-review; championed by @shilman
Summary
We propose deprecating the StoriesOf API in Storybook 7.1 and removing it completely in 8.0.
We propose three migration paths for existing StoriesOf users:
storiesof-to-csf
codemod or manually.Problem Statement
StoriesOf is the original API for creating stories in Storybook. In Storybook 5.2 (2019) we replaced it with Component Story Format (CSF), which is a simpler, portable, and more performant successor. We provided a utility codemod
storiesof-to-csf
to help users create most StoriesOf stories to CSF.We continued to support StoriesOf for a few reasons:
Four years has been ample time for points (1) and (2). Today, the vast majority of Storybooks use CSF and there are millions of CSF stories in the wild. This RFC focuses on point (3).
But before we jump into that, why is supporting StoriesOf such a problem?
In Storybook 7 we introduced a performance-oriented on-demand architecture called Story Store v7 (SSv7). Unfortunately, SSv7 requires that we are able to statically analyze stories, which is not possible using the StoriesOf API. Therefore, we introduced a legacy mode called Story Store v6 (SSv6) to support StoriesOf.
We want to provide a path forward for StoriesOf users so that we can deprecate StoriesOf in 7.1 and remove it in 8.0. We’ve isolated two main use cases that we’d like to support better in CSF:
Therefore, this RFC focuses on how to achieve these two use cases in a CSF/SSv7 compatible way. We hope this gives existing StoriesOf users a chance to review our approach and give feedback if (1) the proposed solutions aren't suitable, (2) there are other use cases we should consider, (3) there are other approaches we should consider taking.
Non-goals
storiesof-to-csf
migration, which works for many StoriesOf files.Implementation
We propose three paths forward for existing StoriesOf users:
storiesof-to-csf
codemod or manually.CSF
Users can convert their stories to CSF using the
storiesof-to-csf
codemod or manually. Given that CSF is 4 years old already, and that we’ve announced the future deprecation ofstoriesOf
shortly after we released it, we assume that everybody who could take this route has already done so. Therefore, we won’t discuss it further here, but are including for completeness.Indexer API
The Indexer API is a way to programmatically tell Storybook about the existence of stories that can be loaded as CSF. Users or addons can register “indexers” which run in Node and run over files in the user’s
stories
glob inmain.js
. The tricky bit is that when that file gets loaded by Webpack or Vite, it must also be loadable as CSF. This has already been applied to alternative syntaxes for stories, such as a “Svelte-native” story format. The Indexer API is already described in a separate RFC in much more detail.How is this applicable to StoriesOf users? We’ve put together a dynamic stories proof of concept using the Indexer AP:
Please check out the demo to see how it works. It is implemented in a small amount of code on top of the Indexer API:
Note that while we plan to support the Indexer API, we have not released an officially supported package for either of these use cases. The combination of the Indexer API and Storybook’s addon system mean that anybody from the community could create an addon that enables this kind of programmatic story generation.
Variants
The second approach is to capture multiple variants WITHIN a single story. Consider the following
storiesOf
example:This could be rewritten inside a CSF story:
There are existing community variants addons that are usable today.
Variants addon
Permutation table addon
We are also considering building this into an official Storybook feature at some point in the future. If we do this, we’d also provide stylized ways of authoring variants and Variants support across various tooling that we provide.
Prior Art
Mostly listed above
Deliverables
Risks
Unresolved Questions
Alternatives considered / Abandoned Ideas
No response
Beta Was this translation helpful? Give feedback.
All reactions