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

ObjectInspector is not updated if roots changed but kept same path #904

@nchevobbe

Description

@nchevobbe

Steps to reproduce:

  1. Set an ObjectInspector with a roots object
  2. Expand it
  3. 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);
+  });
 });

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions