-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Menu: migrate Storybook examples to CSF3 #68204
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hiding whitespace changes removes a lot of noise while reviewing
Flaky tests detected in 2514423. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12435183705
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thanks for the migration @ciampo!
Just left a few questions and things to discuss as I'm getting familiar with the syntax.
@@ -64,300 +64,337 @@ const meta: Meta< typeof Menu > = { | |||
source: { excludeDecorators: true }, | |||
}, | |||
}, | |||
}; | |||
} satisfies Meta< typeof Menu >; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a good reason for this change?
When I run the csf-2-to-3
codemod it keeps that type above, as it was in CSF2.
Try it out on trunk
:
npx storybook@8.4.7 migrate csf-2-to-3 --glob="packages/components/src/menu/stories/index.story.tsx"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also curious. I'd prefer to keep doing it the old way for consistency, if there are no benefits. (I noticed someone recently used satisfies
for the Badge
stories.)
args: { | ||
children: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The csf-2-to-3
codemod would use render: () => { ... }
instead of args.children
. What's the difference? Seems like it allows you to specify the props type inline when passing it to render
:
export const Default: StoryObj< typeof Menu > = {
render: ( props: MenuProps ) => (
<Menu { ...props }>
/// ...
</Menu>
),
args: {},
};
One difference to note is that the codemod uses render:
but also specifically adds this to all stories that inherit from Default
:
args: {
...Default.args,
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was working on some of the TypeScript compilation hotspots, I noticed that not having a render
function is better for performance, since it can bypass a lot of work. So we should avoid render
and prefer children
when possible.
string[] | ||
>( [ 'b' ] ); | ||
export const WithCheckboxes: Story = { | ||
render: function WithCheckboxes( props: MenuProps ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to provide a named function here? Can't we just do:
render: ( props: MenuProps ) => (
<>
//...
</>
),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used named functions to prevent warnings about using hooks outside of a component.
@@ -64,300 +64,337 @@ const meta: Meta< typeof Menu > = { | |||
source: { excludeDecorators: true }, | |||
}, | |||
}, | |||
}; | |||
} satisfies Meta< typeof Menu >; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also curious. I'd prefer to keep doing it the old way for consistency, if there are no benefits. (I noticed someone recently used satisfies
for the Badge
stories.)
args: { | ||
children: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was working on some of the TypeScript compilation hotspots, I noticed that not having a render
function is better for performance, since it can bypass a lot of work. So we should avoid render
and prefer children
when possible.
string[] | ||
>( [ 'b' ] ); | ||
export const WithCheckboxes: Story = { | ||
render: function WithCheckboxes( props: MenuProps ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These parameter types shouldn't be necessary, since that is already handled through the StoryObj<>
generic.
render: function WithCheckboxes( props: MenuProps ) { | |
render: function WithCheckboxes( props ) { |
</Menu> | ||
); | ||
Default.args = {}; | ||
type Story = StoryObj< MenuProps >; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason it's not this?
type Story = StoryObj< MenuProps >; | |
type Story = StoryObj< typeof Menu >; |
What?
Migrate
Menu
's storybook examples to the latest story formatWhy?
Keeping aligned with latest Storybook specs and features, potentially better performance
How?
Followed docs at https://storybook.js.org/docs/api/csf
Testing Instructions
Build storybook locally (
npm run storybook:dev
), make sure that allMenu
stories work as ontrunk