10
10
11
11
'use strict' ;
12
12
13
+ import type XMLHttpRequest from '../Network/XMLHttpRequest' ;
13
14
import type { RenderItemProps } from '@react-native/virtualized-lists' ;
14
15
15
16
import ScrollView from '../Components/ScrollView/ScrollView' ;
@@ -87,6 +88,18 @@ function keyExtractor(request: NetworkRequestInfo): string {
87
88
return String ( request . id ) ;
88
89
}
89
90
91
+ const XHR_ID_KEY = Symbol ( 'XHR_ID' ) ;
92
+
93
+ function getXHRId ( xhr : XMLHttpRequest ) : number {
94
+ // $FlowExpectedError[prop-missing]
95
+ return xhr [ XHR_ID_KEY ] ;
96
+ }
97
+
98
+ function setXHRId ( xhr : XMLHttpRequest , id : number ) {
99
+ // $FlowExpectedError[prop-missing]
100
+ xhr [ XHR_ID_KEY ] = id ;
101
+ }
102
+
90
103
/**
91
104
* Show all the intercepted network requests over the InspectorPanel.
92
105
*/
@@ -110,7 +123,7 @@ class NetworkOverlay extends React.Component<Props, State> {
110
123
111
124
// Map of `socketId` -> `index in `this.state.requests`.
112
125
_socketIdMap : { [ number ] : number } = { } ;
113
- // Map of `xhr._index ` -> `index in `this.state.requests`.
126
+ // Map of `xhr[XHR_ID_KEY] ` -> `index in `this.state.requests`.
114
127
_xhrIdMap : { [ key : number ] : number , ...} = { } ;
115
128
116
129
state : State = {
@@ -127,9 +140,9 @@ class NetworkOverlay extends React.Component<Props, State> {
127
140
// Generate a global id for each intercepted xhr object, add this id
128
141
// to the xhr object as a private `_index` property to identify it,
129
142
// so that we can distinguish different xhr objects in callbacks.
130
- xhr . _index = nextXHRId ++ ;
143
+ setXHRId ( xhr , nextXHRId ++ ) ;
131
144
const xhrIndex = this . state . requests . length ;
132
- this . _xhrIdMap [ xhr . _index ] = xhrIndex ;
145
+ this . _xhrIdMap [ getXHRId ( xhr ) ] = xhrIndex ;
133
146
134
147
const _xhr : NetworkRequestInfo = {
135
148
id : xhrIndex ,
@@ -147,7 +160,7 @@ class NetworkOverlay extends React.Component<Props, State> {
147
160
148
161
XHRInterceptor . setRequestHeaderCallback ( ( header , value , xhr ) => {
149
162
// $FlowFixMe[prop-missing]
150
- const xhrIndex = this . _getRequestIndexByXHRID ( xhr . _index ) ;
163
+ const xhrIndex = this . _getRequestIndexByXHRID ( getXHRId ( xhr ) ) ;
151
164
if ( xhrIndex === - 1 ) {
152
165
return ;
153
166
}
@@ -164,7 +177,7 @@ class NetworkOverlay extends React.Component<Props, State> {
164
177
165
178
XHRInterceptor . setSendCallback ( ( data , xhr ) => {
166
179
// $FlowFixMe[prop-missing]
167
- const xhrIndex = this . _getRequestIndexByXHRID ( xhr . _index ) ;
180
+ const xhrIndex = this . _getRequestIndexByXHRID ( getXHRId ( xhr ) ) ;
168
181
if ( xhrIndex === - 1 ) {
169
182
return ;
170
183
}
@@ -179,7 +192,7 @@ class NetworkOverlay extends React.Component<Props, State> {
179
192
XHRInterceptor . setHeaderReceivedCallback (
180
193
( type , size , responseHeaders , xhr ) => {
181
194
// $FlowFixMe[prop-missing]
182
- const xhrIndex = this . _getRequestIndexByXHRID ( xhr . _index ) ;
195
+ const xhrIndex = this . _getRequestIndexByXHRID ( getXHRId ( xhr ) ) ;
183
196
if ( xhrIndex === - 1 ) {
184
197
return ;
185
198
}
@@ -197,7 +210,7 @@ class NetworkOverlay extends React.Component<Props, State> {
197
210
XHRInterceptor . setResponseCallback (
198
211
( status , timeout , response , responseURL , responseType , xhr ) => {
199
212
// $FlowFixMe[prop-missing]
200
- const xhrIndex = this . _getRequestIndexByXHRID ( xhr . _index ) ;
213
+ const xhrIndex = this . _getRequestIndexByXHRID ( getXHRId ( xhr ) ) ;
201
214
if ( xhrIndex === - 1 ) {
202
215
return ;
203
216
}
0 commit comments