-
-
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
Story source code shows "MDXCreateElement" instead of actual source code #11542
Comments
I'm encountering the same issue using React and CSF stories. The code shown in "Show Code" is the computed output of the component and not the content of the actual story. It shows props that have default values but were not actually passed to the component in the story code. I haven't tried using |
Yes will offer the ability to configure, hopefully this week |
It seems to only occur when using an intermediate variable (including the template/bind pattern):
☝️ Does not work (shows MDXCreateElement)
☝️ Does work (shows Button) |
@robbertkl nah, not working |
@yyynnn Thanks for your very helpful comment, are you a troll? The 2nd example I gave does work (shows the correct in the source), both on |
@robbertkl sorry after some rm-rf magic + update to rc.16 it started working someone should update the docs probably |
Another thing I've noticed is decorators can cause this as well, but only component (and possibly story) decorators, not global ones: When I have working source code display (by avoiding an intermediate variable), and add a decorator to (running |
As a workaround you can set the |
@shilman Thanks for workaround. Is it possible for you to provide a quick code snippet for the workaround in MDX? |
@shilman Thanks for the work around. But seems not working for me. After I set |
This is still an issue in version 6.1.0-alpha.3. However if i use TestComponent.stories.mdx
|
Just wanted to drop in and say that removing the decorators from the components (per the answer quoted) worked for me |
The trick with an inline function mentioned by @robbertkl works only for the root element, while others provided via Source <Canvas>
<Story
name="SvgIcon"
args={{
children: <path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" />,
color: 'lightgreen',
size: 40,
}}
>
{(args) => <SvgIcon {...args} />}
</Story>
</Canvas> Preview <SvgIcon
color="lightgreen"
size={40}
>
<MDXCreateElement
d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"
mdxType="path"
originalType="path"
/>
</SvgIcon> (SB@6.0.26) |
This issue is still happening for me with Storybook 6.2.8, and I can't seem to find any work around. UPDATE: I did find that the set In the file import "../src/index.css";
import "bootstrap/dist/css/bootstrap.css";
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
}; I changed this to: import "../src/index.css";
import "bootstrap/dist/css/bootstrap.css";
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
docs: {
source: {
type: "code"
}
}
}; Then the
instead of:
|
Landed here due to the same issue as everyone above. Can confirm that the suggested fix from @robbertkl works in my case. I'd be happy to update the MDX documentation in a PR if it'll be accepted.
|
It's pretty important to be able to see what the passed args are for developers to be able to make use of the code examples, so the above solution doesn't work for us. I've moved us over to defining the stories in tsx and importing them into the mdx as above and it's working much better, esp with stuff like styled components, and now we get typing :) |
@pconrad Solution worked for our Storybook mdx files and we are using the template binding. It cleared all the MDXCreateElement tags and it now displays our source code accurately. |
Shiver me timbers!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.0-alpha.41 containing PR #14652 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
Just a note, I've just realized that importing the stories in tsx like so (approach suggested by @smathson )
This causes there to be no add-on panel to be shown at all in the canvas view, though argtables work fine in the docs mode. @shilman is this expected behavior? |
Son of a gun!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.0-beta.3 containing PR #15071 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.0-beta.4 containing PR #15071 that references this issue. Upgrade today to the
|
storybook will not display the right code. See storybookjs/storybook#11542
storybook will not display the right code. See storybookjs/storybook#11542
I'm on 6.3.4 and running into this issue. I see that the fix has been tagged in one of the 6.3.0 beta releases but not one of the proper releases. Does that mean it hasn't made it into storybook proper? |
@marti6jm everything that goes into a 6.3 prerelease makes it into the 6.3 final release unless some other PR explicitly removes it (which is rare ... and not the case here). Do you have a reproduction repo I can look at? |
Hey there @shilman Mine shows correctly now when I press I have this code that basically says my
It returns error. Right now I can do this on separate file:
However when I press show code, it shows me Seems like i'm out of workaround.. We're on the latest version:
|
@robertwt7 There are multiple ways to handle this. maybe try a different pattern, such as https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-mdx-docs I'm not sure which ones work well with generated source code, but they should all get around the issue you're having with the MDX-generated code. |
@shilman thanks for your answer, really appreciate it. When I used csf stories I end up getting I end up putting them on the same file like this:
It renders perfectly, I just have one last question if you don't mind. Currently when I click show code, it shows this:
Is this expected? I thought that the args will be mapped ( |
Arrrgh, nothing on this thread seems to be working (on 6.4.19)... I have a component like: <Story
name="TextComposition"
args={{
children: (
<>
<Text type='hero' as='h1'>Look at this source!</Text>
<p>The <Text /> component is designed so that it can apply to individual bits of text, but it can also serve as a text block for laying out simple paragraphs (<p>) and headings (<h3>).</p>
<Text type='subtitle1'>This is a subtitle</Text>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. At nisi sit vulputate rhoncus, ultrices sed. Augue nisi maecenas malesuada accumsan tristique tellus tortor eget erat. Tincidunt euismod nec in imperdiet mollis eget varius sollicitudin. Et lorem eu elit pretium. Faucibus in nec dis pretium aliquam. Arcu, iaculis blandit elementum viverra.</p>
<div>
<div>An arbitrary div block</div>
<div>Items should not get </div>
<div>spaced.</div>
</div>
</>
)
}}>
{Template.bind({})}
</Story> However, the code shows: <MDXCreateElement
mdxType="p"
originalType="p"
>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. At nisi sit vulputate rhoncus, ultrices sed. Augue nisi maecenas malesuada accumsan tristique tellus tortor eget erat. Tincidunt euismod nec in imperdiet mollis eget varius sollicitudin. Et lorem eu elit pretium. Faucibus in nec dis pretium aliquam. Arcu, iaculis blandit elementum viverra.
</MDXCreateElement>
<MDXCreateElement
mdxType="div"
originalType="div"
>
<MDXCreateElement
mdxType="div"
originalType="div"
>
An arbitrary div block
</MDXCreateElement>
<MDXCreateElement
mdxType="div"
originalType="div"
>
Items should not get{' '}
</MDXCreateElement>
<MDXCreateElement
mdxType="div"
originalType="div"
>
spaced.
</MDXCreateElement>
</MDXCreateElement> This only happens in the MDX format. |
@matthew-dean I've added this to the
If you're using the default export then adding the parameters key should work as well. Hope this helps. |
Just to add on this thread, I'm running into a similar issue on My Input is the following: import {
Canvas,
Meta,
Story,
Props,
Preview,
ArgsTable,
} from '@storybook/addon-docs';
import { Button } from '../components/Button';
import * as Icons from '../components/Icons';
import { CloseIcon, DeleteIcon, ArrowRightIcon } from '../components/Icons';
export const IconElementMapping = Object.fromEntries(
Object.entries(Icons).map(([name, Component]) => [name, <Component />]),
);
export const iconOptions = {
options: ['No Icon'].concat(Object.keys(Icons)),
mapping: {
'No Icon': undefined,
...IconElementMapping,
},
};
<Meta
title='Inputs/Buttons'
component={Button}
argTypes={{
startIcon: iconOptions,
endIcon: iconOptions,
}}
parameters={{
viewMode: 'docs',
}}
/>
# Buttons
Buttons represents a clickable element that the user can interact with.
<Canvas withToolbar withSource='open'>
<Story
name='Buttons'
args={{
children: 'Label',
onClick: undefined,
}}>
{(args) => <Button {...args} />}
</Story>
</Canvas>
<ArgsTable story='Buttons' />
... While everything works well including an interactive <Button endIcon={<MDXCreateElement mdxType="Icon" originalType={() => {}}/>}>
Label
</Button> Instead of the expected output being: <Button endIcon={<AddIcon />}>
Label
</Button> |
2023, still happening. I set:
And I get:
It basically returns the |
Describe the bug
The output of Show Code tabs mismatches the source
To Reproduce
.mdx
story:Expected behavior
Output match contents of the
<Story>
Screenshots
Code snippets
Full Story
Main.js
Show code output
System:
Environment Info:
System:
OS: macOS 10.15.5
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 10.15.2 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Browsers:
Chrome: 83.0.4103.116
Firefox: 74.0
Safari: 13.1.1
npmPackages:
@storybook/addon-a11y: ^6.0.0-rc.3 => 6.0.0-rc.3
@storybook/addon-actions: ^6.0.0-rc.3 => 6.0.0-rc.3
@storybook/addon-controls: ^6.0.0-beta.15 => 6.0.0-beta.15
@storybook/addon-docs: ^6.0.0-rc.3 => 6.0.0-rc.3
@storybook/addon-links: ^6.0.0-rc.3 => 6.0.0-rc.3
@storybook/addon-viewport: ^6.0.0-rc.3 => 6.0.0-rc.3
@storybook/addons: ^6.0.0-rc.3 => 6.0.0-rc.3
@storybook/preset-create-react-app: ^3.1.2 => 3.1.3
@storybook/react: ^6.0.0-rc.3 => 6.0.0-rc.3
@storybook/theming: ^6.0.0-rc.3 => 6.0.0-rc.3
The text was updated successfully, but these errors were encountered: