Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/platform/web/lib/http/request/xhrrequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class XHRRequest extends EventEmitter implements IXHRRequest {
Logger.logAction(this.logger, Logger.LOG_ERROR, 'Request.on' + errorEvent.type + '()', errorMessage);
this.complete(new PartialErrorInfo(errorMessage, code, statusCode));
};
xhr.onerror = function (errorEvent) {
xhr.onerror = (errorEvent) => {
errorHandler(errorEvent, 'XHR error occurred', null, 400);
};
xhr.onabort = (errorEvent) => {
Expand All @@ -193,7 +193,7 @@ class XHRRequest extends EventEmitter implements IXHRRequest {
errorHandler(errorEvent, 'Request cancelled', null, 400);
}
};
xhr.ontimeout = function (errorEvent) {
xhr.ontimeout = (errorEvent) => {
errorHandler(errorEvent, 'Request timed out', null, 408);
};

Expand Down Expand Up @@ -306,7 +306,7 @@ class XHRRequest extends EventEmitter implements IXHRRequest {
});
};

xhr.onreadystatechange = function () {
xhr.onreadystatechange = () => {
Comment thread
VeskeR marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, if function expressions are a problem in SWC minimization, shouldn't we also change xhr.onerror and xhr.ontimeout assignments in this file to also use arrow functions just to be safe?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into minimized code and

a.onerror=function(e){u(e,"XHR error occurred",null,400)}

and

a.ontimeout=function(e){u(e,"Request timed out",null,408)}

it's nothing to inline here. On other hand, here is onreadystatechange:

a.onreadystatechange=function(){let i=a.readyState;i<3||0!==a.status&&(void 0===t&&(t=a.status,(()=>{var s;if(clearTimeout(r),n=t<400,204==t)return this.complete(null,null,null,null,t)...

To fix this properly, we need to decide on a strategy for all function declarations across all SDKs. I think it would be good to release this fix first so SDK users don’t have to wait. This definitely doesn’t introduce any new problems but does fix some existing ones.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into minimized code and
a.onerror=function(e){u(e,"XHR error occurred",null,400)}
and
a.ontimeout=function(e){u(e,"Request timed out",null,408)}

huh, so there are multiple places which call errorHandler so it doesn't get inlined and as a result xhr.onerror and xhr.ontimeout don't break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, changing xhr.onerror and xhr.ontimeout to arrow functions is trivial but if you'd like to keep this PR specific and fix the immediate problem with xhr.onreadystatechange then sure. Will approve the PR as it fixes the problem

const readyState = xhr.readyState;
if (readyState < 3) return;
if (xhr.status !== 0) {
Expand Down
Loading