Fixed bug in reset-children to properly calculate new root weight
Brian Vaughn committed
Apr 18, 2019 at 09:54 UTC
d6e829d7a5f0b105930e26f21fe05562e495fab3
3 files changed
+24
-4
src/__tests__/__snapshots__/store-test.js.snap
+7
@@ -407,3 +407,10 @@ exports[`Store should not allow a root node to be collapsed: 1: mount 1`] = `
407
[root]
408
<Component>
409
`;
410
+
411
+exports[`Store should properly handle a root with no visible nodes: 1: mount 1`] = `
412
+[root]
413
+ <Root>
414
+`;
415
+
416
+exports[`Store should properly handle a root with no visible nodes: 2: add host nodes 1`] = `[root]`;
src/__tests__/store-test.js
+12
@@ -40,6 +40,18 @@ describe('Store', () => {
40
);
41
});
42
43
+ it('should properly handle a root with no visible nodes', () => {
44
+ const Root = ({ children }) => children;
45
+
46
+ const container = document.createElement('div');
47
+
48
+ act(() => ReactDOM.render(<Root>{null}</Root>, container));
49
+ expect(store).toMatchSnapshot('1: mount');
50
+
51
+ act(() => ReactDOM.render(<div />, container));
52
+ expect(store).toMatchSnapshot('2: add host nodes');
53
+ });
54
+
55
describe('collapseNodesByDefault:false', () => {
56
beforeEach(() => {
57
store.collapseNodesByDefault = false;
src/devtools/store.js
+5
-4
@@ -768,16 +768,17 @@ export default class Store extends EventEmitter {
768
769
if (!element.isCollapsed) {
770
const prevWeight = element.weight;
771
- let childWeight = 0;
771
+
772
+ let nextWeight = element.type === ElementTypeRoot ? 0 : 1;
773
774
children.forEach(childID => {
775
const child = ((this._idToElement.get(childID): any): Element);
775
- childWeight += child.isCollapsed ? 1 : child.weight;
776
+ nextWeight += child.isCollapsed ? 1 : child.weight;
777
});
778
778
- element.weight = childWeight + 1;
779
+ element.weight = nextWeight;
780
780
- weightDelta = childWeight + 1 - prevWeight;
781
+ weightDelta = nextWeight - prevWeight;
782
}
783
break;
784
case TREE_OPERATION_UPDATE_TREE_BASE_DURATION: