Skip to content

Commit

Permalink
Clarify reason for setTextContent helper (facebook#11813)
Browse files Browse the repository at this point in the history
* Update comment on setTextContent

update the comment explaining the reason for the helper

* Use `setTextContent` in ReactDOM for consistency
  • Loading branch information
jquense authored and yenshih committed Jan 6, 2018
1 parent e83ec6d commit faa1f40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -736,7 +737,7 @@ const DOMRenderer = ReactFiberReconciler({
},

resetTextContent(domElement: Instance): void {
domElement.textContent = '';
setTextContent(domElement, '');
},

commitTextUpdate(
Expand Down
11 changes: 6 additions & 5 deletions packages/react-dom/src/client/setTextContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit faa1f40

Please sign in to comment.