Skip to content

Commit

Permalink
Provide component reference in ReactDOMFiberTextarea warnings (#13361)
Browse files Browse the repository at this point in the history
* Provide component reference if possible in ReactDOMFiberTextarea.js warning

* Nits
  • Loading branch information
raunofreiberg authored and gaearon committed Aug 13, 2018
1 parent 714c78d commit 47e217a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,22 +399,22 @@ describe('ReactDOMTextarea', () => {
});

it('should warn if value and defaultValue are specified', () => {
const InvalidComponent = () => (
<textarea value="foo" defaultValue="bar" readOnly={true} />
);
expect(() =>
ReactTestUtils.renderIntoDocument(
<textarea value="foo" defaultValue="bar" readOnly={true} />,
),
ReactTestUtils.renderIntoDocument(<InvalidComponent />),
).toWarnDev(
'Textarea elements must be either controlled or uncontrolled ' +
'InvalidComponent contains a textarea with both value and defaultValue props. ' +
'Textarea elements must be either controlled or uncontrolled ' +
'(specify either the value prop, or the defaultValue prop, but not ' +
'both). Decide between using a controlled or uncontrolled textarea ' +
'and remove one of these props. More info: ' +
'https://fb.me/react-controlled-components',
);

// No additional warnings are expected
ReactTestUtils.renderIntoDocument(
<textarea value="foo" defaultValue="bar" readOnly={true} />,
);
ReactTestUtils.renderIntoDocument(<InvalidComponent />);
});

it('should not warn about missing onChange in uncontrolled textareas', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/react-dom/src/client/ReactDOMFiberTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import invariant from 'shared/invariant';
import warning from 'shared/warning';

import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';
import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';

let didWarnValDefaultVal = false;

Expand Down Expand Up @@ -70,11 +71,13 @@ export function initWrapperState(element: Element, props: Object) {
) {
warning(
false,
'Textarea elements must be either controlled or uncontrolled ' +
'%s contains a textarea with both value and defaultValue props. ' +
'Textarea elements must be either controlled or uncontrolled ' +
'(specify either the value prop, or the defaultValue prop, but not ' +
'both). Decide between using a controlled or uncontrolled textarea ' +
'and remove one of these props. More info: ' +
'https://fb.me/react-controlled-components',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
);
didWarnValDefaultVal = true;
}
Expand Down

0 comments on commit 47e217a

Please sign in to comment.