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

Commit a57f3e5

Browse files
committed
Don't add root actors to the state of the ObjectInspector.
The actors property on the ObjectInspector state keep track of all the actors that need to be released when we're done with the component. The problem of releasing the root actor is that if the comsumer of the OI was simply hidden, and then shown again, the user would not be able to expand the objectInspector. Here we don't track root actors so the consumer handle the lifetime of the root actors it handles. This causes no issues for non-root actors, since the ObjectInspector is unmounted, if the user want to expand it again after a hide/show cycle again, we'll end up creating new ObjectClient (and actors thus).
1 parent 109624c commit a57f3e5

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,15 @@ class ObjectInspector extends Component {
315315
const nextLoading = new Map(prevState.loading);
316316
nextLoading.delete(path);
317317

318+
const isRoot = this.props.roots.some(root => {
319+
const rootValue = getValue(root);
320+
return rootValue && rootValue.actor === value.actor;
321+
});
322+
318323
return {
319-
actors: (new Set(prevState.actors)).add(value.actor),
324+
actors: isRoot
325+
? prevState.actors
326+
: (new Set(prevState.actors)).add(value.actor),
320327
loadedProperties: (new Map(prevState.loadedProperties)).set(path, response),
321328
loading: nextLoading,
322329
};

packages/devtools-reps/src/object-inspector/tests/component/__snapshots__/state.js.snap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ exports[`ObjectInspector - state has the expected state when expanding a node 1`
4242
4343
exports[`ObjectInspector - state has the expected state when expanding a node 2`] = `
4444
"▼ {}
45-
| __proto__: Object { }
45+
| ▶︎ __proto__: Object { }
46+
▶︎ Proxy { <target>: {}, <handler>: […] }"
47+
`;
48+
49+
exports[`ObjectInspector - state has the expected state when expanding a node 3`] = `
50+
"▼ {}
51+
| ▼ __proto__: {}
52+
| | ▶︎ __proto__: Object { }
4653
▶︎ Proxy { <target>: {}, <handler>: […] }"
4754
`;
4855

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const ObjectInspector = createFactory(require("../../index"));
1111
const repsPath = "../../../reps";
1212
const gripRepStubs = require(`${repsPath}/stubs/grip`);
1313
const ObjectClient = require("../__mocks__/object-client");
14+
const stub = gripRepStubs.get("testMoreThanMaxProps");
1415

1516
function generateDefaults(overrides) {
16-
const stub = gripRepStubs.get("testMoreThanMaxProps");
1717
return Object.assign({
1818
autoExpandDepth: 0,
1919
roots: [{
@@ -29,7 +29,6 @@ function generateDefaults(overrides) {
2929
describe("release actors", () => {
3030
it("release actors when unmount", () => {
3131
const releaseActor = jest.fn();
32-
// The window node should have the "lessen" class when collapsed.
3332
const props = generateDefaults({
3433
releaseActor,
3534
});

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,19 @@ describe("ObjectInspector - state", () => {
8585
});
8686

8787
it("has the expected state when expanding a node", async () => {
88-
const wrapper = mount(ObjectInspector(generateDefaults({})));
88+
const protoStub = {
89+
"prototype": {
90+
"type": "object",
91+
"actor": "server2.conn0.child1/obj628",
92+
"class": "Object",
93+
}
94+
};
95+
96+
const wrapper = mount(ObjectInspector(generateDefaults({
97+
createObjectClient: grip => ObjectClient(grip, {
98+
getPrototype: () => Promise.resolve(protoStub)
99+
}),
100+
})));
89101
expect(formatObjectInspector(wrapper)).toMatchSnapshot();
90102
let nodes = wrapper.find(".node");
91103

@@ -104,9 +116,28 @@ describe("ObjectInspector - state", () => {
104116
state = wrapper.state();
105117
expect(state.loading.has("root-1")).toBeFalsy();
106118
expect(state.loadedProperties.has("root-1")).toBeTruthy();
119+
// We don't want to track root actors.
107120
expect(state.actors.has(gripRepStubs.get("testMoreThanMaxProps").actor))
108-
.toBeTruthy();
121+
.toBeFalsy();
109122
expect(formatObjectInspector(wrapper)).toMatchSnapshot();
123+
124+
nodes = wrapper.find(".node");
125+
const protoNode = nodes.at(1);
126+
protoNode.simulate("click");
127+
128+
state = wrapper.state();
129+
expect(state.loading.has("root-1/__proto__")).toBeTruthy();
130+
131+
// Once all the loading promises are resolved, the loading
132+
// state property should be cleaned up, and actors and loadedProperties
133+
// should have the expected values.
134+
await Promise.all(state.loading.get("root-1/__proto__"));
135+
expect(formatObjectInspector(wrapper)).toMatchSnapshot();
136+
state = wrapper.state();
137+
138+
expect(state.loading.has("root-1/__proto__")).toBeFalsy();
139+
expect(state.loadedProperties.has("root-1/__proto__")).toBeTruthy();
140+
expect(state.actors.has(protoStub.prototype.actor)).toBeTruthy();
110141
});
111142

112143
it("has the expected state when expanding a proxy node", async () => {
@@ -143,7 +174,8 @@ describe("ObjectInspector - state", () => {
143174
state = wrapper.state();
144175
expect(state.loading.has("root-2")).toBeFalsy();
145176
expect(state.loadedProperties.get("root-2")).toEqual(protoStub);
146-
expect(state.actors.has(gripRepStubs.get("testProxy").actor)).toBeTruthy();
177+
// We don't want to track root actors.
178+
expect(state.actors.has(gripRepStubs.get("testProxy").actor)).toBeFalsy();
147179

148180
nodes = wrapper.find(".node");
149181
const protoNode = nodes.at(4);

0 commit comments

Comments
 (0)