From deb472865753fdb1414ec4c7da96e7c897828cb7 Mon Sep 17 00:00:00 2001 From: Jim Date: Tue, 14 Jun 2016 16:11:48 -0700 Subject: [PATCH] Move null-input-value-prop warning into devtool, add stack trace --- .../dom/client/wrappers/ReactDOMInput.js | 17 ------- .../dom/client/wrappers/ReactDOMSelect.js | 18 ------- .../dom/client/wrappers/ReactDOMTextarea.js | 19 ------- src/renderers/dom/shared/ReactDOMDebugTool.js | 2 + .../ReactDOMNullInputValuePropDevtool.js | 50 +++++++++++++++++++ 5 files changed, 52 insertions(+), 54 deletions(-) create mode 100644 src/renderers/dom/shared/devtools/ReactDOMNullInputValuePropDevtool.js diff --git a/src/renderers/dom/client/wrappers/ReactDOMInput.js b/src/renderers/dom/client/wrappers/ReactDOMInput.js index c4bcca0c8e31c..43158c2d26111 100644 --- a/src/renderers/dom/client/wrappers/ReactDOMInput.js +++ b/src/renderers/dom/client/wrappers/ReactDOMInput.js @@ -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; diff --git a/src/renderers/dom/client/wrappers/ReactDOMSelect.js b/src/renderers/dom/client/wrappers/ReactDOMSelect.js index 5fc85ef3db2ee..c693fb7036e05 100644 --- a/src/renderers/dom/client/wrappers/ReactDOMSelect.js +++ b/src/renderers/dom/client/wrappers/ReactDOMSelect.js @@ -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 diff --git a/src/renderers/dom/client/wrappers/ReactDOMTextarea.js b/src/renderers/dom/client/wrappers/ReactDOMTextarea.js index 3c06222f7af80..52f2ae8426463 100644 --- a/src/renderers/dom/client/wrappers/ReactDOMTextarea.js +++ b/src/renderers/dom/client/wrappers/ReactDOMTextarea.js @@ -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