The library for web and native user interfaces.
Continue over ID-less children in ReactMount.findComponentRoot.
This fixes our perf test by coping with edge cases like the injection of `<tbody>` between `<table>` and `<tr>` nodes, which occurs automatically in some browsers when we set `.innerHTML`. Introducing more search branches would be risky if not for my previous commit that made `findComponentRoot` breadth-first instead of depth-first.
Ben Newman committed
Jul 8, 2013 at 11:48 UTC
a4123a069ef05b6fdbb065d060baee47a61ec3ec
2 files changed
+16
-4
src/core/ReactInstanceHandles.js
+7
@@ -303,6 +303,13 @@ var ReactInstanceHandles = {
303
firstChildren.push(child.firstChild);
304
break;
305
}
306
+ } else {
307
+ // If this child had no ID, then there's a chance that it was
308
+ // injected automatically by the browser, as when a `<table>`
309
+ // element sprouts an extra `<tbody>` child as a side effect of
310
+ // `.innerHTML` parsing. Optimistically continue down this
311
+ // branch, but not before examining the other siblings.
312
+ firstChildren.push(child.firstChild);
313
}
314
child = child.nextSibling;
315
}
src/core/__tests__/ReactInstanceHandles-test.js
+9
-4
@@ -133,15 +133,20 @@ describe('ReactInstanceHandles', function() {
133
// No ID on `childNodeA`, it was "rendered by the browser".
134
ReactID.setID(childNodeB, '.react[0].1:0');
135
136
+ expect(ReactInstanceHandles.findComponentRoot(
137
+ parentNode,
138
+ ReactID.getID(childNodeB)
139
+ )).toBe(childNodeB);
140
+
141
expect(function() {
142
ReactInstanceHandles.findComponentRoot(
143
parentNode,
139
- ReactID.getID(childNodeB)
144
+ ReactID.getID(childNodeB) + ":junk"
145
);
146
}).toThrow(
142
- 'Invariant Violation: findComponentRoot(..., .react[0].1:0): Unable ' +
143
- 'to find element. This probably means the DOM was unexpectedly ' +
144
- 'mutated (e.g. by the browser).'
147
+ 'Invariant Violation: findComponentRoot(..., .react[0].1:0:junk): ' +
148
+ 'Unable to find element. This probably means the DOM was ' +
149
+ 'unexpectedly mutated (e.g. by the browser).'
150
);
151
});
152
});