-
Notifications
You must be signed in to change notification settings - Fork 10.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
[gatsby-plugin-mdx] import names across MDX content collide #17119
Comments
Hi! Thanks for taking the time to write this up. I'm following the workaround right now. To add some context, I wanted to add the use case I'm running into, to validate/challenge some of the assumptions made:
When you are working with user created content (example a gatsby theme), the theme itself has little control over how the mdx is authored. If there are components imported, conflicts can happen.
In my case, I'm trying to make use of the Component Story Format by the storybook team. You would see this typically in styleguides/component docs. I have seen folks handle this in different ways in modulz and docz. Here's an example of what that looks like import React from 'react'
import { Input } from 'your-library'
export default { title: 'Input' }
export const Simple = () => (
<Input type="text" placeholder="Enter some text" />
)
export const Disabled = () => (
<Input type="text" disabled={true} placeholder="Enter some text" />
)
export const WithIcon = () => (
<Input type="text" icon="copy" value="secret-token" />
) For your documentation, you would want to import some of these examples to showcase them. import { Simple, WithIcon } from './input.stories'
<Simple />
## Examples
You can add icons to the input which defaults to the right side of the input.
<WithIcon /> The workaround works pretty great in this scenario, but does require some education for the user first. import * as InputExamples from './input.stories'
<InputExamples.Simple />
## Examples
You can add icons to the input which defaults to the right side of the input.
<InputExamples.WithIcon /> |
Related issue: #16799 |
I also created a reproduction of this in https://github.com/patrickarlt/gatsby-issue-17119-reproduction based on the MDX starter before I found this issue. My use case is different then the above bases using
we might share the So in import FAQ from "./faq.mdx";
Some Markdown content in `feature-a/index.mdx`...
<FAQ /> and import FAQ from "./faq.mdx";
Some Markdown content in `feature-b/index.mdx`...
<FAQ /> But end up with the wrong Right now our recommendation is to simply have authors use unique names for all imports (like below) but this definitely feels like a "gotcha" that I would expect to work. import FeatureBFAQ from "./faq.mdx";
Some Markdown content in `feature-b/index.mdx`...
<FeatureBFAQ /> |
They're only warnings and not errors because gatsby-plugin-mdx has broken imports that end up being global so it doesn't *really* matter, but I like not seeing warnings. gatsbyjs/gatsby#17119
They're only warnings and not errors because gatsby-plugin-mdx has broken imports that end up being global so it doesn't *really* matter, but I like not seeing warnings. gatsbyjs/gatsby#17119
They're only warnings and not errors because gatsby-plugin-mdx has broken imports that end up being global so it doesn't *really* matter, but I like not seeing warnings. gatsbyjs/gatsby#17119
They're only warnings and not errors because gatsby-plugin-mdx has broken imports that end up being global so it doesn't *really* matter, but I like not seeing warnings. gatsbyjs/gatsby#17119
Description
When using MDX content from nodes, the imports have the potential to collide.
Steps to reproduce
Two MDX nodes, both used to do whatever but filtered through the node system via some source (doesn't matter which source, just have to get Mdx nodes to exist). The content of both nodes must have an import whose name conflicts with the other. This can easily be achieved with default exports since they can be re-named whenever.
Expected result
Each node, when rendered gets the appropriately named component.
Actual result
Only one of the components "survives", both renderings get the same one of the two Things.
Notes
This rarely happens in practice because of the way most of the ecosystem works. It will, however, increasingly happen as more and more people use MDX because we'll start hitting edge cases that few people use.
Path forward
We basically want to associate some Mdx content with a set of imports in
gatsby-plugin-mdx
. We could do this by forcing the mandatory usage ofid
inMDXRenderer
.I want to find a "more automatic" way of doing this. Maybe through something that I've talked about a few times that is the ability to return components from the GraphQL API such that:
could be used directly as
Where the
Component
return is really a bootstrappedMDXRenderer
with the content and theid
, etc. AS a side note, this would also solve an issue with GraphQL interfaces sourced from multiple locations with different primary content types (like aBlogPost
withhtml
strings andMdx.body
strings, because the usage would be to render both withComponent
).Workarounds
Typically the problem arises when the culture of an eng org is such that exports are named and destructured similarly, such as
Because this is typically a cultural thing, asking the team to change habits for export naming, etc is a non-starter. The imports can be imported as such inside Mdx files instead:
The text was updated successfully, but these errors were encountered: