Skip to content

perf: Avoid CORS preflight request by removing upload listener when not used #1610

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

Merged
merged 2 commits into from
Nov 18, 2022

Conversation

ricmatsui
Copy link
Contributor

@ricmatsui ricmatsui commented Nov 11, 2022

New Pull Request Checklist

Issue Description

Related issue: #1609
Closes #1609

Starting with v2.13.0, most Parse JS SDK operations began triggering the need for a preflight request. This is due to the addition of a progress listener on upload for all XHR requests with RESTController: #1133 . This listener triggers the need for a preflight request: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload#sect1

Note: Attaching event listeners to this object prevents the request from being a "simple request" and will cause a preflight request to be issued if cross-origin; see CORS.

While this upload progress listener is useful in cases where a progress callback is being used, it should not be set when no progress callback is provided to avoid the performance issue.

Approach

Only set the progress listeners on the XHR when a progress callback is provided.

TODOs before merging

  • Add tests

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: avoid CORS preflight request by removing upload listener when not used fix: Avoid CORS preflight request by removing upload listener when not used Nov 11, 2022
@parse-github-assistant
Copy link

parse-github-assistant bot commented Nov 11, 2022

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@mtrezza mtrezza requested a review from a team November 12, 2022 00:54
@mtrezza mtrezza changed the title fix: Avoid CORS preflight request by removing upload listener when not used perf: Avoid CORS preflight request by removing upload listener when not used Nov 12, 2022
@mtrezza
Copy link
Member

mtrezza commented Nov 12, 2022

Thanks for this PR, even with a test case, very nice. Let's for the CI to pass and maybe another review.

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

Looks good!

@codecov
Copy link

codecov bot commented Nov 18, 2022

Codecov Report

Base: 99.89% // Head: 99.89% // No change to project coverage 👍

Coverage data is based on head (a4d3d46) compared to base (782c057).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head a4d3d46 differs from pull request most recent head 06e38d9. Consider uploading reports for the commit 06e38d9 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #1610   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files          61       61           
  Lines        5973     5973           
  Branches     1367     1367           
=======================================
  Hits         5967     5967           
  Misses          6        6           
Impacted Files Coverage Δ
src/RESTController.js 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mtrezza mtrezza merged commit 6125419 into parse-community:alpha Nov 18, 2022
parseplatformorg pushed a commit that referenced this pull request Nov 18, 2022
# [4.0.0-alpha.3](4.0.0-alpha.2...4.0.0-alpha.3) (2022-11-18)

### Performance Improvements

* Avoid CORS preflight request by removing upload listener when not used ([#1610](#1610)) ([6125419](6125419))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.0.0-alpha.3

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Nov 18, 2022
@ricmatsui ricmatsui deleted the fix-preflight branch November 19, 2022 02:07
mtrezza pushed a commit to mtrezza/Parse-SDK-JS that referenced this pull request Jan 22, 2023
mtrezza pushed a commit to mtrezza/Parse-SDK-JS that referenced this pull request Jan 22, 2023
# [4.0.0-alpha.3](parse-community/Parse-SDK-JS@4.0.0-alpha.2...4.0.0-alpha.3) (2022-11-18)

### Performance Improvements

* Avoid CORS preflight request by removing upload listener when not used ([parse-community#1610](parse-community#1610)) ([6125419](parse-community@6125419))
parseplatformorg pushed a commit that referenced this pull request Jan 23, 2023
# [4.0.0-beta.1](3.5.1...4.0.0-beta.1) (2023-01-23)

### Bug Fixes

* `Parse.Query.subscribe()` does not return a rejected promise on error in Cloud Code Triggers `beforeConnect` or `beforeSubscribe` ([#1490](#1490)) ([96d7174](96d7174))
* Remove support for Node <14 ([#1603](#1603)) ([bc04b4b](bc04b4b))

### Features

* Add Node 16 and 18 support ([#1598](#1598)) ([2c79a31](2c79a31))
* Add node 19 support ([8ed0fab](8ed0fab))
* Add Node 19 support ([#1643](#1643)) ([dfb5196](dfb5196))

### Performance Improvements

* Avoid CORS preflight request by removing upload listener when not used ([#1610](#1610)) ([6125419](6125419))

### BREAKING CHANGES

* Calling `Parse.Query.subscribe()` will now return a rejected promise if an error is thrown in Cloud Code Triggers `beforeConnect` or `beforeSubscribe`; in previous releases a resolved promise was returned, even if subscribing failed and it was necessary to create an `error.on` listener to handle these errors (#1490) ([96d7174](96d7174))
* This release removes support for Node versions <14 ([bc04b4b](bc04b4b))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.0.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Jan 23, 2023
parseplatformorg pushed a commit that referenced this pull request Jan 23, 2023
# [4.0.0](3.5.1...4.0.0) (2023-01-23)

### Bug Fixes

* `Parse.Query.subscribe()` does not return a rejected promise on error in Cloud Code Triggers `beforeConnect` or `beforeSubscribe` ([#1490](#1490)) ([96d7174](96d7174))
* Remove support for Node <14 ([#1603](#1603)) ([bc04b4b](bc04b4b))

### Features

* Add Node 16 and 18 support ([#1598](#1598)) ([2c79a31](2c79a31))
* Add node 19 support ([8ed0fab](8ed0fab))
* Add Node 19 support ([#1643](#1643)) ([dfb5196](dfb5196))

### Performance Improvements

* Avoid CORS preflight request by removing upload listener when not used ([#1610](#1610)) ([6125419](6125419))

### BREAKING CHANGES

* Calling `Parse.Query.subscribe()` will now return a rejected promise if an error is thrown in Cloud Code Triggers `beforeConnect` or `beforeSubscribe`; in previous releases a resolved promise was returned, even if subscribing failed and it was necessary to create an `error.on` listener to handle these errors (#1490) ([96d7174](96d7174))
* This release removes support for Node versions <14 ([bc04b4b](bc04b4b))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.0.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance regression due to CORS preflight request
3 participants