@samitouri / QOS-React / commits / 686010037d

Remove IE8-specific setInnerHTML behavior (#9288)

Since IE8 is not supported anymore, lets save those bytes!

Brandon Dail committed Mar 30, 2017 at 11:24 UTC 686010037d10adde53b8ac926a7bfef0ab2ab8b1
1 file changed +1 -59
src/renderers/dom/shared/setInnerHTML.js
+1 -59
@@ -11,20 +11,14 @@
11
12 'use strict';
13
14 -var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
14 var DOMNamespaces = require('DOMNamespaces');
16 -
17 -var WHITESPACE_TEST = /^[ \r\n\t\f]/;
18 -var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/;
19 -
15 var createMicrosoftUnsafeLocalFunction = require('createMicrosoftUnsafeLocalFunction');
16
17 // SVG temp container for IE lacking innerHTML
18 var reusableSVGContainer;
19
20 /**
26 - * Set the innerHTML property of a node, ensuring that whitespace is preserved
27 - * even in IE8.
21 + * Set the innerHTML property of a node
22 *
23 * @param {DOMElement} node
24 * @param {string} html
@@ -47,56 +41,4 @@ var setInnerHTML = createMicrosoftUnsafeLocalFunction(function(node, html) {
41 }
42 });
43
50 -if (ExecutionEnvironment.canUseDOM) {
51 - // IE8: When updating a just created node with innerHTML only leading
52 - // whitespace is removed. When updating an existing node with innerHTML
53 - // whitespace in root TextNodes is also collapsed.
54 - // @see quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
55 -
56 - // Feature detection; only IE8 is known to behave improperly like this.
57 - var testElement = document.createElement('div');
58 - testElement.innerHTML = ' ';
59 - if (testElement.innerHTML === '') {
60 - setInnerHTML = function(node, html) {
61 - // Magic theory: IE8 supposedly differentiates between added and updated
62 - // nodes when processing innerHTML, innerHTML on updated nodes suffers
63 - // from worse whitespace behavior. Re-adding a node like this triggers
64 - // the initial and more favorable whitespace behavior.
65 - // TODO: What to do on a detached node?
66 - if (node.parentNode) {
67 - node.parentNode.replaceChild(node, node);
68 - }
69 -
70 - // We also implement a workaround for non-visible tags disappearing into
71 - // thin air on IE8, this only happens if there is no visible text
72 - // in-front of the non-visible tags. Piggyback on the whitespace fix
73 - // and simply check if any non-visible tags appear in the source.
74 - if (
75 - WHITESPACE_TEST.test(html) ||
76 - (html[0] === '<' && NONVISIBLE_TEST.test(html))
77 - ) {
78 - // Recover leading whitespace by temporarily prepending any character.
79 - // \uFEFF has the potential advantage of being zero-width/invisible.
80 - // UglifyJS drops U+FEFF chars when parsing, so use String.fromCharCode
81 - // in hopes that this is preserved even if "\uFEFF" is transformed to
82 - // the actual Unicode character (by Babel, for example).
83 - // https://github.com/mishoo/UglifyJS2/blob/v2.4.20/lib/parse.js#L216
84 - node.innerHTML = String.fromCharCode(0xfeff) + html;
85 -
86 - // deleteData leaves an empty `TextNode` which offsets the index of all
87 - // children. Definitely want to avoid this.
88 - var textNode = node.firstChild;
89 - if (textNode.data.length === 1) {
90 - node.removeChild(textNode);
91 - } else {
92 - textNode.deleteData(0, 1);
93 - }
94 - } else {
95 - node.innerHTML = html;
96 - }
97 - };
98 - }
99 - testElement = null;
100 -}
101 -
44 module.exports = setInnerHTML;