Skip to content
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

Update deprecated jQuery methods #4625

Merged

Conversation

cpfergus1
Copy link
Contributor

@cpfergus1 cpfergus1 commented Sep 13, 2022

Summary

After the inclusion of #4167, it was discovered that some of the extensions (specifically solidus_product_assembly) specs are failing on master with no changes to the code. It was discovered that after moving to jQuery3, some methods no longer existed including one being utilized in ajax calls for splitting shipments and image uploads.

This PR corrects these issues by updating the deprecated methods to utilize those available in jQuery3.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

  • I have written a thorough PR description.
  • I have kept my commits small and atomic.
  • I have used clear, explanatory commit messages.

The following are not always needed (cross them out if they are not):

  • I have added automated tests to cover my changes.
  • I have attached screenshots to demo visual changes.
  • I have opened a PR to update the guides.
  • I have updated the readme to account for my changes.

From the jQuery upgrade guide:

The jqXHR object returned from jQuery.ajax() is a jQuery Deferred and
has historically had three extra methods with names matching the
arguments object of success, error, and complete. This often confused
people who did not realize that the returned object should be treated
like a Deferred. As of jQuery 3.0 these methods have been removed.
As replacements, use the Deferred standard methods of done, fail,
and always, or use the new then and catch methods for Promises/A+
compliance.

Note that this does not have any impact at all on the ajax callbacks
of the same name passed through the options object, which continue to
exist and are not deprecated. This only affects the jqXHR methods.
@github-actions github-actions bot added the changelog:solidus_backend Changes to the solidus_backend gem label Sep 13, 2022
@cpfergus1 cpfergus1 force-pushed the nebulab/fix_jquery_methods branch from 42b84dc to 6ae4717 Compare September 13, 2022 13:22
@cpfergus1 cpfergus1 marked this pull request as ready for review September 13, 2022 13:46
@cpfergus1 cpfergus1 changed the title Nebulab/fix jquery methods Update deprecated jQuery methods Sep 13, 2022
@waiting-for-dev
Copy link
Contributor

Thanks, @cpfergus1. Do you think it would be challenging to include a regression test? It looks like our test suite was failing to detect that breaking change.

@waiting-for-dev waiting-for-dev added the type:bug Error, flaw or fault label Sep 14, 2022
@cpfergus1
Copy link
Contributor Author

cpfergus1 commented Sep 14, 2022

Thanks, @cpfergus1. Do you think it would be challenging to include a regression test? It looks like our test suite was failing to detect that breaking change.

I think my latest commit might achieve that. It did not appear that we were testing AJAX call failures so I forced it by adding a few lines in a current spec to input bad data. This should cover "fail" and "then" - LMKWYT

Edit: It appears that this only works when the driver is not headless or when I add save_and_open_page 🤔
Any thoughts on how to deal with this timing issue?

Edit 2: Forcing it to wait for the popup works, but this does not seem like an ideal solution

Edit 3: Stopped trying to capture the alert and just utilized accept_alert - test will fail if the alert does not pop up. LMKWYT

@cpfergus1 cpfergus1 force-pushed the nebulab/fix_jquery_methods branch from 42c3a31 to 17cfbc6 Compare September 15, 2022 12:04
Specs did not catch the deprecated method "error" because there were
not any tests that checked for an AJAX error. Added steps to a current
current test to ensure an AJAX call fails to cover the method "fail"
and "then" incase those methods might be deprecated in the future
@cpfergus1 cpfergus1 force-pushed the nebulab/fix_jquery_methods branch from 17cfbc6 to c8218ba Compare September 15, 2022 14:02
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @cpfergus1, it looks good to me!

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks Connor!

@solidusio/core-team do you think we should backport this?

@waiting-for-dev
Copy link
Contributor

@solidusio/core-team do you think we should backport this?

It makes sense.

Copy link
Member

@elia elia left a comment

Choose a reason for hiding this comment

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

🙌

@@ -56,7 +56,7 @@ Spree.Models.ImageUpload = Backbone.Model.extend({
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
xhr: function () {
var xhr = $.ajaxSettings.xhr();
var xhr = $.ajaxSetup.xhr(); // Using default ajax builder but inputting upload settings
Copy link
Member

Choose a reason for hiding this comment

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

🙏 thanks for this!

Copy link
Contributor

Choose a reason for hiding this comment

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

Unsure how this is working for anyone. We're getting errors about ajaxSetup.xhr being undefined, and I cannot find references to it in anywhere else in Solidus, or in any of our external libraries including jQuery itself.

Where is ajaxSetup.xhr being defined?

Copy link
Member

Choose a reason for hiding this comment

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

It's here, but I think we mistakenly called it without the parenthesis: https://api.jquery.com/jQuery.ajaxSetup/
Opening the console and typing jQuery.ajaxSetup().xhr() seems to be working fine

cc @cpfergus1

@waiting-for-dev waiting-for-dev merged commit 02d3bd3 into solidusio:master Sep 20, 2022
kennyadsl added a commit that referenced this pull request Oct 14, 2022
Update deprecated jQuery methods (Backport #4625 to v3.2)
@elia elia deleted the nebulab/fix_jquery_methods branch November 8, 2022 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem type:bug Error, flaw or fault
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants