-
-
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
[Bug]: Storybook 7.x storysource addon doesn't show whole story code #22922
Comments
This looks like an issue with the AST. I'm making some wild guesses here, but it's probably doing a check inside the Component, and now the component is an object. I wonder if simply changing it to look at |
repo with code to replicate this issue is here: https://github.com/Podlipny/storybook-storysource-issue I am defining story based on storybook documentation, so this should wor without any need to modify anything import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
const meta = {
title: 'Example/Button',
component: Button,
tags: ['autodocs'],
argTypes: {
backgroundColor: { control: 'color' },
},
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const Primary: Story = {
render: () => <Button primary label="Button" />,
args: {
primary: true,
label: 'Button sdsd sdsd sdsds',
},
}; |
Is there any progress and possible workaround on this issue? |
nothing I would know about - we just stopped using storysource until this bug is resolved |
I am also able to reproduce this after migrating from 6.x to 7.5. Cheers! |
Can someone help me to understand the issue? As far as I understand it, in Storybook 6.x the whole Storyfile was outputted as source code. Now, in 7.x, only the code is outputted, which applies to the selected Story. Isn't this the wished behavior? Why should someone be interested in showing the source code from the other Stories when one is selected? Wouldn't this be a mess for huge Story files? I am missing some context here. |
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) |
I also encountered the same problem while displaying a source code by using storysource. Has anyone got the solutions of it ?? |
Seeing the same issue:
Output shows the following: {
args: {
['icon-group']: 'general'
}
} versus the desired: <component-name icon-group="general"></component-name> 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. |
Could anyone find a workaround to this issue? :( |
I found that there is a storySource parameter you can add to override what the rendered story code can be. For example:
Based on how the addon works, it looks like it tries to load the loaderSource first, then defaults to an object of the args:
|
thanks for response guys, We've been able to make it work with this inside `.storybook/preview
|
It does not work for us. |
is there any update? it seems that there is a lot of issues with the show code , source code mechanism |
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 🙏 |
Since upgrading to Storybook v8 I can only see the current story source, and there is no way to reveal the full story source. |
@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. |
after upgrading to storybook 8, still running into the same issue :( |
Sorry to hear that but also glad I didn't go through the upgrade just for this now. Clearly, there's something else going on. |
Any chance this will be fixed in the future? |
Same issue here! @valentinpalkovic there is any chance, please? |
Still actual |
We're also getting this in 7.0 and 8.0. When running the dev server with Vite the story source appears correctly, but then when building for production we get The issue only appears when displaying stories in a custom .mdx file. When using autodocs the source appears correctly which makes me think it's not to do with source parsing? |
It is unfortunate that it is still happening. Our team used to use
|
Any updates/workarounds?:( |
@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 component |
@brynshanahan Also I've made workaround that works for me to view the file source code:
|
Any updates? |
Any updates? |
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 |
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. // Expected in Story Source
<Tabs id='default-tabs' /> // Actual in Story Source
{
args: { id: 'default-tabs' }
render: function Default(args) { return <Tabs { ...args }/> }
} Note that I have plenty of other stories that utilize 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. |
@ddamato is the behavior identical in dev and build modes? |
Yes identical behavior between both. |
@ddamato is this the literal story source? {
args: { id: 'default-tabs' }
render: function Default(args) { return <Tabs { ...args }/> }
} If so, can you try changing it to the following and see if that fixes anything: {
args: { id: 'default-tabs' }
render: (args) => { return <Tabs { ...args }/> }
} |
Yes, that is the literal source. That change doesn't seem to affect the output past showing the new source. |
Is this getting fixed? We really miss the old behaviour of the Storysource in our Project. |
I think it will require a PR. |
If you are interested for an "hard-coded" workaround that uses docs.source.code check this out: TLTR: I create a custom addon and show the source code that i generate using LLMs |
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
andnpm storybook
, tabcode
should contain whole story codeSystem
Additional context
No response
The text was updated successfully, but these errors were encountered: