-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add Option to override built-in HTML elements #2052
Conversation
… (h1, p, img, ...etc)
…nal code generated
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov Report
@@ Coverage Diff @@
## main #2052 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2308 2322 +14
=========================================
+ Hits 2308 2322 +14
Continue to review full report at Codecov.
|
Readme still needs to be updated to include the new option. Just trying to figure out which readme files need editing. |
Hey! My comment below is somewhat negative. That has to do with what the technical properties of this PR. It has no bearing on whether or not you are running into a problem.
|
All good. I know how it can be with dealing with pull requests and I did not create an issue to talk about this in.
I understand this is "intentional" now, but V1 specifically had the opposite handling so it's a pretty big breaking change that is barely even mentioned in the documentation (I couldn't find anything mentioning it until it was pointed out). This is why I created a new pull request and set it as an passable option instead of overriding the now intentional behavior.
You are probably right in that this could be a plugin that essentially duplicates some of the processing happening in Quoted from #821 (comment)
Issue 821 refers to the want to be able to tell MDX if you do or do not want to override literal HTML tags but the changes it presented completely removed the functionality with no way to add it back without setting up another plugin to parse the tree. |
@wooorm I've gone ahead and added some documentation that will maybe make this clearer https://mdx-git-fork-jlaramie-override-jsx-components-mdx.vercel.app/migrating/v2/#mdx-jsmdx-sandboxing |
I have found that many people did not expect the previous behavior and I have heard very few people that miss it. Other than that expectation, there’s also the fact that: it was very hard to undo the replacement, while it is very easy to add
I have no clue what you are doing. Perhaps you can share why it is impossible for you to call things The plugin would be extremely simple: it would essentially be From my perspective, the previous results have lead many people astray. I am choosing between to complex states. I also have to choose between more complex APIs with more options, and less complex APIs. Especially if options are niche. |
Another point here is that unless all the mdx is written with implicit So this works in a regular renderer import { Img } from "./Img.jsx";
<div>
<Img src="my-image.gif" />
</div> This does not work in a regular renderer since <div>
<Img src="my-image.gif" />
</div> This works and can be useful for a rough preview outside of a build system even though the output doesn't look 100% like what the final rendered output would look like. <div>
<img src="my-image.gif" />
</div> Another example is how when I was editing the md files to add documentation, I was able to run it through a mdx preview vscode plugin, even though the rendered output is not the same as what is deployed to vercel. This was still useful to me in order to check for some common mistakes when formatting the additional documentation. Had the md files used custom components isntead of native ones, the mdx preview would have failed unless there were implicit |
Hmm, I find the previewer issue rather interesting, but I’m not sure I really buy into it.
A lot of cool things can be done with plugins. They became extra powerful in v2. They are collected here: https://mdxjs.com/docs/extending-mdx/#list-of-plugins. Perhaps you want to make one, list it there, and we can work on adding it to migration too? |
It did take me some playing around to find which plugin had all the information necessary to do this {
rehypePlugins: [
() => (tree) => {
visit(tree, "mdxJsxTextElement", (node) => {
if (node.data) {
delete node.data._mdxExplicitJsx;
}
});
},
]
} |
Obviously this isn't my project so do with it what you want. I was just trying to add back a feature that got removed even though the ticket associated to the change wanted to make it optional. I still think there is are plenty of really good use cases for this and have used I'd suggest at least updating the migration documentation with the above plugin or something similar in order to avoid confusion. I'm more than happy to continue working on this pull request in order to get documentation and naming conventions to your standard, but if you don't want this change, go ahead and close this out I guess. Thanks for your time here and the time you put into this package. |
Heya!
I do not understand your use case. If you want say custom images, use a component with a capital
People ran into it and didn’t understand it and it caused bugs. Having the feature but reverting it is complex to reason about (e.g., a sandbox component). Not having the feature but adding it is easy and explainable: by using a capital, or a plugin.
There are not many people that run into your problem and don’t like it, so I’m not sure it should be thoroughly documented in the migration docs. That it changed is explained in https://mdxjs.com/migrating/v2/#update-mdx-content:
I’d be interested in hearing what you propose to change there, but I find it fine. Closing because I currently don’t believe this should be an option |
I would love to see this feature 😅 I just spend 2 hours trying figure out what is best approach, but this would be super useful 🙈 |
Please see the thread. It is unclear why the good alternatives are not enough. You can use |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
Locking this thread as the resolution is to add a plugin. #2052 (comment) and #2052 (comment) demonstrate how that plugin can be added |
There is no way to tell
@mdx-js/mdx
to use passed in components when overriding native built-in HTML elements.This is a big pain if you want to provide some custom handling for certain native HTML elements.
I looked into
disableParentContext
and it does not provide this feature at all.disableParentContext
just prevents the use ofcomponents
from a parent provider but does not control the code output in a way that would allow overriding native HTML elements.I added a test which shows what I look to accomplish
Related To: