storybook: Regression with default value not being selected in Controls column
Describe the bug We’ve been loving Storybook with our Typescript setup, but after upgrading from 6.2.9 to 6.3.0, we’ve lost the feature to have SB select the default value in the Controls column.
For example, in the demo files produced with npx sb init, a Button.tsx is created.
Its size prop has a default value of medium, but the RadioControl does not select the radio option labeled medium anymore.
To Reproduce
I have a very simple reproduction repo which simply ran npx sb@next repro with no manual configurations.
System Environment Info:
System: OS: macOS 11.4 CPU: (8) x64 Intel® Core™ i7-1068NG7 CPU @ 2.30GHz Binaries: Node: 12.20.2 - ~/rg/community/bin/build/nodejs/bin/node Yarn: 1.22.5 - ~/rg/community/bin/build/yarn/bin/yarn npm: 6.14.11 - ~/rg/community/bin/build/nodejs/bin/npm Browsers: Chrome: 91.0.4472.114 Firefox: 89.0 Safari: 14.1.1
Additional context
I’m not that familiar with SB’s codebase, but what I can tell is that the value prop for RadioControl is undefined.
The only time this is not undefined is when the Story supplies it via the args property, i.e.
const Template: ComponentStory<typeof Button> = (args) => <Button {...args />
const Example1 = Template.bind({});
Example1.args = {
size: 'large'
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (16 by maintainers)
Commits related to this issue
- Pin storybook version to 6.2.9 for now to avoid https://github.com/storybookjs/storybook/issues/15378 — committed to uxpin-merge/storybook-material-ui by naohiro-t 3 years ago
@penx 👋 - so the issue here is that it is setting it to
undefinedrather than not setting it at all?@shilman would it be possible to just not pass any value at all to the props? The current behavior messes with our setup:
This allows us to have:
propsWithDefaultsobject that automatically gets the resolved types for each props, potentially with defaults. E.g. instead of'user' | 'entity' | undefinedthe type gets resolved to'user' | 'entity'which is great since that’s the actual type due to the default, andundefinedis not an option.This worked great for earlier versions of storybook, but now I have two issues:
undefined, the object spread (which will accept any own property, no matter the value) is replacing the default props with undefined.This is an awkward situation, because if you look at the types, the component always expects some props to have a value (for example the
variantprop above), but it comes withundefinedwhich typescript doesn’t even contemplate.Doesn’t it suffice just not setting the props at all? Otherwise, this will force us to either not upgrade or change our whole codebase for a storybook quirk 😕
By the way, I’ve also realized that this is only happening the second time a component is loaded in storybook. The first time, it’s fine. This was one of the biggest head-scratchers I initially found 😛
Thank you!
@tmeasday thanks for your input, I understand better what’s happening now.
Just to be clear, here’s the 3 related behaviors I’ve identified on 6.3 regarding defaults:
I understand that behavior 2 is intended and I understand and appreciate the goal.
However, the other two are problematic in my opinion:
I can attempt to create a repro of behaviors 1 and 3 if that helps. If these behaviors are confirmed, would you consider both to be bugs? Or is anything intentional that I’m missing, especially regarding behavior 3?
Thank you 😃
@penx in your example, your story is defined:
https://github.com/penx/storyshots-default-props/blob/5178570178dafead76bf67a06b7cfe7ea25387ed/src/stories/Footer.stories.jsx#L8
(
export const Default = Footer;)which is wrong (it should be
export const Default = (args) => <Footer {...args} />;)If you make that change, then
(a) in
6.2.9the component renders correctly with all default values. (b) in6.3.4the component also renders correctly with all default values.In (b) I can see the
undefinedvalues getting passed in. For vanilla React this isn’t actually a problem but I agree it is a bug.I agree, perhaps you could open a specific issue for this and we can take a look at it.
They should show up in the table, in the “default value” column, just not in the “control” column. Is that not the case in your examples?
Our thinking is that we could probably make it clearer that this what’s happening (that the control isn’t showing anything because we are using the default), but we aren’t going go back to trying to get proper values for args from strings (such as JSDoc comments) as it is too unreliable.
No, the function could return some arbitrary string, like the name of a variable in your source file.
Here is the documentation: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-argtypedefaultvalue
PRs are very welcome if you have specific ideas on how to make this more clear.
@DaniGuardiola Yes I think that could be a possibility; I’m just not sure about the impact of that change. @tmeasday WDYT?