-
-
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
MDX2: newline character is added visually, and extra <p>
tag is getting inserted in the DOM
#18921
Comments
This is mdx library issue. SHORT ANSWERThe bug occurred at fromMarkdown fn. LONG EXPLANATIONFor to demonstrate the explanation, I set up a new repo: debug-mdx the call stack is: compile(file, options?) <- process(file) <- parse(doc) for line 263, the VFile {
data: {},
messages: [],
history: [],
cwd: '/Users/zhyd1997/workspace/mdx',
value: "import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';\n" +
"import { Heading } from './Heading';\n" +
'\n' +
'<Meta title="Components/Heading" component={Heading} />\n' +
'\n' +
'# MDX 2 Rendering Bugs\n' +
'\n' +
`When there's no linebreak between jsx in the story source code, "\n` +
'" gets inserted visually in the UI.\n' +
'\n' +
'<Canvas>\n' +
' <Story name="one">\n' +
' <Heading>Lorem ipsum dolor sit amet</Heading>\n' +
' <Heading>Lorem ipsum dolor sit amet</Heading>\n' +
' </Story>\n' +
'</Canvas>\n' +
'\n' +
`When there is a linebreak between jsx in the story source code, then there's no "\n` +
'" in the UI, and things look normal.\n' +
'\n' +
'<Canvas>\n' +
' <Story name="two">\n' +
' <Heading>Lorem ipsum dolor sit amet</Heading>\n' +
'\n' +
' <Heading>Lorem ipsum dolor sit amet</Heading>\n' +
'\n' +
' </Story>\n' +
'</Canvas>\n' +
'\n' +
'When the jsx is multi-line in the source code, then the content gets wrapped in a \\<p\\> tag when rendered.\n' +
'\n' +
'ONLY occurs if the source code itself (the jsx) is multi-line, not if the content itself is rendered on multiple lines and wraps in the UI.\n' +
'\n' +
'<Canvas>\n' +
' <Story name="three">\n' +
' <Heading>I am very long, but am kept on one line in the source code, so there is no wrapper paragraph tag inserted around me. I am very long, but am kept on one line in the source code, so there is no wrapper paragraph tag inserted around me.</Heading>\n' +
'\n' +
' <Heading>\n' +
' Multi-line in the source code, wrapped in p tag.\n' +
' </Heading>\n' +
'\n' +
' </Story>\n' +
'</Canvas>\n' +
'\n' +
'## Props\n' +
'\n' +
'<ArgsTable of={Heading} />'
} but when running the return statement, the result is strange (you can try to run
After logging the Parser: console.log(Parser.toString()) I found it uses so continuing the call stack:
the definition of That's all I found until now. |
I don’t know enough about everything here, but the main thing on the |
Thanks @wooorm, make sense 👍 In my case, it was because I have my IDE set to run Prettier on save, and text was getting forced onto a new line due to props bloating the line length. Getting around it in my stories with curly braces: <Heading prop="asdf" anotherProp="asdf">
{"Some text"}
</Heading> |
We’re cleaning house! Storybook has changed a lot since this issue was created and we don’t know if it’s still valid. Please open a new issue referencing this one if:
|
This is still a problem |
Describe the bug
I've come across two rendering issues working with MDX 2 /
previewMdx2: true
is set.When there's no newline between jsx in the story source code,
"\n"
gets inserted visually in the UI.When the jsx is multi-line in the source code, then the content gets wrapped in a
<p>
tag in the DOM. ONLY occurs if the source code itself (the jsx) is multi-line, not if the content itself is rendered on multiple lines and wraps in the UI.I can't seem to upload any screenshots along with this issue report to help visually show this (GitHub says
"something went wrong and we can't process that file"
😕), so please check out my link below to reproduce this.To Reproduce
https://github.com/melanieseltzer/mdx2-rendering-bugs-reproduction
System
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: