This repository was archived by the owner on Sep 21, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed
packages/devtools-reps/src/object-inspector Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments