ObjectInspector is not updated if roots changed but kept same path
nchevobbe opened this issue · comments
Nicolas Chevobbe commented
Steps to reproduce:
- Set an ObjectInspector with a
roots
object - Expand it
- Update the
roots
object to another object, but keep the same path value
Expected results:
The ObjectInspector is updated and shows the new roots
children
Actual results:
The ObjectInspector is not updated.
This is due to the fact that we cache nodes, and never clear the cache. The getChildren
then uses this cache and find matching nodes since the path stayed the same.
This issue is resolved when the following test pass:
diff --git a/packages/devtools-reps/src/object-inspector/tests/component/basic.js b/packages/devtools-reps/src/object-inspector/tests/component/basic.js
index bf27ca0..80800e8 100644
--- a/packages/devtools-reps/src/object-inspector/tests/component/basic.js
+++ b/packages/devtools-reps/src/object-inspector/tests/component/basic.js
@@ -261,4 +261,40 @@ describe("ObjectInspector - renders", () => {
}]});
expect(formatObjectInspector(oi)).toMatchSnapshot();
});
+
+ it("updates when the root changes but has same path", () => {
+ let oi = mount(ObjectInspector(generateDefaults({
+ roots: [{
+ path: "root",
+ name: "root",
+ contents: [{
+ name: "a",
+ contents: {
+ value: 30,
+ }
+ }, {
+ name: "b",
+ contents: {
+ value: 32,
+ }
+ }]
+ }],
+ mode: MODE.LONG,
+ })));
+ oi.find(".node").at(0).simulate("click");
+
+ const oldTree = formatObjectInspector(oi);
+ oi.setProps({roots: [{
+ path: "root",
+ name: "root",
+ contents: [{
+ name: "c",
+ contents: {
+ value: "i'm the new node",
+ }
+ }]
+ }]});
+
+ expect(formatObjectInspector(oi)).not.toBe(oldTree);
+ });
});