Skip to content

Commit 47e217a

Browse files
raunofreiberggaearon
authored andcommitted
Provide component reference in ReactDOMFiberTextarea warnings (#13361)
* Provide component reference if possible in ReactDOMFiberTextarea.js warning * Nits
1 parent 714c78d commit 47e217a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

packages/react-dom/src/__tests__/ReactDOMTextarea-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,22 +399,22 @@ describe('ReactDOMTextarea', () => {
399399
});
400400

401401
it('should warn if value and defaultValue are specified', () => {
402+
const InvalidComponent = () => (
403+
<textarea value="foo" defaultValue="bar" readOnly={true} />
404+
);
402405
expect(() =>
403-
ReactTestUtils.renderIntoDocument(
404-
<textarea value="foo" defaultValue="bar" readOnly={true} />,
405-
),
406+
ReactTestUtils.renderIntoDocument(<InvalidComponent />),
406407
).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 ' +
408410
'(specify either the value prop, or the defaultValue prop, but not ' +
409411
'both). Decide between using a controlled or uncontrolled textarea ' +
410412
'and remove one of these props. More info: ' +
411413
'https://fb.me/react-controlled-components',
412414
);
413415

414416
// No additional warnings are expected
415-
ReactTestUtils.renderIntoDocument(
416-
<textarea value="foo" defaultValue="bar" readOnly={true} />,
417-
);
417+
ReactTestUtils.renderIntoDocument(<InvalidComponent />);
418418
});
419419

420420
it('should not warn about missing onChange in uncontrolled textareas', () => {

packages/react-dom/src/client/ReactDOMFiberTextarea.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import invariant from 'shared/invariant';
1111
import warning from 'shared/warning';
1212

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

1516
let didWarnValDefaultVal = false;
1617

@@ -70,11 +71,13 @@ export function initWrapperState(element: Element, props: Object) {
7071
) {
7172
warning(
7273
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 ' +
7476
'(specify either the value prop, or the defaultValue prop, but not ' +
7577
'both). Decide between using a controlled or uncontrolled textarea ' +
7678
'and remove one of these props. More info: ' +
7779
'https://fb.me/react-controlled-components',
80+
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
7881
);
7982
didWarnValDefaultVal = true;
8083
}

0 commit comments

Comments
 (0)