Uncaught error when doing dangerouslySetInnerHTML="<svg>...</svg>"
See original GitHub issueWhen my dangerouslySetInnerHTML
string includes an inline SVG, it renders fine the first time, but when it re-renders I get uncaught errors:
preact.js:158 Uncaught TypeError: Cannot assign to read only property 'height' of object '#<SVGSVGElement>'
I’m guessing this is to do with the fact that inline SVGs require a special module, preact-svg…? But I’m not sure how that can work for my use case, because my SVG is entirely inside the string I am trying to ‘dangerously inject’.
Any idea how I can fix this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
React - Using svg <defs> with dangerouslySetInnerHTML
The problem comes from you calling your functional component's input argument icons , and the assumptions that stem from that naming choice.
Read more >Two ways to solve: Cannot find SVG module error when ...
Here we declare a new module for SVGs by specifying any import that ends in .svg and defining the module's content as any....
Read more >Managing inline SVGs with React/Webpack - union.io
In the first file, we simply require() the second file (line 2), and, within the component, add a <g> tag with the raw...
Read more >preact dangerouslysetinnerhtml - You.com | The AI Search ...
React dangerouslySetInnerHTML not working when using variable ... preactjs/preactUncaught error when doing dangerouslySetInnerHTML="<svg>...</svg>"#194.
Read more >Experimenting with SVGs | by Redfin Engineering - Code Red
Recently, we started using SVG for icons at Redfin! ... I used a set of 20 SVGs, including 2 icons that are malformed,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@callumlocke Sorry for the wait there (painting a bedroom) - I just published
preact-compat@1.8.0
that will allow you to usepreact@beta
. Let me know if that works!I think I can confirm this seems to be fixed in 5.x: https://jsfiddle.net/developit/j31tf2jd/
Also a note: I just published
preact-compat@1.10.0
, which removes theoptionalDependencies
field frompackage.json
, which I think might have been causing the semver issue.