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.

Docs addon eval breaking Storybook Composition for certain prop default values

See original GitHub issue

I’ve discovered an issue with the Docs addon while attempting to set up my team’s Storybook for Storybook Composition. This issue is always at play, it just doesn’t become immediately apparent until you try to compose the Storybook.

React Docgen produces default values as strings, so @shilman added an eval to extractArgTypes in https://github.com/storybookjs/storybook/pull/10812. This works well most of the time, however it produces undesirable behavior when the default value is a string that matches something that exists on the window object.

In my case, I was trying to compose a Storybook with a Tooltip component that has a placement prop with the default 'top'. Since window.top provides a reference to the topmost window in the window hierarchy, this makes the Docs addon set the arg default to window. Try it yourself - run eval('top') in the console. Within that Storybook I haven’t noticed any issues, however when you try to compose it in another Storybook, you get an error when the composing storybook tries to serialize the window object from another origin: Uncaught DOMException: Blocked a frame with origin from accessing a cross-origin frame.. You can see more info about my exploration of this issue in this comment. I opened a new issue because the one I linked originally relates to the actions addon (whereas this is an issue with docs).

Unfortunately, disabling the Docs addon for a specific story or set of stories is not an option, as the arg types seem to be extracted for every story regardless of this. The only way I can get Storybook Composition to work is by disabling the Docs addon entirely or by changing the default value of our component’s placement prop (a breaking change that we would like to avoid).

If I wrap the try/catch in a conditional, everything works as expected:

let defaultValue = defaultSummary && (defaultSummary.detail || defaultSummary.summary);

if (!(defaultValue in window)) {
  try {
    defaultValue = eval(defaultValue);
  } catch (_unused) {}
}

This is completely blocking us from using Composition. I’d be willing to submit a PR with some guidance, however I’m not sure if the above snippet is the best approach. Alternatively, we could use JSON.parse instead of eval, but it depends what other inputs you expect (there are no tests to reference that I can find). Would love some feedback! Thanks 🙂


To Reproduce Steps to reproduce the behavior:

  1. Set up a storybook with @storybook/addon-docs enabled
  2. Add a story for a component with a prop that has a default value of a string that exists on the window object (e.g. 'top', 'confirm', etc.)
  3. Compose that storybook in another storybook
  4. Inspecting the arg types generated for the story, you will see that the default for that prop is window.
  5. Get the Uncaught DOMException: Blocked a frame with origin "http://localhost:9009" from accessing a cross-origin frame. error when loading that story in a composing Storybook.

Expected behavior The default for the arg should be interpreted as expected (a string). Serializing stories across origins (for composition) should work as intended.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
shilmancommented, May 6, 2021

Should be fixed in 6.3 by #14579

1reaction
shilmancommented, Mar 9, 2021

@anicholls I think there’s already an issue for this, so please look for it or open a new one and I can de-dupe. Thanks!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

DocsPage - Storybook - JS.ORG
It aggregates your stories, text descriptions, docgen comments, args tables, and code examples into a single page for each component. The best practice...
Read more >
HTML Standard
1 Introduction; 2 Common infrastructure; 3 Semantics, structure, and APIs of HTML documents; 4 The elements of HTML; 5 Microdata; 6 User interaction ......
Read more >
Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Default value for a database column; 4.5. Columns unique constraint; 4.6. Columns index. 5. Persistence Context. 5.1. Accessing Hibernate APIs from JPA ...
Read more >
TinkerPop Documentation
It is fairly certain that readers of the Reference Documentation are coming ... A vertex property can have standard key/value properties attached to...
Read more >
NWCG Standards for Interagency Incident Business ...
applicable procurement regulations. • Management and tracking of government property. • Financial coordination with the jurisdictional agency and ...
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