-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Addon-docs: Fix MDX stories with multiple children #9531
Addon-docs: Fix MDX stories with multiple children #9531
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/storybook/monorepo/62sikvvz3 |
if (body.type === 'JSXExpressionContainer') { | ||
// FIXME: handle fragments | ||
body = body.expression; | ||
const bodyParts = bodyNodes.map(bodyNode => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be simpler, and even more correct, if we just wrapped the child nodes in a fragment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain, not sure i follow where you have it in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pseudocode since I'm on my phone:
if(len(Non-text children) > 1):
story.children = [wrapInFragment(story.children)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I need to think about the non-react case too 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment below on the code, thats what the coe does if i understand correct;y. The comment here about FIXME was from the old code/
// 1. Add line breaks | ||
// 2. Enclose in <> ... </> | ||
storyCode = bodyParts.map(({ code }) => code).join('\n'); | ||
const storyReactCode = bodyParts.length > 1 ? `<>\n${storyCode}\n</>` : storyCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shilman - here it is enclosing the elements in <> </>
if more than one child - is that what you meant for the fragment?
I think this is more correct to use pure JSX instead of React.Fragment, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll play around with it more. Not what I expected the code to look like, but I also haven't really dug in yet. Thanks for your patience!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let me know. I had to make some code compromises to keep compatibility and the tests running. Another constraint was to have the <> tags in the code so it works, but to not have them for-the story source preview
if (body.type === 'JSXExpressionContainer') { | ||
// FIXME: handle fragments | ||
body = body.expression; | ||
const bodyParts = bodyNodes.map(bodyNode => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment below on the code, thats what the coe does if i understand correct;y. The comment here about FIXME was from the old code/
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Issue: #8571
What I did
mdx-compiler-plugin now filters all potential children.
added example to official storybook addon-docs.stories.mdx - multiple children
added test case to mdx-compiler-plugin.tests
How to test
official storybook
yarn test --core