@samitouri / QOS-React-2 / commits / d1d2d8d463
Fork 0

The library for web and native user interfaces.

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.

Paul O'Shannessy committed Jul 22, 2013 at 10:27 UTC d1d2d8d4636b881bfbe25c9712d5b61efc5c1ea9
1 file changed +9 -1
src/core/ReactDOMIDOperations.js
+9 -1
@@ -71,7 +71,15 @@ var ReactDOMIDOperations = {
71 'updatePropertyByID(...): %s',
72 INVALID_PROPERTY_ERRORS[name]
73 );
74 - DOMPropertyOperations.setValueForProperty(node, name, value);
74 +
75 + // If we're updating to null or undefined, we should remove the property
76 + // from the DOM node instead of inadvertantly setting to a string. This
77 + // brings us in line with the same behavior we have on initial render.
78 + if (value != null) {
79 + DOMPropertyOperations.setValueForProperty(node, name, value);
80 + } else {
81 + DOMPropertyOperations.deleteValueForProperty(node, name);
82 + }
83 },
84
85 /**