@samitouri / QOS-React-2 / commits / 945d041160

Add clearer invariant in processUpdates

The `updatedChildren[j].parentNode.removeChild(updatedChildren[j]);` line below can fail if (1) we're moving/moving the same node twice or (2) the node we're looking for is gone completely. This makes it easier to distinguish between the two cases. Perf shouldn't be a concern here because this is DOM code and invariants are fast in comparison. Test Plan: grunt test

Ben Alpert committed Apr 16, 2014 at 15:07 UTC 945d041160cb2fca3bde2c2422c46e6fe99af4dd
1 file changed +12
src/browser/ui/dom/DOMChildrenOperations.js
+12
@@ -23,6 +23,7 @@ var Danger = require('Danger');
23 var ReactMultiChildUpdateTypes = require('ReactMultiChildUpdateTypes');
24
25 var getTextContentAccessor = require('getTextContentAccessor');
26 +var invariant = require('invariant');
27
28 /**
29 * The DOM property to use when setting text content.
@@ -119,6 +120,17 @@ var DOMChildrenOperations = {
120 var updatedChild = update.parentNode.childNodes[updatedIndex];
121 var parentID = update.parentID;
122
123 + invariant(
124 + updatedChild,
125 + 'processUpdates(): Unable to find child %s of element. This ' +
126 + 'probably means the DOM was unexpectedly mutated (e.g., by the ' +
127 + 'browser), usually due to forgetting a <tbody> when using tables ' +
128 + 'or nesting <p> or <a> tags. Try inspecting the child nodes of the ' +
129 + 'element with React ID `%s`.',
130 + updatedIndex,
131 + parentID
132 + );
133 +
134 initialChildren = initialChildren || {};
135 initialChildren[parentID] = initialChildren[parentID] || [];
136 initialChildren[parentID][updatedIndex] = updatedChild;