Move null-input-value-prop warning into devtool, add stack trace (#7040)

This commit is contained in:
Jim
2016-06-14 16:34:38 -07:00
committed by GitHub
parent 6e8c2fb828
commit 97d89fa5bf
5 changed files with 52 additions and 54 deletions
@@ -22,7 +22,6 @@ var warning = require('warning');
var didWarnValueLink = false;
var didWarnCheckedLink = false;
var didWarnValueNull = false;
var didWarnValueDefaultValue = false;
var didWarnCheckedDefaultChecked = false;
var didWarnControlledToUncontrolled = false;
@@ -35,19 +34,6 @@ function forceUpdateIfMounted() {
}
}
function warnIfValueIsNull(props) {
if (props != null && props.value === null && !didWarnValueNull) {
warning(
false,
'`value` prop on `input` should not be null. ' +
'Consider using the empty string to clear the component or `undefined` ' +
'for uncontrolled components.'
);
didWarnValueNull = true;
}
}
function isControlled(props) {
var usesChecked = props.type === 'checkbox' || props.type === 'radio';
return usesChecked ? props.checked !== undefined : props.value !== undefined;
@@ -149,7 +135,6 @@ var ReactDOMInput = {
);
didWarnValueDefaultValue = true;
}
warnIfValueIsNull(props);
}
var defaultValue = props.defaultValue;
@@ -169,8 +154,6 @@ var ReactDOMInput = {
var props = inst._currentElement.props;
if (__DEV__) {
warnIfValueIsNull(props);
var controlled = isControlled(props);
var owner = inst._currentElement._owner;
@@ -19,7 +19,6 @@ var ReactUpdates = require('ReactUpdates');
var warning = require('warning');
var didWarnValueLink = false;
var didWarnValueNull = false;
var didWarnValueDefaultValue = false;
function updateOptionsIfPendingUpdateAndMounted() {
@@ -45,19 +44,6 @@ function getDeclarationErrorAddendum(owner) {
return '';
}
function warnIfValueIsNull(props) {
if (props != null && props.value === null && !didWarnValueNull) {
warning(
false,
'`value` prop on `select` should not be null. ' +
'Consider using the empty string to clear the component or `undefined` ' +
'for uncontrolled components.'
);
didWarnValueNull = true;
}
}
var valuePropNames = ['value', 'defaultValue'];
/**
@@ -168,7 +154,6 @@ var ReactDOMSelect = {
mountWrapper: function(inst, props) {
if (__DEV__) {
checkSelectPropTypes(inst, props);
warnIfValueIsNull(props);
}
var value = LinkedValueUtils.getValue(props);
@@ -205,9 +190,6 @@ var ReactDOMSelect = {
postUpdateWrapper: function(inst) {
var props = inst._currentElement.props;
if (__DEV__) {
warnIfValueIsNull(props);
}
// After the initial mount, we control selected-ness manually so don't pass
// this value down
@@ -20,7 +20,6 @@ var invariant = require('invariant');
var warning = require('warning');
var didWarnValueLink = false;
var didWarnValueNull = false;
var didWarnValDefaultVal = false;
function forceUpdateIfMounted() {
@@ -30,19 +29,6 @@ function forceUpdateIfMounted() {
}
}
function warnIfValueIsNull(props) {
if (props != null && props.value === null && !didWarnValueNull) {
warning(
false,
'`value` prop on `textarea` should not be null. ' +
'Consider using the empty string to clear the component or `undefined` ' +
'for uncontrolled components.'
);
didWarnValueNull = true;
}
}
/**
* Implements a <textarea> host component that allows setting `value`, and
* `defaultValue`. This differs from the traditional DOM API because value is
@@ -109,7 +95,6 @@ var ReactDOMTextarea = {
);
didWarnValDefaultVal = true;
}
warnIfValueIsNull(props);
}
@@ -159,10 +144,6 @@ var ReactDOMTextarea = {
updateWrapper: function(inst) {
var props = inst._currentElement.props;
if (__DEV__) {
warnIfValueIsNull(props);
}
var node = ReactDOMComponentTree.getNodeFromInstance(inst);
var value = LinkedValueUtils.getValue(props);
if (value != null) {
@@ -11,6 +11,7 @@
'use strict';
var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
var ReactDebugTool = require('ReactDebugTool');
@@ -68,5 +69,6 @@ var ReactDOMDebugTool = {
};
ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);
module.exports = ReactDOMDebugTool;
@@ -0,0 +1,50 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactDOMNullInputValuePropDevtool
*/
'use strict';
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
var warning = require('warning');
var didWarnValueNull = false;
function handleElement(debugID, element) {
if (element == null) {
return;
}
if (element.type !== 'input' && element.type !== 'textarea' && element.type !== 'select') {
return;
}
if (element.props != null && element.props.value === null && !didWarnValueNull) {
warning(
false,
'`value` prop on `%s` should not be null. ' +
'Consider using the empty string to clear the component or `undefined` ' +
'for uncontrolled components.%s',
element.type,
ReactComponentTreeDevtool.getStackAddendumByID(debugID)
);
didWarnValueNull = true;
}
}
var ReactDOMUnknownPropertyDevtool = {
onBeforeMountComponent(debugID, element) {
handleElement(debugID, element);
},
onBeforeUpdateComponent(debugID, element) {
handleElement(debugID, element);
},
};
module.exports = ReactDOMUnknownPropertyDevtool;