Skip to content
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

addon-knobs: null default prop is false after page reload #3400

Closed
binomialstew opened this issue Apr 11, 2018 · 3 comments
Closed

addon-knobs: null default prop is false after page reload #3400

binomialstew opened this issue Apr 11, 2018 · 3 comments

Comments

@binomialstew
Copy link

When setting a boolean default prop value, for example, const shouldBeNullByDefault = boolean('Should Be Null By Default', null);, the value is null but changes to false if page is reloaded.

Steps to reproduce

Clone repo:
git@github.com:CLL80/storybook.git

Checkout branch:
knob-test

Run storybook

Go to the withKnobs story:
http://localhost:9011/?selectedKind=Addons%7CKnobs.withKnobs&selectedStory=tweaks%20static%20values

You will see a <h3> that was added at the top of the story. "Should be `null` by default: null".

Reload the page, and null will now be false. This is important because when it is false, the prop will be passed to the component, but if it was null, it would not.

Please specify which version of Storybook and optionally any affected addons that you're running

@storybook/react 4.0.0-alpha.2
@storybook/addon-knobs 4.0.0-alpha.2

I first noticed this issue using v3.3.10.

@mshaaban088
Copy link
Contributor

mshaaban088 commented Apr 16, 2018

Just some insights about this issue, this is happening because:

  • First time the value is null, serialized as 'null' (String), and stored in query-params
  • When you reload the page, the value is loaded
    • First from stories (value is still null)
    • Second from the query params, which has the serialized version of type String, and when the deserialization happens (value === 'true') it ends having value equals to false

See Serialization/Deserialization

@mshaaban088
Copy link
Contributor

I'm going to write a small fix for it

@Hypnosphi
Copy link
Member

Released as 3.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants