@@ -62,8 +62,15 @@ export function inspectElement({
62
62
rendererID : number ,
63
63
| } ) : Promise < InspectElementReturnType > {
64
64
const { id } = element ;
65
+
66
+ // This could indicate that the DevTools UI has been closed and reopened.
67
+ // The in-memory cache will be clear but the backend still thinks we have cached data.
68
+ // In this case, we need to tell it to resend the full data.
69
+ const forceFullData = ! inspectedElementCache . has ( id ) ;
70
+
65
71
return inspectElementAPI ( {
66
72
bridge,
73
+ forceFullData,
67
74
id,
68
75
path,
69
76
rendererID,
@@ -74,7 +81,7 @@ export function inspectElement({
74
81
switch ( type ) {
75
82
case 'no-change' :
76
83
// This is a no-op for the purposes of our cache.
77
- inspectedElement = inspectedElementCache . get ( element . id ) ;
84
+ inspectedElement = inspectedElementCache . get ( id ) ;
78
85
if ( inspectedElement != null ) {
79
86
return [ inspectedElement , type ] ;
80
87
}
@@ -85,7 +92,7 @@ export function inspectElement({
85
92
case 'not-found' :
86
93
// This is effectively a no-op.
87
94
// If the Element is still in the Store, we can eagerly remove it from the Map.
88
- inspectedElementCache . remove ( element . id ) ;
95
+ inspectedElementCache . remove ( id ) ;
89
96
90
97
throw Error ( `Element "${ id } " not found` ) ;
91
98
@@ -98,7 +105,7 @@ export function inspectElement({
98
105
fullData . value ,
99
106
) ;
100
107
101
- inspectedElementCache . set ( element . id , inspectedElement ) ;
108
+ inspectedElementCache . set ( id , inspectedElement ) ;
102
109
103
110
return [ inspectedElement , type ] ;
104
111
@@ -108,7 +115,7 @@ export function inspectElement({
108
115
109
116
// A path has been hydrated.
110
117
// Merge it with the latest copy we have locally and resolve with the merged value.
111
- inspectedElement = inspectedElementCache . get ( element . id ) || null ;
118
+ inspectedElement = inspectedElementCache . get ( id ) || null ;
112
119
if ( inspectedElement !== null ) {
113
120
// Clone element
114
121
inspectedElement = { ...inspectedElement } ;
@@ -121,7 +128,7 @@ export function inspectElement({
121
128
hydrateHelper ( value , ( ( path : any ) : Path ) ) ,
122
129
) ;
123
130
124
- inspectedElementCache . set ( element . id , inspectedElement ) ;
131
+ inspectedElementCache . set ( id , inspectedElement ) ;
125
132
126
133
return [ inspectedElement , type ] ;
127
134
}
@@ -140,3 +147,7 @@ export function inspectElement({
140
147
throw Error ( `Unable to inspect element with id "${ id } "` ) ;
141
148
} ) ;
142
149
}
150
+
151
+ export function clearCacheForTests ( ) : void {
152
+ inspectedElementCache. reset ( ) ;
153
+ }
0 commit comments