-
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
: remark-external-links
generates invalid rel
#22719
Comments
Preliminary check on this: The remark plugin does set I guess it's the AST "stringifier" that is different for mdx here (it joins props with commas Will have to dig a bit into gatsby-plugin-mdx to where this is actually happening - is it in gatsby plugin or is it in |
Interestingly the code that MDX produces is this: /* @jsx mdx */
import { mdx } from '@mdx-js/react';
/* @jsx mdx */
import DefaultLayout from "/Users/misiek/test/i22719/src/components/Layout.js"
export const _frontmatter = {};
const makeShortcode = name => function MDXDefaultShortcode(props) {
console.warn("Component " + name + " was not imported, exported, or provided by MDXProvider as global scope")
return <div {...props}/>
};
const layoutProps = {
_frontmatter
};
const MDXLayout = DefaultLayout
export default function MDXContent({
components,
...props
}) {
return <MDXLayout {...layoutProps} {...props} components={components} mdxType="MDXLayout">
<h1>{`Hello, world!`}</h1>
<p><a parentName="p" {...{
"href": "https://github.com/remarkjs/remark",
"target": "_blank",
"rel": ["nofollow", "noopener", "noreferrer"]
}}>{`remark`}</a></p>
</MDXLayout>;
}
;
MDXContent.isMDXComponent = true; So it didn't do anything to
- props.rel = (rel || defaultRel).concat()
+ props.rel = (rel || defaultRel).join(` `) |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Think it's something in mdx. Hast uses arrays for attributes with lists, mdx naively assumes those are all space separated (they often are, but this one is comma separated?) |
Or: mdx dos not support space separated lists at all 🤔 |
WorkaroundUse // In your gatsby-config.js
plugins: [
{
resolve: `gatsby-plugin-mdx`,
options: {
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-external-links`,
},
],
},
},
], |
I have opened a pull request warning of this behavior (#23505) in the |
Hmm, maybe it’s a good idea instead to fix it in MDX? |
It's bit weird - seems like github repository does not match to what is released on npm. On npm that package is using string and not array ( https://unpkg.com/browse/[email protected]/index.js ) and I guess that's why it actually "works" |
Interesting, seems like JLongley/gatsby-remark-external-links#6 introduced I've asked them to publish, would be interesting to see if it still works afterwards. |
It won’t, #22719 (comment), it’s a bug in MDX |
@wooorm If you're certain of this, I'm happy to open an issue in So if you can provide me with the technical details of a reportable issue, I will do the reporting :) |
I wasn’t 100% that it was MDX at first, but now I definitely am. I forgot about it, but you reported mdx-js/mdx#715 which lead to mdx-js/mdx#716. Problematic code is here: https://github.com/mdx-js/mdx/blob/9b4f192afd3255ac48780934dd848806912bff44/packages/mdx/mdx-hast-to-jsx.js#L19-L45. The proper solution will be in MDX2, which I’m working on now! |
Ah right, cool! Yeah I forgot about this too 😅 Thanks for the update! If you would guide me, I'd be happy to add this as a test case to your PR. I guess that this PR can be closed when mdx-js/mdx#1039 lands. I've also updated #23505 to note that this applies to versions of MDX before v2. |
That PR is pretty big and hard to read already, so I think a separate PR when it lands with more integration tests is a good idea, and a very welcome addition! (I’d like to do more of that too, e.g., SVG/MathML and more integration tests!) I’m heavily biased of course, but I think the quality of gatsby-remark plugins is sometimes lacking, and I’d want to push towards cooperation instead of separation. Some combination plugins of course make lots of sense (if the plugin is really integrating with Gatsby), but “wrapper” or “copy-paste” plugins leads to the same problems grunt/gulp had, where plugins are out of date leading to issues that are already solved (such as this one), and plugins that implement something in gatsby-remark where it could’ve been a remark plugin too, leads to doing the same things twice in silos. So, while in this case technically a solution for this issue, I’m not sure pointing people to an unmaintained wrapper plugin at 0.0.4 with other issues is a great solution either. |
Alright sounds good, let's do it then 👍
Agree on all points, would be nice if the API of Gatsby plugins such as
Agree, it's not a great solution. But having it break with no recourse for those affected is even worse. I've experienced a lot of pain and incompatibility in Gatsby already, and I feel strongly about doing my part so that users don't have to go through the same grief that I did. Again, I totally prefer the method of pushing towards more correct and simple solutions, but if those solutions do not yet exist (or if a project is stuck on an old version for some reason), then it's important to have a way of getting around it until the project can upgrade. |
Just thinking, maybe there's a way to get correctness now and close this issue after all - maybe mdx would accept a PR for v1 for a That would allow |
That should be possible! I’m sure John would be happy to cut a release early for that? Either adding the prop to the list of exceptions, or using hast-to-hyperscript like so to solve everything! (which looks a bit ugly but I wanted to do cleaning up later) |
Looking at your comments in mdx-js/mdx#715 and considering pulling in Then I can create the Any downsides with this? If not, I'll give it a shot. |
I’d suggest using prop info instead of hardcoding the list for maintainability’s sake, property information is relatively frequently updated with new HTML attributes. |
But as the PR will land soonish, hardcoding for now is fine! |
Ok, open! mdx-js/mdx#1048 Edit: Great, that's been merged now, so as soon as it's published, Then this issue can be closed 🎉 Edit 2: PR in Gatsby open! #23700 |
Ok, this has been resolved (CodeSandbox: https://codesandbox.io/s/serverless-snowflake-yo8mt?file=/package.json): I've also closed #23505. |
I've also opened an issue in |
Ah it looks like publishing additional "wrapper" npm packages to wrap every remark plugin is the recommended way of doing things 😞 At least in 2018 it was like this. References:
So @wooorm I guess the process of writing extra wrapper packages you described the downsides about in #22719 (comment) is actually recommended 😞 |
Ohh. I think that’s unfortunate. I see some upsides in doing that, but mostly short term, I feel like in the long run it would be better to not do wrappers. |
Yes, agree it's unfortunate. Wonder if the Gatsby team would be open to changing this for Remark plugins (the wrapper bit can also be absorbed into |
Description
Using
remark-external-links
withgatsby-plugin-mdx
generates an invalidrel
attribute:nofollow,noopener,noreferrer
instead ofnofollow noopener noreferrer
, how it is supposed to be.Usage with
gatsby-plugin-mdx
andremarkPlugins
Usage alone
Steps to reproduce
Add the following code to Runkit (you can use this link: https://npm.runkit.com/remark-external-links). This generates the correct
rel
.Try out my
gatsby-plugin-mdx
sandbox at the link below. This generates an invalidrel
:gatsby-plugin-mdx
Sandbox: https://codesandbox.io/s/empty-cdn-u31qbExpected result
The correct
rel
should be generated.Actual result
An invalid
rel
is generated.Environment
cc @ChristopherBiscardi
The text was updated successfully, but these errors were encountered: