[Scopes] expanded properties are not updated while stepping #2509
Conversation
Hi @jasonLaster The expanded properties would not be updated while stepping is because we're getting the properties from the cache actor instead of the current item's properties. The solution that I got fixes this issue but there is one drawback: we're not actually updating the cache actor; instead, we modify the cache actor locally and return this object to getChildren. Please let me know if there is a better way to tackle this issue. 😄 |
src/utils/object-inspector.js
Outdated
} | ||
} | ||
} | ||
return thisActor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! If we move this change to the ObjectInspector.js here instead.
Then we can do this.props.setActors(actors);
after, which will set the cached actor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion! I thought using this.props.setActors(actors);
in render
would cause an error, but I was wrong! Thank you! 😊
Looking good! |
Codecov Report
@@ Coverage Diff @@
## master #2509 +/- ##
==========================================
+ Coverage 53.24% 54.36% +1.12%
==========================================
Files 51 51
Lines 1959 1970 +11
Branches 393 396 +3
==========================================
+ Hits 1043 1071 +28
+ Misses 916 899 -17
Continue to review full report at Codecov.
|
src/components/Editor/Preview.js
Outdated
@@ -100,6 +100,7 @@ class Preview extends Component { | |||
onDoubleClick: () => {}, | |||
loadObjectProperties, | |||
getActors: () => ({}), | |||
setActors: () => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will return undefined
, should be setActors: () => ({})
instead
@@ -162,6 +162,7 @@ class Expressions extends React.Component { | |||
this.editExpression(expression, options), | |||
loadObjectProperties, | |||
getActors: () => ({}), | |||
setActors: () => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -122,6 +122,26 @@ const ObjectInspector = React.createClass({ | |||
getChildren(item: ObjectInspectorItem) { | |||
const { getObjectProperties } = this.props; | |||
const { actors } = this; | |||
const key = item.path; | |||
|
|||
if (item.contents.value && item.contents.value.preview && actors[key]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny note, just for security ... actors && actors[key]
} | ||
} | ||
actors[key] = thisActor; | ||
this.props.setActors(actors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we can simplify the cache significantly.
The way i see it working is that it would keep a key of IDs that are expanded and that's it. This way, values don't need to be synced...
src/utils/object-inspector.js
Outdated
} | ||
index++; | ||
}); | ||
return thisActor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding actors[key] = thisActor;
above this line should update actorCache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also , the actors[key]
only goes stale across the ObjectInspector
component loads (i.e during stepping), therefore across internal component renders we should still be fine doing return actors[key]
if it exists, due to performance reasons.
Hi @bomsy and @jasonLaster I've reverted to previous implementation where the code logic for detecting/updating
To @bomsy: |
ok looking and testing .. |
actors[key] = thisActor; | ||
this.props.setActors(actors); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this move to utils/object-inspector
and get some unit tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple simplifying comments
@@ -221,4 +222,63 @@ describe("promises", () => { | |||
const node = getPromiseProperties(promise); | |||
expect(node.contents.value.type).to.eql("3"); | |||
}); | |||
|
|||
it("update actors when necessary", () => { | |||
const item = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove some of the data from this fixture so that it is much smaller. for instance, do we need the entire value
? Can we remove preview
's contents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please check my new commit :)
@@ -181,6 +181,22 @@ function getChildren( | |||
// node would be a new instance every render. | |||
const key = item.path; | |||
if (actors && actors[key]) { | |||
if (item.contents.value && item.contents.value.preview) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this code to an updateActor
helper function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem 🙂
…devtools#2509) * Fix expanded properties are not updated while stepping * Revert yarn.lock * Move code logic to ObjectInspector * Made a few corrections * Retrieve property values * Remove code from previous commit * Revert to previous implementation * Revert yarn.lock * Move code logic to object-inspector and add a unit test * Simplify code
Associated Issue: #2394
Summary of Changes
Test Plan
Screenshots/Videos (OPTIONAL)