question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Controls: Rework default value handling

See original GitHub issue

Instead 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 undefined and reset
  • We need an ArgEnhancer construct that mirrors the ArgTypeEnhancer so that addons can add values
  • addon-actions needs to move from ArgTypeEnhancer to ArgEnhancer
  • The control logic must be updated to only initialize using args, not argType.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 argTypes.x.defaultValue to set args.x automatically? => YES

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
shilmancommented, Apr 23, 2021

@ThibaudAV great point 🤦

i’ll sleep on it and see if i can come up with something better

1reaction
shilmancommented, Jul 19, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Set default values for fields or controls - Microsoft Support
This article explains how to set a default value for a table field or for a control on a form in an Access...
Read more >
Warning: Use the 'defaultValue' or 'value' props on <select ...
React uses value instead of selected for consistency across the form components. You can use defaultValue to set an initial value.
Read more >
Default Value (DriveWorks Documentation)
Default Value. The Default Value property sets an initial value to the control while allowing a new value to be entered or selected...
Read more >
How do I... Base a control's default value on data input?
Enter a new date to update the control's Default Value property. ... Be sure to test the code thoroughly and add error-handling routines...
Read more >
Creating parameter defaults in Amazon QuickSight
If there are multiple values a default field for a user entity, the single-value control for that field displays the static default instead....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found