dangerouslySetInnerHTML doesn't properly reconcile
See original GitHub issue@sbezboro reported the following issue on IRC:
http://jsfiddle.net/vjeux/8vZ57/1/ (Both on master and 4.0)
The repro case is:
- Render
<div dangerouslySetInnerHTML={{__html: '<b>HTML</b>'}} />
- Render
<div>Text</div>
- Render the same as 1)
The div has its innerHTML empty instead of <b>HTML</b>
.
I don’t really know what’s going on. @jordwalke, @petehunt can you guys look at it?
Issue Analytics
- State:
- Created 10 years ago
- Comments:20 (8 by maintainers)
Top Results From Across the Web
React.js: Set innerHTML vs dangerouslySetInnerHTML
Assume I'm properly sanitizing things for the sake of simplicity. Example: var test = React.createClass({ render: function(){ ...
Read more >Using dangerouslySetInnerHTML in a React application
dangerouslySetInnerHTML is a property that you can use on HTML elements in a React application to programmatically set their content. Instead of ...
Read more >Design Principles - React
For example, dangerouslySetInnerHTML is hard to miss in a code review. Optimizing for search is also important because of our reliance on codemods...
Read more >fx-team - Mercurial - Mozilla
This build has "addons", or + * functionality we've built and think might be useful but doesn't have a good + * place...
Read more >Dangerously Set innerHTML | React
The prop name dangerouslySetInnerHTML is intentionally chosen to be frightening, ... After fully understanding the security ramifications and properly ...
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 Free
Top 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
I know this is a very old issue but I had a similar problem and came across this.
I found that this problem occurs when you do not add a
key
property to the React component containing thedangerouslySetInnerHTML
property. So,does not seem to work reproducibly, whereas
seems to. I think this could be related to React’s diffing algorithm that might not properly treat a component with a
dangerouslySetInnerHTML
statement if that component gets rerendered multiple times with different inner content. Just posting this here in case other people have the same issue and stumble upon this.What happens if you change step 2 to a
span
instead of adiv
? It works, right?