mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
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:
committed by
Dan Abramov
parent
588198d266
commit
4e044f553f
3
packages/react-dom/src/client/ReactDOM.js
vendored
3
packages/react-dom/src/client/ReactDOM.js
vendored
@@ -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(
|
||||
|
||||
11
packages/react-dom/src/client/setTextContent.js
vendored
11
packages/react-dom/src/client/setTextContent.js
vendored
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user