From d1d2d8d4636b881bfbe25c9712d5b61efc5c1ea9 Mon Sep 17 00:00:00 2001 From: Paul O'Shannessy Date: Mon, 22 Jul 2013 10:27:00 -0700 Subject: [PATCH] Don't set DOM attributes to `"undefined"` on update We already skip `null` and `undefined` when building up the stringified html on first render, but if you update a component to the *exact same* conditions, React will leave the DOM in a different state. We shouldn't do that. --- src/core/ReactDOMIDOperations.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/ReactDOMIDOperations.js b/src/core/ReactDOMIDOperations.js index a0ddd01720..c98edcbe8f 100644 --- a/src/core/ReactDOMIDOperations.js +++ b/src/core/ReactDOMIDOperations.js @@ -71,7 +71,15 @@ var ReactDOMIDOperations = { 'updatePropertyByID(...): %s', INVALID_PROPERTY_ERRORS[name] ); - DOMPropertyOperations.setValueForProperty(node, name, value); + + // If we're updating to null or undefined, we should remove the property + // from the DOM node instead of inadvertantly setting to a string. This + // brings us in line with the same behavior we have on initial render. + if (value != null) { + DOMPropertyOperations.setValueForProperty(node, name, value); + } else { + DOMPropertyOperations.deleteValueForProperty(node, name); + } }, /**