Controls: Rework default value handling
See original GitHub issueInstead of initializing an optional control value to its default value, initialize it to undefined
Rationale
Default value handling is currently problematic in Storybook’s Arg handling.
We statically analyze the code to determine the default value. This is impossible to do statically in all cases, and on top of that there are various inconsistencies between how different libraries handle the output (e.g. string literal vs expression).
This leads to issues such as #14387 #14370 #13919 and many more.
However, since the default value gets set automatically when NO value is passes to the component, passing undefined is a much better option. It sidesteps all the existing issues and the component will use the runtime default value, which will be correct.
What’s needed
A few different things are needed to make this happen:
- All controls must be able to handle
undefinedand reset - We need an ArgEnhancer construct that mirrors the ArgTypeEnhancer so that addons can add values
-
addon-actionsneeds to move from ArgTypeEnhancer to ArgEnhancer - The control logic must be updated to only initialize using
args, notargType.defaultValue - We probably need a migration/deprecation strategy since technically this is a breaking change
- Delete all the old code
Open question:
-
Do we want=> YESargTypes.x.defaultValueto setargs.xautomatically?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (6 by maintainers)

Top Related StackOverflow Question
@ThibaudAV great point 🤦
i’ll sleep on it and see if i can come up with something better
@mboettcher it’s being discussed here FYI https://github.com/storybookjs/storybook/issues/15378