Use feature detection and more robust recovering of whitespace for innerHTML in IE8 #684
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
dangerouslySetInnerHTML
in IE8 collapses whitespace in root TextNodes and removes leading whitespace. Your current fix for this is to replace any first space with
which is a surprisingly good and simple fix, but it does this for all browsers and doesn't solve the collapsing whitespace (or any whitespace besides space).I propose the following fix instead, which makes it work identically to all other browsers at minimal cost, and does so via feature detection so only IE8 is affected.
PS. Make sure to spot the seriously magic trick I discovered to making IE8 behave better!
Disclaimer: if the root node is a TABLE/TBODY/OL/SELECT or anything else that (kind of) doesn't support TextNodes AND there is whitespace in the beginning of the HTML, this will create a faulty TextNode with whitespace (when it actually should be removed)... however, the code/size penalty for solving this is unreasonably large when the use-cases are virtually none, as far as I'm aware