-
-
Notifications
You must be signed in to change notification settings - Fork 847
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
react-markdown replaces hrefs of links around it under some conditions #740
Comments
Welcome @arsinclair! I'd recommend taking some time to try to isolate the issue. I also copied your code into the create-react-app sandbox that is offered in the PR template. source code from sandboximport React from 'react';
import Markdown from 'react-markdown';
const markdownSource = `
[Jason Stanley](https://en.wikipedia.org/wiki/Jason_Stanley) is an American philosopher who is the Jacob Urowsky Professor of Philosophy at Yale University. He is best known for his contributions to philosophy of language and epistemology, which often draw upon and influence other fields, including linguistics and cognitive science.
`;
const App = () => (
<>
<p>
<Markdown>{markdownSource}</Markdown>
</p>
<p>
<a href="https://upload.wikimedia.org/wikipedia/commons/f/f0/Jason_Stanley.jpg">
Photo
</a>
</p>
</>
);
export default App; And I found that the issue doesn't seem to happen outside of Gatsby either. Broadly speaking I'm closing this as it doesn't appear to be an issue here. If you have general questions, feel free to reach out in the Q&A discussions https://github.com/orgs/remarkjs/discussions/new?category=q-a |
This comment has been minimized.
This comment has been minimized.
The replication steps are provided in the original description. There's a repository that has the exact configuration where this issue is reproduced. I am not familiar with Code Sandbox, but the issue is reproduced on a local system. I stripped it down to the bare minimum. There's nothing else I can do to further isolate it, without getting into the react-markdown internals.
It's very well reproduced on Netlify environment, so I can't say there's another tool in my system that's causing this. I can host it on Netlify, if it makes it easier for you. |
Your original description also points to Gatsby being the issue.
Opening an issue at
You believe it is an issue in
If you believe it is a Netlify issue, feel free to open an issue with them. |
Yes, it's reproduced only with Gatsby and only with v3. And as I said, I am not sure where the error originates. It may very well be a Gatsby issue, or it may be an issue with react-markdown under very rare and unusual circumstances that Gatsby creates for it when it bundles the code. Either way, the quick fix for me was to get rid of invalid HTML, i.e. nested It's totally fine if you deem that further investigation is not necessary at this point. Thank you for quick responses. |
Then take some time to isolate it.
In general
Invalid HTML breaks SSR platforms, this is well established #731 and #704 Gatsby should have thrown a hydration error here, because the HTML changed between initial render and hydration. |
This is good to know, thank you for the linked issues and for the explanation.
I already spent several hours debugging the hydration code in Gatsby to no avail. It's not an intuitive code and I can't find a good documentation about it. As clear as it is right now, the issue originates because of the invalid HTML, so that's enough an explanation for me: HTML is a tool, and if the tool is misused I am not surprised that something misbehaves. |
Initial checklist
Affected packages and versions
react-markdown@^8.0.7
Link to runnable example
https://github.com/arsinclair/react-markdown-error-repro
Steps to reproduce
So this bug report is something that has begun as a bizarre error, through two days of bisecting and troubleshooting I'm here to present no less strange circumstances when it occurs.
Description
Under some circumstances react-markdown transforms the value in the href attribute of the links on the same page, the links which should be 'invisible' to react-markdown.
For example, we have such component:
The href attribute on the rendered page should point to the image of Jason Stanley, however when we build the site and run it, the link will point to the the Wikipedia page about him. I.e. the target of the link inside of the React Markdown component gets copied into other links on the page.
These circumstances are:
<p>
tag; the other link needs to be inside of another<p>
tag;How it looks when the error is reproduced:
How it should be
Reproduction steps
gatsby build
, and when it completes, rungatsby serve
href
attribute of a second linkResolution
So I am not sure where the error originates. I've looked into the code of react-markdown a little, but everything looks benign. Since these circumstances are very rare, the used version of Gatsby is quite old, and nested
<p>
tags is not even a valid HTML, I think the decision whether a time should be spent on fixing this is debatable. However, if this is indeed a problem with react-markdown, I think it's worth looking into, as it can be indicative of a scope spillover by the plugin, which can reveal other issues.As a solution for my project I'm just going to get rid of an extraneous
<p>
tag.Runtime
Node v16
Package manager
npm 8
OS
Linux
Build and bundle tools
Gatsby
The text was updated successfully, but these errors were encountered: