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

trim() is deprecated in the forthcoming jQuery 4 #1527

Open
mrleemon opened this issue Aug 26, 2024 · 7 comments
Open

trim() is deprecated in the forthcoming jQuery 4 #1527

mrleemon opened this issue Aug 26, 2024 · 7 comments
Labels

Comments

@mrleemon
Copy link

mrleemon commented Aug 26, 2024

I tried your plugin with the Test jQuery Updates plugin which ships with jQuery 4.0 beta, and Polylang throws a trim() is not a function error here:

https://github.com/polylang/polylang/blob/bcc11ff89075b8d483aa17f44458714f8999f890/admin/admin-base.php#L335C74-L335C78

@mrleemon
Copy link
Author

This is the list of deprecated functions in jQuery 4:

https://blog.jquery.com/2024/02/06/jquery-4-0-0-beta/

It would be wise to replace them with equivalent vanilla JS functions as soon as possible.

@mrleemon
Copy link
Author

@wpsumo
Copy link

wpsumo commented Aug 27, 2024

It would be wise to replace them with equivalent vanilla JS functions as soon as possible.

+1

@manooweb manooweb self-assigned this Sep 4, 2024
@manooweb manooweb added this to the 3.7 milestone Sep 4, 2024
@manooweb manooweb added the WP 6.8 label Sep 4, 2024
@manooweb
Copy link
Contributor

manooweb commented Sep 4, 2024

Hello @mrleemon,
I will look at the Test jQuery updates you mentioned but I think it's a false positive in this case.
This isn't jQuery.trim() call here (or more exactly $.trim()) but the javascript String trim() method applied to the options.data string.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim

However, thanks to point it to us. We opened a task about jQuery 4.0.

@manooweb
Copy link
Contributor

manooweb commented Sep 5, 2024

@mrleemon FYI all of our plugins aren't concerned by deprecated jQuery APIs removed in its future 4.0 release.
What you found is an issue with jQuery 4 in the ajax process.

With jQuery 3, a conversion (any data passed as an object is converted to string) is done before ajaxPrefilter.
Now with jQuery 4, I saw that this conversion is done after ajaxPrefilter. As in Polylang we expects to always have a string (json or not) the javascript trim() fails because we try to apply it on an object.

@manooweb
Copy link
Contributor

manooweb commented Sep 5, 2024

The breaking changes introduced in jQuery 4 ➡ jquery/jquery#5197

@manooweb
Copy link
Contributor

manooweb commented Sep 5, 2024

As jQuery will be introduced in WordPress 6.8, we decided not to fix the issue in our next release.

What?

The difference between jQuery ajax code in jQuery 3.x and 4.x is that Ajax request data are converted to a string before applying prefilters.

Note:

How?

We have 2 options to fix it:

  • As jQuery 3.x does, apply jQuery.param() to stringify the ajax request data and then execute our code like now.
  • Add a condition to process specifically the PlainObject case and exclude Array

@manooweb manooweb removed their assignment Sep 5, 2024
@manooweb manooweb removed this from the 3.7 milestone Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants