Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
[webchannel][js] Fix useFetchStreams duplicate message dispatch issue.
Browse files Browse the repository at this point in the history
RELNOTES: n/a

PiperOrigin-RevId: 578901815
Change-Id: Ifc4357edd504cdb30224e64bfb7fbde9a05b6cd7
  • Loading branch information
sampajano authored and copybara-github committed Nov 2, 2023
1 parent 5bd7be2 commit 7818ff7
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions closure/goog/labs/net/webchannel/channelrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ ChannelRequest.prototype.decodeXmlHttpResponse_ = function() {
responseText += this.fetchResponseState_.textDecoder.decode(
responseChunks[i], {stream: isLastChunk});
}
responseChunks.splice(0, responseLength);
responseChunks.length = 0; // Empty the `responseChunks` array.
this.fetchResponseState_.responseBuffer += responseText;
this.xmlHttpChunkStart_ = 0;
return this.fetchResponseState_.responseBuffer;
Expand Down Expand Up @@ -906,22 +906,6 @@ ChannelRequest.prototype.useFetchStreamsForResponse_ = function() {
};


/**
* Resets the response buffer if the saved chunk has been processed.
* @private
* @param {string|!Object|undefined} chunkText
*/
ChannelRequest.prototype.maybeResetBuffer_ = function(chunkText) {
'use strict';
if (this.useFetchStreamsForResponse_() &&
chunkText != ChannelRequest.INCOMPLETE_CHUNK_ &&
chunkText != ChannelRequest.INVALID_CHUNK_) {
this.fetchResponseState_.responseBuffer = '';
this.xmlHttpChunkStart_ = 0;
}
};


/**
* Decodes the next set of available chunks in the response.
* @param {number} readyState The value of readyState.
Expand Down Expand Up @@ -960,7 +944,12 @@ ChannelRequest.prototype.decodeNextChunks_ = function(
}
}

this.maybeResetBuffer_(chunkText);
if (this.useFetchStreamsForResponse_() && this.xmlHttpChunkStart_ != 0) {
// Remove processed chunk text from response buffer.
this.fetchResponseState_.responseBuffer =
this.fetchResponseState_.responseBuffer.slice(this.xmlHttpChunkStart_);
this.xmlHttpChunkStart_ = 0;
}

if (readyState == goog.net.XmlHttp.ReadyState.COMPLETE &&
responseText.length == 0 &&
Expand Down

0 comments on commit 7818ff7

Please sign in to comment.