-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Inline SVGs not rendering and break page #3179
Comments
Hi, you can include svgs (and images) like this:
Or like this:
You can also choose to create a React component that renders the svg (in a |
Hi @teikjun thanks for your response. Unfortunately, even when the file is named mdx.mdx, the same error occurs. Regarding the other ways to include it, those are not inline, and I am trying to include inline svgs instead of external ones |
Hi,
This is not std javascript to import a svg, this is Webpack specific, and there's no unique way to handle a svg file import:
This is not a bug to me, but a feature request, and Docusaurus user may want different behaviors according to their own usecases In the meantime, you should be able to solve your problem by using "inline" Webpack loaders, directly in your import expression, and using a loader like: https://github.com/jhamlet/svg-react-loader Add the dependency, and then:
I'm closing, but open to discuss a feature request for this. |
Hi @slorber the thing is that in the docs https://v2.docusaurus.io/docs/static-assets#jsx-example states that inline svgs are an option. |
Hmmmm, I didn't know we had that! Need to check this next week, but I can confirm I see this webpack loader:
|
Awesome! Thank you! |
I will take this. |
I checked the code and the problem is that there are conflicting webpack-loaders for |
We can use something like this.
then it won't break existing websites. import starUrl, { ReactComponent as Star } from './star.svg'
const App = () => (
<div>
<img src={starUrl} alt="star" />
<Star />
</div>
) |
I think in the image loader of webpack:
we can just remove the svg from here, as:
Can you find a way to dogfood this feature somewhere by rendering an svg as both a md image + a mdx react component? That would help us not break this feature again in the future. (opened also an issue to improve the assets doc as it's on 2 pages #3198) |
But if we remove |
This is a new feature, I don't think it has been used by users in this small amount of time, and also, this feature is actually in contraction with our existing svg to React conversion in the first place, so I'd rather revert to the correct behavior we had before alpha 59, even if it's a breaking change. |
Thank you @slorber ! |
thank @anshulrgoyal :) |
🐛 Bug Report
This may be user error, as I feel like this is core enough that it would have already been reported, so I apologize if I waste anyone's time.
Have you read the Contributing Guidelines on issues?
Yes
To Reproduce
DOMException: Failed to execute 'createElement' on 'Document': The tag name provided ('/assetsundraw_docusaurus_mountain-b480421ae597bc5783ec62d605645b24.svg') is not a valid name.
I want to add that I also tried including the svg in an external component file with the same results
Your Environment
This was done with the most recent version of docusaurus
Reproducible Demo
I'm not including a link because the steps to reproduce from scratch are so quick. Hopefully that's ok!
The text was updated successfully, but these errors were encountered: