-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Docs addon eval breaking Storybook Composition for certain prop default values #13608
Comments
I believe this was fixed in #13919 Closing. Please comment if you're still seeing the issue in 6.2-beta! 🙏 |
@shilman Thank you! Much appreciated. I have tried to upgrade to 6.2.0-beta.11 to test and I am having babel issues. On start up I’m getting a bunch of |
@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!! |
I'm on Storybook 6.2 in two separate repositories, composing one (port 9009) into another (port 6006). I get the CORS error |
@shilman I was finally able to upgrade to 6.2.9 after using resolutions and doing some dependency finageling. Now that I was able to test this out, I discovered that the issue is not fixed. This needs to be reopened. The fix in #13919 was to use the following logic: var defaultValueString = defaultSummary && (defaultSummary.detail || defaultSummary.summary);
try {
if (defaultValueString) {
// eslint-disable-next-line no-new-func
defaultValue = Function("\"use strict\";return (".concat(defaultValueString, ")"))();
} // eslint-disable-next-line no-empty
} catch (_unused) {} This does not solve the original use case I provided. Try running |
Should be fixed in 6.3 by #14579 |
@anicholls thanks for looking at this so closely. Just to be clear the fix in #13919 was more than just changing how we What the problem was:
In #13919 I put some code in to workaround 1., as well as getting rid of 2 in some cases (but not all, yet, see #14579). I guess my workarounds are failing in your case. Can you give a bit more detail the exact setup for your component with a default value
Thanks. |
@tmeasday Thanks for the quick response! Re. #14579, initializing optional default values to For our use case: you can have a closer look at the component/file in question here, but I'll share the details to answer your questions below:
Yes
export interface TooltipProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
// ...
/**
* Sets the placement preference used by PopperJS.
* @default 'top'
*/
placement?: Placement;
// ...
} Note: we have tried both
It is initialized in the prop destructure: export const Tooltip = ({
type = 'label',
placement = 'top',
title,
children,
...elemProps
}: TooltipProps) => {
Thanks! |
Hi @anicholls Thanks for the details. There was one crucial thing I needed which was the exact type of In which case it is a union of strings? In theory then that should work. It's complicated because there are a lot of different potentially string valued types that we need to "repair" when RDT gives us the wrong value, and it isn't always possible to actually do that. For instance, suppose you have this type: type Pathological = "true" | true; Then when RDT gives us the string In any case, we did encounter the case of a union of string types and added this code to deal with it: storybook/addons/docs/src/lib/docgen/createPropDef.ts Lines 27 to 45 in f3744e2
It seems that's not working in this case. Perhaps you could investigate why? Or put a simple repro together? There's also just the option of overriding the
We are still going to use the inferred defaultValue string to write down the default values in the table, but it's less crucial there that we get it exactly right. For actual args that are passed into actual components, we are just going to let the framework do its thing when we don't pass any value in the prop. That's what default values are for after all. |
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
toextractArgTypes
in #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 thewindow
object.In my case, I was trying to compose a Storybook with a
Tooltip
component that has aplacement
prop with the default'top'
. Sincewindow.top
provides a reference to the topmost window in the window hierarchy, this makes the Docs addon set the arg default towindow
. Try it yourself - runeval('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:
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 ofeval
, 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:
@storybook/addon-docs
enabled'top'
,'confirm'
, etc.)window
.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.
The text was updated successfully, but these errors were encountered: