Magento2: Incompatibilies with jQuery 3

Created on 15 Feb 2018  路  29Comments  路  Source: magento/magento2

We'd like to use tools that are standard in web development industry.
This includes latest jQuery.

Preconditions

  1. I use Bootstrap 4
  2. I want to use navigation and other scripts.

Steps to reproduce

  1. npm install jquery
  2. Copy jquery.js to you your theme
  3. Build theme.
  4. Open product page with configurable product.

Expected result

  1. No errors

Actual result

  1. size() is not defined (http://api.jquery.com/size/ was deleted from jQuery 3)
Fixed in 2.3.x Clear Description Confirmed Format is valid improvement

All 29 comments

@kirmorozov, thank you for your report.
We've acknowledged the issue and added to our backlog.

Such bug report is not valid. While jQuery, like any other third party library, can definitely be upgraded via one or more PRs, core is not supposed to be forward compatible with any version but only with ones actually used.

Hi @kirmorozov. Thank you for your report.
The issue has been fixed in magento/magento2#13688 by @kirmorozov in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

Main concern was .browser from https://github.com/magento/magento2/issues/14267
Its resolved.

Hi @kirmorozov. Thank you for your report.
The issue has been fixed in magento/magento2#14637 by @kirmorozov in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@antonkril @okorshenko @vrann Please check it and make sure we are up-to-date with major js libraries.

We'd like to use tools that are standard in web development industry.
This includes latest jQuery.

Just to mention it, the "new" standard is to not use jQuery and use Babel to transpile JavaScript (ES6) / TypeScript to ES5 using browserslist.

jQuery is huge and mostly not needed imho.

@DanielRuf Yes, new, fancy JS, but:

  1. Backward compatibility is what keeps your system running.
    And most of the web is running due to Linux backward compatibility.
  2. We have to inject js processing via nodejs within the core. https://github.com/magento/magento2/issues/14646 Will start this process. Feel free to join.

Babel, another beast to worship, like redis or varnish or nginx, it will be part of the build process sooner or later.
Hyper, premature optimization kills, just look at overlearning in machine learning.

I will do some planning how we could get there (browserslist config + webpack + babel).

I'm all for new cool stuff with tangible benefits.

But having jQuery upgraded to a recent version (v3) is important for all of us that are working with third party libraries (sliders, carousels, plugins included in extensions, etc), and can't just make the switch. I don't think jQuery is going away any time soon, and for some use cases it's very practical.

Magento is using a fairly old version of the library, which means that extensions usually can't upgrade it without too many complications, and that will be stuck with some bugs that are present in old versions of the library. This upgrade would be very useful if it can be included in the next major release.

Sure.

Just to mention it

It was just meant as notice.

This upgrade would be very useful if it can be included in the next major release.

Totally agree with this.

@VladimirZaets was assigned to latest PR,
There might be 3-4-5 other issues found after complete MFTF run, can be resolved easily.

If jQuery can be upgraded to the 3.x release stream without significant regression, then we could do it. But we can't set a precedent where we keep all of the core lib/ support libraries up to date. A lot of working software may be reliant on behaviors that are peculiar to those versions. Semantic versioning can only protect us so much from this.

I sympathize with @leoquijano in being forced to use older versions of plugins, but the jQuery install base is still largely 1.x, and so the community of plugin authors usually do maintain 1.x compatibility. Alternatives are likely to exist.

So again, in the individual case, I support experimenting with jQuery 3, but I think it's likely that an upgrade would break more functionality than it would enable.

@zetlen, I would be more concerned about what jQuery version is expected by the other libraries, and not by the global use base. If we were concerned by that metric, we wouldn't be using PHP 7 either, since 82.7% of the global installations use v5.x.

Since jQuery is such a critical library, having an old version of it is probably blocking upgrades for the other libraries, and not the other way around. Keep in mind that a jQuery Migrate v3 plugin is available to smooth out the upgrade process. That effectively makes it look like we have v1.12 in terms of backwards compatibility.

@leoquijano We're not officially refusing a jQuery 3 upgrade because of that install base metric. It's just a stat to help us all weigh the costs and benefits.

Again, we're open to a PR to upgrade to jQuery 3, considering its special role as a nearly global dependency. But I want to avoid:

  • Unforeseen regressions in popular third party modules
  • A combination of modules that loads jQuery 3 and jQuery 1.12 at the same time

We all probably want such a PR to have safeguards in place to prevent that last thing in particular. Maybe \Magento\Framework\RequireJs could have a server-side sanity check in place to check for multiple jQuery versions.

Thanks @zetlen. There are a few PRs already in progress, if I understand correctly?

That's right! I'm just stating on this thread our requirements for such a PR to merge. Thanks!

@zetlen any update on this one? It is too risky to get into a patch release but it would be super helpful for 2.4 branch as it helps us address major security questions.

@piotrekkaminski Nobody has sent me a jQuery upgrade PR to review, but I also haven't looked for one. The things we are looking for are still the same:

  • an upgrade to current-state jQuery 3
  • "Migration" plugins as necessary to cover breaking changes
  • Refactoring where any regressions occur
  • No visible test regression
  • Some kind of safeguard to prevent a downstream theme from loading more than one jQuery version at once

I would be really excited to see such a change, and though there is a regression risk, I think it's digestible by an ambitious community developer.

@zetlen so this PR only solves your first point not the others, right? https://github.com/magento/magento2/pull/15531

@piotrekkaminski It may satisfy the following, too:

  • Refactoring where any regressions occur
  • No visible test regression

But without seeing the output of an end to end test, we can't be sure!

@piotrekkaminski Hello old friend.
This initiative is there since April and I have jQuery 3 in production for front-end.
Its been few months since I put a bit of an effort to fix tests and minor core incompatibilities.
Everything else was pushed to the core before April.

@piotrekkaminski
When do you expect to have end-to-end tests?
I expect to put it in production as early as Magento 2.3 Production release.

Hi @kirmorozov, thank you for you report, this issue has already fixed in 2.3-develop branch, and available on 2.3.0 release.

@orlangur hmm.., but this comment -> https://github.com/magento/magento2/issues/13685#issuecomment-373909529

is there any update? since the the jQuery version is still v1.12.4 https://github.com/magento/magento2/blob/2.3.2/lib/web/jquery.js#L2

Was this page helpful?
0 / 5 - 0 ratings