-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clients(lightrider): always get transferSize from X-TotalFetchedSize header #7478
Changes from 6 commits
8406bc9
e8cbbe2
49c70ca
a208c69
fd7d187
17e6bd8
9ff988b
852ed20
e669481
779fcfa
e50eb65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -191,7 +191,7 @@ module.exports = class NetworkRequest { | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
this._updateResponseReceivedTimeIfNecessary(); | ||||||||||||||
this._updateTransferSizeForLightRiderIfNecessary(); | ||||||||||||||
this._updateTransferSizeForLightrider(); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -209,6 +209,7 @@ module.exports = class NetworkRequest { | |||||||||||||
this.localizedFailDescription = data.errorText; | ||||||||||||||
|
||||||||||||||
this._updateResponseReceivedTimeIfNecessary(); | ||||||||||||||
this._updateTransferSizeForLightrider(); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -246,6 +247,18 @@ module.exports = class NetworkRequest { | |||||||||||||
|
||||||||||||||
this.responseReceivedTime = timestamp; | ||||||||||||||
|
||||||||||||||
this.responseHeadersText = response.headersText || ''; | ||||||||||||||
this.responseHeaders = NetworkRequest._headersDictToHeadersArray(response.headers); | ||||||||||||||
|
||||||||||||||
// The total length of the encoded data is spread out among multiple events. The sum of the | ||||||||||||||
// values in onResponseReceived and all the onDataReceived events will equal the value | ||||||||||||||
// seen on the onLoadingFinished event. As we process onResonseReceived and onDataReceived | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't know exactly what leads to a situation when the loadingFinished total is different than the sum of the parts, but apparently it does happen. I just tried against 6 saved devtoolslogs i have. (Disclaimer: the artifacts were collected months ago definitely without networkservice, though I wouldn't expect it to matter)... There's, 320 network requests in total and nearly all of them have a sum that matches (or the sum was 0).. But I found 3 requests where this wasn't the case.
Again.. don't know what leads to this situation, but it happens. I'm happy with admitting that in the comment or we can ask caseq/network people about the circumstances.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooh that is funky. With NS off, it's good. But on it was off by 5 for "empty_module?delay=500". And there was no |
||||||||||||||
// we accumulate the total encodedDataLength. When we process onLoadingFinished, we override | ||||||||||||||
// the accumulated total. We do this so that if the request is aborted or fails, we still get | ||||||||||||||
// a value via the accumulation. | ||||||||||||||
// In Lightrider, we do not have true value for encodedDataLength, and we get the actual size | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Looks like we do, as of now.. We just override the transferSize in loadingFinished Thank you VERY MUCH for writing all this shit out. These comments are so Good. here's a very small rewrite of this second para for clarity:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops thanks for the revisions ❤️ |
||||||||||||||
// of the encoded data via a special response header. Because the values are totally bogus, | ||||||||||||||
// we do no accumulation. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move comment down to |
||||||||||||||
this.transferSize = response.encodedDataLength; | ||||||||||||||
if (typeof response.fromDiskCache === 'boolean') this.fromDiskCache = response.fromDiskCache; | ||||||||||||||
|
||||||||||||||
|
@@ -254,15 +267,11 @@ module.exports = class NetworkRequest { | |||||||||||||
this.timing = response.timing; | ||||||||||||||
if (resourceType) this.resourceType = RESOURCE_TYPES[resourceType]; | ||||||||||||||
this.mimeType = response.mimeType; | ||||||||||||||
this.responseHeadersText = response.headersText || ''; | ||||||||||||||
this.responseHeaders = NetworkRequest._headersDictToHeadersArray(response.headers); | ||||||||||||||
|
||||||||||||||
this.fetchedViaServiceWorker = !!response.fromServiceWorker; | ||||||||||||||
|
||||||||||||||
if (this.fromMemoryCache) this.timing = undefined; | ||||||||||||||
if (this.timing) this._recomputeTimesWithResourceTiming(this.timing); | ||||||||||||||
|
||||||||||||||
this._updateTransferSizeForLightRiderIfNecessary(); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -297,12 +306,10 @@ module.exports = class NetworkRequest { | |||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* LR loses transfer size information, but passes it in the 'X-TotalFetchedSize' header. | ||||||||||||||
* 'X-TotalFetchedSize' is the canonical transfer size in LR. Nothing should supersede it. | ||||||||||||||
*/ | ||||||||||||||
_updateTransferSizeForLightRiderIfNecessary() { | ||||||||||||||
// Bail if we're not in LightRider, this only applies there. | ||||||||||||||
if (!global.isLightRider) return; | ||||||||||||||
// Bail if we somehow already have transfer size data. | ||||||||||||||
if (this.transferSize) return; | ||||||||||||||
_updateTransferSizeForLightrider() { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also leave a comment on L70 that says go read the _updateTransferSizeForLightrider comment? |
||||||||||||||
if (!global.isLightrider) return; | ||||||||||||||
|
||||||||||||||
const totalFetchedSize = this.responseHeaders.find(item => item.name === 'X-TotalFetchedSize'); | ||||||||||||||
// Bail if the header was missing. | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move these lines back?