Skip to content

Commit 8f3becb

Browse files
authored
Merge branch 'alpha' into add-node-16
2 parents 80d38fc + 17374a3 commit 8f3becb

File tree

6 files changed

+42
-15
lines changed

6 files changed

+42
-15
lines changed

changelogs/CHANGELOG_alpha.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [4.0.0-alpha.3](https://github.com/parse-community/Parse-SDK-JS/compare/4.0.0-alpha.2...4.0.0-alpha.3) (2022-11-18)
2+
3+
4+
### Performance Improvements
5+
6+
* Avoid CORS preflight request by removing upload listener when not used ([#1610](https://github.com/parse-community/Parse-SDK-JS/issues/1610)) ([6125419](https://github.com/parse-community/Parse-SDK-JS/commit/6125419e749866ffa814a4a3e696382206d5da09))
7+
18
# [4.0.0-alpha.2](https://github.com/parse-community/Parse-SDK-JS/compare/4.0.0-alpha.1...4.0.0-alpha.2) (2022-11-15)
29

310

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse",
3-
"version": "4.0.0-alpha.2",
3+
"version": "4.0.0-alpha.3",
44
"description": "The Parse JavaScript SDK",
55
"homepage": "https://parseplatform.org/",
66
"keywords": [

src/RESTController.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,24 @@ const RESTController = {
169169
headers[key] = customHeaders[key];
170170
}
171171

172-
function handleProgress(type, event) {
173-
if (options && typeof options.progress === 'function') {
172+
if (options && typeof options.progress === 'function') {
173+
const handleProgress = function (type, event) {
174174
if (event.lengthComputable) {
175175
options.progress(event.loaded / event.total, event.loaded, event.total, { type });
176176
} else {
177177
options.progress(null, null, null, { type });
178178
}
179-
}
180-
}
181-
182-
xhr.onprogress = event => {
183-
handleProgress('download', event);
184-
};
179+
};
185180

186-
if (xhr.upload) {
187-
xhr.upload.onprogress = event => {
188-
handleProgress('upload', event);
181+
xhr.onprogress = event => {
182+
handleProgress('download', event);
189183
};
184+
185+
if (xhr.upload) {
186+
xhr.upload.onprogress = event => {
187+
handleProgress('upload', event);
188+
};
189+
}
190190
}
191191

192192
xhr.open(method, url, true);

src/__tests__/RESTController-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,20 @@ describe('RESTController', () => {
570570
);
571571
});
572572

573+
it('does not set upload progress listener when callback is not provided to avoid CORS pre-flight', () => {
574+
const xhr = {
575+
setRequestHeader: jest.fn(),
576+
open: jest.fn(),
577+
upload: jest.fn(),
578+
send: jest.fn(),
579+
};
580+
RESTController._setXHR(function () {
581+
return xhr;
582+
});
583+
RESTController.ajax('POST', 'users', {});
584+
expect(xhr.upload.onprogress).toBeUndefined();
585+
});
586+
573587
it('does not upload progress when total is uncomputable', done => {
574588
const xhr = mockXHR([{ status: 200, response: { success: true } }], {
575589
progress: {

src/__tests__/test_helpers/mockXHR.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ function mockXHR(results, options = {}) {
3535
this.readyState = 4;
3636
attempts++;
3737
this.onreadystatechange();
38-
this.onprogress(options.progress);
39-
this.upload.onprogress(options.progress);
38+
39+
if (typeof this.onprogress === 'function') {
40+
this.onprogress(options.progress);
41+
}
42+
43+
if (typeof this.upload.onprogress === 'function') {
44+
this.upload.onprogress(options.progress);
45+
}
4046
},
4147
};
4248
return XHR;

0 commit comments

Comments
 (0)