mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
bb3c22c66f
* Convert ReactDOM to const/let * Convert ReactDOMComponentTree to const/let * Convert ReactDOMComponentTree to const/let * Convert getNodeForCharacterOffset to const/let * Convert getTextContentAccessor to const/let * Convert inputValueTracking to const/let * Convert setInnerHTML to const/let * Convert setTextContent to const/let * Convert validateDOMNesting to const/let
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import {Namespaces} from '../shared/DOMNamespaces';
|
|
import createMicrosoftUnsafeLocalFunction
|
|
from '../shared/createMicrosoftUnsafeLocalFunction';
|
|
|
|
// SVG temp container for IE lacking innerHTML
|
|
let reusableSVGContainer;
|
|
|
|
/**
|
|
* Set the innerHTML property of a node
|
|
*
|
|
* @param {DOMElement} node
|
|
* @param {string} html
|
|
* @internal
|
|
*/
|
|
const setInnerHTML = createMicrosoftUnsafeLocalFunction(function(node, html) {
|
|
// IE does not have innerHTML for SVG nodes, so instead we inject the
|
|
// new markup in a temp node and then move the child nodes across into
|
|
// the target node
|
|
|
|
if (node.namespaceURI === Namespaces.svg && !('innerHTML' in node)) {
|
|
reusableSVGContainer =
|
|
reusableSVGContainer || document.createElement('div');
|
|
reusableSVGContainer.innerHTML = '<svg>' + html + '</svg>';
|
|
const svgNode = reusableSVGContainer.firstChild;
|
|
while (node.firstChild) {
|
|
node.removeChild(node.firstChild);
|
|
}
|
|
while (svgNode.firstChild) {
|
|
node.appendChild(svgNode.firstChild);
|
|
}
|
|
} else {
|
|
node.innerHTML = html;
|
|
}
|
|
});
|
|
|
|
export default setInnerHTML;
|