-
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] ALL root-relative markdown links are broken, prefixed with assetPrefix #21462
Comments
Has anyone else experienced this issue? This seems pretty breaking; it makes all linking in |
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! 💪💜 |
This is definitely still an issue, not sure why more people haven’t experienced it. It’s possible people don’t know their mdx links are broken if they’re using assetPrefix. We got alerted because we’ve programmed a crawler to check our links. |
@ZLevine Same here, I didn't realize my MDX links are broken until yesterday, but the |
Looks like this is the relevant bit of the code
So we're not actually setting |
I fixed this issue temporarily. First, add MDX components to handle custom anchor. function MDX({ children }) {
return <MDXProvider components={{ a: Anchor }}>{children}</MDXProvider>;
} Second, replace the broken link in import { useStaticQuery, graphql } from "gatsby";
export default function Anchor(props: AnchorProps) {
const { children, href, ...otherProps } = props;
const { site } = useStaticQuery(graphql`
{
site {
assetPrefix
}
}
`);
let newHref = href;
const assetPrefix = site.assetPrefix.replace("https://", "https:/");
if (href.startsWith(assetPrefix)) {
newHref = href.slice(assetPrefix.length);
}
const allProps = { ...otherProps, href: newHref };
return (
<a rel="noopener noreferrer" {...allProps}>
{children}
</a>
);
} |
Same issue here. It is really a bug. |
@xsq007 I agree. It seems Gatsby is setting I was hoping that setting |
Is there an ETA on the fix for this? It is majorly breaking. I'm guessing that setting pathPrefix equal to assetPrefix is causing subtle issues elsewhere as well. Looks like this file is the culprit https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/get-public-path.ts |
This issue is even harder to catch now that you can't run |
Hi! I'm closing this as a stale issue as in the meantime Gatsby 4 and related packages were released. You can check our Framework Version Support Page to see which versions currently receive active support. If this is a feature request, please create a discussion as we moved feature requests from issues to GitHub Discussions. Please try the mentioned issue on the latest version (using the Thanks! |
This is still an issue in 4.6.0. The behaviour is passingly mentioned at the very bottom of the I don't understand how prefixing links using an implicit path prefix became the default, nor why it isn't an option to disable it. I certainly don't understand how this issue has gone ignored for over two years. |
? Why this issue is closed? Can some one expland? |
Inspired by a solution posted on gatsbyjs/gatsby#21462, we fix broken links from gatsby-plugin-mdx when building with a `assetPrefix`, by removing those broken prefixes from the URL before passing it on to our `Link` component.
Inspired by a solution posted on gatsbyjs/gatsby#21462, we fix broken links from gatsby-plugin-mdx when building with a `assetPrefix`, by removing those broken prefixes from the URL before passing it on to our `Link` component.
Inspired by a solution posted on gatsbyjs/gatsby#21462, we fix broken links from gatsby-plugin-mdx when building with a `assetPrefix`, by removing those broken prefixes from the URL before passing it on to our `Link` component.
Inspired by a solution posted on gatsbyjs/gatsby#21462, we fix broken links from gatsby-plugin-mdx when building with a `assetPrefix`, by removing those broken prefixes from the URL before passing it on to our `Link` component.
Inspired by a solution posted on gatsbyjs/gatsby#21462, we fix broken links from gatsby-plugin-mdx when building with a `assetPrefix`, by removing those broken prefixes from the URL before passing it on to our `Link` component.
Inspired by a solution posted on gatsbyjs/gatsby#21462, we fix broken links from gatsby-plugin-mdx when building with a `assetPrefix`, by removing those broken prefixes from the URL before passing it on to our `Link` component.
Description
When generating
.mdx
pages usinggatsby-plugin-mdx
, any root-relative links such as[hello](/some-page)
are prefixed with assetPrefix for some reason. Obviously, links are not assets and shouldn't receive an assetPrefix.Steps to reproduce
Create an MDX page; e.g.
/pages/hello.mdx
Add a markdown link to that file:
assetPrefix
ingatsby-config.js
:Build and serve Gatsby with path prefixes enabled:
gatsby build --prefix-paths && gatsby serve
Visit the page in your browser and observe the HTML output.
Expected result
The output of the above markdown should be:
Actual result
The output of the above markdown actually is:
Might be related: In addition, it also outputs
https:/
instead ofhttps://
(with one slash) for some reason—either way, it should just output/privacy
.Additional notes:
.mdx
files.Environment
The text was updated successfully, but these errors were encountered: