Skip to content

Commit

Permalink
Fixed "Sending didSendNetworkData with no listeners registered" war…
Browse files Browse the repository at this point in the history
…ning

Summary:
XMLHttpRequest was sending the request before registering any listeners, resulting in a warning from the native event emitter.

Since we weren't seeing widespread problems with XHR missing data, this was probably working OK in practice because the queuing of events meant that the listener would have been registered before the message was actually delivered.

Still, this was working more through luck than design. This diff fixes it by registering the listeners *before* sending the request.

Reviewed By: lexs

Differential Revision: D3371320

fbshipit-source-id: c688d4053a61f856eaacccd0106905edbefcc86a
  • Loading branch information
nicklockwood authored and Facebook Github Bot 1 committed Jun 1, 2016
1 parent aa53770 commit bdcdfb0
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions Libraries/Network/XMLHttpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,6 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
// exposed for testing
__didCreateRequest(requestId: number): void {
this._requestId = requestId;
this._subscriptions.push(RCTNetworking.addListener(
'didSendNetworkData',
(args) => this.__didUploadProgress(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didReceiveNetworkResponse',
(args) => this._didReceiveResponse(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didReceiveNetworkData',
(args) => this._didReceiveData(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didCompleteNetworkResponse',
(args) => this.__didCompleteResponse(...args)
));
}

// exposed for testing
Expand Down Expand Up @@ -340,6 +324,22 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
useIncrementalUpdates: boolean,
timeout: number,
): void {
this._subscriptions.push(RCTNetworking.addListener(
'didSendNetworkData',
(args) => this.__didUploadProgress(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didReceiveNetworkResponse',
(args) => this._didReceiveResponse(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didReceiveNetworkData',
(args) => this._didReceiveData(...args)
));
this._subscriptions.push(RCTNetworking.addListener(
'didCompleteNetworkResponse',
(args) => this.__didCompleteResponse(...args)
));
RCTNetworking.sendRequest(
method,
url,
Expand Down

0 comments on commit bdcdfb0

Please sign in to comment.