mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #1885 from syranide/testinnerhtml
Use faster cached regexps for tests in setInnerHTML
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
|
||||
var ExecutionEnvironment = require('ExecutionEnvironment');
|
||||
|
||||
var WHITESPACE_TEST = /^[ \r\n\t\f]/;
|
||||
var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/;
|
||||
|
||||
/**
|
||||
* Set the innerHTML property of a node, ensuring that whitespace is preserved
|
||||
* even in IE8.
|
||||
@@ -56,13 +59,8 @@ if (ExecutionEnvironment.canUseDOM) {
|
||||
// thin air on IE8, this only happens if there is no visible text
|
||||
// in-front of the non-visible tags. Piggyback on the whitespace fix
|
||||
// and simply check if any non-visible tags appear in the source.
|
||||
if (html.match(/^[ \r\n\t\f]/) ||
|
||||
html[0] === '<' && (
|
||||
html.indexOf('<noscript') !== -1 ||
|
||||
html.indexOf('<script') !== -1 ||
|
||||
html.indexOf('<style') !== -1 ||
|
||||
html.indexOf('<meta') !== -1 ||
|
||||
html.indexOf('<link') !== -1)) {
|
||||
if (WHITESPACE_TEST.test(html) ||
|
||||
html[0] === '<' && NONVISIBLE_TEST.test(html)) {
|
||||
// Recover leading whitespace by temporarily prepending any character.
|
||||
// \uFEFF has the potential advantage of being zero-width/invisible.
|
||||
node.innerHTML = '\uFEFF' + html;
|
||||
|
||||
Reference in New Issue
Block a user