Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit a8906b6

Browse files
committed
Flush nodes cache when roots prop is updated.
Fixes #904. Add a test to make sure we don't regress this.
1 parent 2b4d6e9 commit a8906b6

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

packages/devtools-reps/src/object-inspector/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,15 @@ class ObjectInspector extends Component {
162162
expandedPaths,
163163
loadedProperties
164164
} = this.state;
165-
return this.props.roots !== nextProps.roots
166-
|| expandedPaths.size !== nextState.expandedPaths.size
165+
166+
if (this.props.roots !== nextProps.roots) {
167+
// Since the roots changed, we assume the properties did as well. Thus we can clear
168+
// the cachedNodes to avoid bugs and memory leaks.
169+
this.cachedNodes.clear();
170+
return true;
171+
}
172+
173+
return expandedPaths.size !== nextState.expandedPaths.size
167174
|| loadedProperties.size !== nextState.loadedProperties.size
168175
|| [...expandedPaths].some(key => !nextState.expandedPaths.has(key));
169176
}

packages/devtools-reps/src/object-inspector/tests/component/basic.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,40 @@ describe("ObjectInspector - renders", () => {
261261
}]});
262262
expect(formatObjectInspector(oi)).toMatchSnapshot();
263263
});
264+
265+
it("updates when the root changes but has same path", () => {
266+
let oi = mount(ObjectInspector(generateDefaults({
267+
roots: [{
268+
path: "root",
269+
name: "root",
270+
contents: [{
271+
name: "a",
272+
contents: {
273+
value: 30,
274+
}
275+
}, {
276+
name: "b",
277+
contents: {
278+
value: 32,
279+
}
280+
}]
281+
}],
282+
mode: MODE.LONG,
283+
})));
284+
oi.find(".node").at(0).simulate("click");
285+
286+
const oldTree = formatObjectInspector(oi);
287+
oi.setProps({roots: [{
288+
path: "root",
289+
name: "root",
290+
contents: [{
291+
name: "c",
292+
contents: {
293+
value: "i'm the new node",
294+
}
295+
}]
296+
}]});
297+
298+
expect(formatObjectInspector(oi)).not.toBe(oldTree);
299+
});
264300
});

0 commit comments

Comments
 (0)