storybook: [Bug]: Storybook 7.x storysource addon doesn't show whole story code
Describe the bug
I have a problem with the Storybook addon Storysource after migration from Storybook 6.x to Storybook 7.x. In Storybook 6.x I was able to see the whole story code, but now I am able only to see args content.
To Reproduce
here is repo: https://github.com/Podlipny/storybook-storysource-issue
just npm i and npm storybook, tab code should contain whole story code
System
Storybook 7 and newer
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 50
- Comments: 45 (5 by maintainers)
thanks for response guys, We’ve been able to make it work with this inside `.storybook/preview
I am also seeing this issue on v7.5. The information outlined in “Displaying full source” on the landing page does not appear to make a difference.
@valentinpalkovic, The end goal isn’t to see other stories’ source code, but to see the full component code of the corresponding story that is selected. Right now, we’re just seeing the args.
Screenshot of the current result:
Compared to the desired (screenshot pulled from the Storysource landing page gif)
is there any update? it seems that there is a lot of issues with the show code , source code mechanism
This is still happening on the latest storybook version 8.6.12
addon-storysourcehas been deprecated. As of Storybook 9, it has been replaced by the addon-docs code panel, which provides more snippet options. Please see migration guide.Also having this problem.
It’s a monorepo using
@storybook/addon-essentials, I have a root configuration which is referenced in the leaf packages for individual component projects. When I was migrating to SB7, some of the stories would have this problem. Others would render as expected. It wasn’t immediately clear to me what the difference between the projects was; they are have the same or share configurations between them with varying degrees of upkeep.Checking today, now they are all having this problem. I don’t know what has caused this update, since there’s different kinds of changes happening in the repo all the time.
Referring to the documentation as @SalahAdDin suggested, there is a mention in the
@storybook/addon-storysourcedocs with the following message:The examples there are confusing to me. It suggests that
@storybook/addon-docshas an option calledsourceLoaderOptions. Visiting the docs for that plugin (which is inside of@storybook/addon-essentials) has no mention of that option; onlycsfPluginOptionsandmdxPluginOptions.So if one was to update the behavior through options within
@storybook/addon-essentials, what is the correct configuration?It does not work for us.
I also encountered the same problem while displaying a source code by using storysource. Has anyone got the solutions of it ??
Hey, guys! We’ve also encountered this issue in 8.3.3, and did a little analysis, here are the results (to clarify, there are screenshots with storysource-addon code below).
In 7.5.2 we have
storySource.sourcewith full file content in story’s parameters, this is convenient because in this case we see all scope for the current story. We would like to have this behaviour, at least it should be managed by parameter. Expected resultIn 8.1.10 we don’t have
storySourceanddocs.source.originalSourceproperties at all and just see"loading source..."in code panel.In 8.3.3 we also don’t have
storySourceproperty, and we could work only withdocs.source.originalSourcethat just refers to object with arguments for story. This is not convenient especially for basic story (in this case we just have empty object as code for the story). Actual resultStorybook config
preview.ts
It seems that some changes in source-loader between 7.5.2 and 8.1.10 (8.3.3) have led to the current behavior. So here are two questions
showFullSource) for source-loader. If this is a bug, I could and I would like to contribute and help.@shilman @valentinpalkovic
It’s still happening on my project, but less so than I reported earlier. Out of 70 components, this seems to affect 7 of them. Also noticed this because where it happens, the Storybook Controls are inert in the docs. More specifically, the first story in the file used as the docs example renders knobs that do nothing. And the code shows precisely what is written in source instead of what is meant to be written as a component.
Note that I have plenty of other stories that utilize
renderthat do not have this problem. I’m well aware therenderfunction I’m giving in this example seems excessive. I’ve omitted the parts within for the sake of simplicity in the example. I also have a component that simply displays{}as is in the source.Also note that if I fire up the local Storybook for examples that do not work, the Storybook Controls do work on the individual story pages. In my setup, this seems to be a problem specifically when rendering docs for certain components that don’t seem to be different from others that are working.
Any updates?
@brynshanahan Alright, thanks!
Also I’ve made workaround that works for me to view the file source code:
@oeem1011 I also ran in into a similar issue when trying out a few tactics. My initial thought was to simply convert the exported component into a string:
But like you said it coverts the code. It might work for some crude use-cases, but isn’t a great option.
Could anyone find a workaround to this issue? 😦
We managed to fix this issue. We tracked it down to React contexts being imported twice from the same package, in one build we were getting
module.cjsandmodule.mjsof the same module. The culprit was our custom Rollup resolver plugin. We were able to fix it by changing our custom resolver plugin to usethis.resolveso it would use Vite’s default resolving rather than just straightrequire.resolveAny updates?
@Zlvsky if you check out @sashathor’s branch it appears they’ve used a custom component that parses the story source instead of relying on the <Canvas/> component
after upgrading to storybook 8, still running into the same issue 😦
Since upgrading to Storybook v8 I can only see the current story source, and there is no way to reveal the full story source.
This issue appears to be fixed in 8.x but it would be nice if a fix is made available for those who can’t upgrade yet 🙏
I found that there is a storySource parameter you can add to override what the rendered story code can be.
For example:
Button.stories.tsBased on how the addon works, it looks like it tries to load the loaderSource first, then defaults to an object of the args:
/core/addons/storysource/src/StoryPanel.tsxSeeing the same issue:
Output shows the following:
versus the desired:
The code preview in the doc view works just fine, which is ultimately what I want in the addon view that updates with the controls.