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.

Addon-controls: Improve select arg serialization

See original GitHub issue
As a developer,
I want to use non-serializable objects in controls,
so that I can choose between different {images, react components, etc.}

Currently, all keys and values must be JSON serializable (telejson-serializable, actually), which is a serious restriction when components can take arbitrary blob values / complex functions as their inputs.

If we modify the select arg serialization, we can make use of the existing API to support non-serializable objects.

Consider the following example:

export default {
  component: YourComponent,
  title: 'A complex case with a function',
  // creates specific argTypes with options
  argTypes: {
    propertyA: {
      control: {
        type: 'select',
        options: {
          One: <Foo />,
          Two: <Bar />
          Three: </Baz>
        },
      },
    },
  },
};

Currently this will fail because we try to serialize <Foo/>, <Bar/>, and <Baz/>, which are non-serializable. However, if we updated the behavior to serialize One, Two, and Three, and then did a lookup in the options map before the arg values were passed into the story rendering function, then the user could use any value.

This would be a non-breaking change because the serialization behavior is currently an implementation detail.

Fixing this will also mitigate the security restrictions introduced in URL handling: #13803

┆Issue is synchronized with this Asana task by Unito

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
shilmancommented, Mar 1, 2021

@ghengeveld chatted with @tmeasday about this today. his suggestion (which I think makes sense) is to make this a feature of args. So

argTypes: {
  foo: {
    // typical argType stuff
    control: { type: 'select', options: { key1: 'val1', key2: 'val2' }
    mapping: {
      val1: <SomeComplexValue />,
      val2: () => someFunction,
      ...
    }
  }
}

Then it would be up to the StoryStore to transform the serializable values into the complex values before the story is rendered. WDYT?

0reactions
shilmancommented, Mar 9, 2021

Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.2.0-beta.12 containing PR #14169 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there’s still more to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@storybook/addon-controls - npm
This section is a step-by-step walkthrough for how to upgrade your stories. It takes you from a starting point of the traditional "no...
Read more >
@storybook/addon-controls | Yarn - Package Manager
Storybook Controls gives you a graphical UI to interact with a component's arguments dynamically, without needing to code. It creates an addon panel...
Read more >
Controls - Storybook - JS.ORG
Storybook will automatically generate UI controls based on your args and what it ... Choosing the control type ... Essential addon Controls using...
Read more >
Storybook problem while migrating argument of type object ...
I'm having some trouble migrating one thing from the old addon-knobs to the new controls. Let me explain, maybe it's not such difficult...
Read more >
https://raw.githubusercontent.com/storybooks/story...
... URL args ([#14511](https://github.com/storybookjs/storybook/pull/14511)) - UI: ... Maintenance - Addon-controls: Improve color picker UI and migrate to ...
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