Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide component reference in ReactDOMFiberTextarea warnings #13361

Merged
merged 2 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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