Clarify reason for setTextContent helper (#11813)

* Update comment on setTextContent

update the comment explaining the reason for the helper

* Use `setTextContent` in ReactDOM for consistency
This commit is contained in:
Jason Quense
2018-01-05 13:10:12 -05:00
committed by Dan Abramov
parent 588198d266
commit 4e044f553f
2 changed files with 8 additions and 6 deletions

View File

@@ -43,6 +43,7 @@ import warning from 'fbjs/lib/warning';
import * as ReactDOMComponentTree from './ReactDOMComponentTree';
import * as ReactDOMFiberComponent from './ReactDOMFiberComponent';
import * as ReactInputSelection from './ReactInputSelection';
import setTextContent from './setTextContent';
import validateDOMNesting from './validateDOMNesting';
import * as ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
import * as ReactDOMEventListener from '../events/ReactDOMEventListener';
@@ -736,7 +737,7 @@ const DOMRenderer = ReactFiberReconciler({
},
resetTextContent(domElement: Instance): void {
domElement.textContent = '';
setTextContent(domElement, '');
},
commitTextUpdate(

View File

@@ -3,21 +3,22 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import {TEXT_NODE} from '../shared/HTMLNodeType';
/**
* Set the textContent property of a node, ensuring that whitespace is preserved
* even in IE8. innerText is a poor substitute for textContent and, among many
* issues, inserts <br> instead of the literal newline chars. innerHTML behaves
* as it should.
* Set the textContent property of a node. For text updates, it's faster
* to set the `nodeValue` of the Text node directly instead of using
* `.textContent` which will remove the existing node and create a new one.
*
* @param {DOMElement} node
* @param {string} text
* @internal
*/
let setTextContent = function(node, text) {
let setTextContent = function(node: Element, text: string): void {
if (text) {
let firstChild = node.firstChild;