@samitouri / QOS-React / commits / 47e217a77d

Provide component reference in ReactDOMFiberTextarea warnings (#13361)

* Provide component reference if possible in ReactDOMFiberTextarea.js warning * Nits

Rauno Freiberg committed Aug 13, 2018 at 17:55 UTC 47e217a77d302cdafed76f92119252e9bdae94f0
2 files changed +11 -8
packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
+7 -7
@@ -399,12 +399,14 @@ describe('ReactDOMTextarea', () => {
399 });
400
401 it('should warn if value and defaultValue are specified', () => {
402 + const InvalidComponent = () => (
403 + <textarea value="foo" defaultValue="bar" readOnly={true} />
404 + );
405 expect(() =>
403 - ReactTestUtils.renderIntoDocument(
404 - <textarea value="foo" defaultValue="bar" readOnly={true} />,
405 - ),
406 + ReactTestUtils.renderIntoDocument(<InvalidComponent />),
407 ).toWarnDev(
407 - 'Textarea elements must be either controlled or uncontrolled ' +
408 + 'InvalidComponent contains a textarea with both value and defaultValue props. ' +
409 + 'Textarea elements must be either controlled or uncontrolled ' +
410 '(specify either the value prop, or the defaultValue prop, but not ' +
411 'both). Decide between using a controlled or uncontrolled textarea ' +
412 'and remove one of these props. More info: ' +
@@ -412,9 +414,7 @@ describe('ReactDOMTextarea', () => {
414 );
415
416 // No additional warnings are expected
415 - ReactTestUtils.renderIntoDocument(
416 - <textarea value="foo" defaultValue="bar" readOnly={true} />,
417 - );
417 + ReactTestUtils.renderIntoDocument(<InvalidComponent />);
418 });
419
420 it('should not warn about missing onChange in uncontrolled textareas', () => {
packages/react-dom/src/client/ReactDOMFiberTextarea.js
+4 -1
@@ -11,6 +11,7 @@ import invariant from 'shared/invariant';
11 import warning from 'shared/warning';
12
13 import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';
14 +import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
15
16 let didWarnValDefaultVal = false;
17
@@ -70,11 +71,13 @@ export function initWrapperState(element: Element, props: Object) {
71 ) {
72 warning(
73 false,
73 - 'Textarea elements must be either controlled or uncontrolled ' +
74 + '%s contains a textarea with both value and defaultValue props. ' +
75 + 'Textarea elements must be either controlled or uncontrolled ' +
76 '(specify either the value prop, or the defaultValue prop, but not ' +
77 'both). Decide between using a controlled or uncontrolled textarea ' +
78 'and remove one of these props. More info: ' +
79 'https://fb.me/react-controlled-components',
80 + getCurrentFiberOwnerNameInDevOrNull() || 'A component',
81 );
82 didWarnValDefaultVal = true;
83 }