Upgrade to jQuery 3
Open, NormalPublic

Description

After we ended support for Internet Explorer 8 in our Grade A "JavaScript" run-time (T118303 and https://gerrit.wikimedia.org/r/252383), we now start work on aligning the remainder differences between MediaWiki and jQuery browser support. Not all of it, but at least the bottom line of Grade A support so that we can upgrade to jQuery 3.0.

In the next release of jQuery, the 1.x and 2.x branches are being rebranded. The jQuery 2.x branch naturally becomes jQuery 3.0. The jQuery 1.x branch becomes jQuery 3.0 Compat. This better reflects what 1.x branch is (that is, the same API with additional support code for MSIE 6-8).

However, during the jQuery 3.0 alpha release cycle, it has become clear that there is no longer much need in maintaining the Compat branch. After Microsoft publicly announced that MSIE 8, 9 and 10 are EOL effective immediately, jQuery followed suit. jQuery 3.0 will still support IE9+, but not IE8. As such, jQuery Compat (for IE6-8) will no longer be maintained.

There are a few other support differences between jQuery 1.x (the version we currently use) and jQuery 2.x/3.x, so we're not quite there. Specifically, older versions of Safari (Mac), Mobile Safari (iOS), and Android will likely encounter run-time failures if we don't blacklist them from Grade A (so we may provide the non-javascript Grade C experience instead.)

Documentation

jQuery 1.11 to 1.12 (or jQuery 2.1 to jQuery 2.2)

jQuery 1.12 to jQuery 3.0 (or jQuery 2.2 to jQuery 3.0)

jQuery 3.x

Blockers

Regressions that may affect us:


T46740: Upgrade jQuery from 1.8.x to 1.11.x

Related Objects

StatusAssignedTask
OpenKrinkle
OpenKrinkle
ResolvedFlorian
ResolvedNone
ResolvedPeter
ResolvedJonas
ResolvedNikerabbit
Resolvedmatmarex
Resolvedmatmarex
ResolvedMooeypoo
ResolvedJdforrester-WMF
ResolvedEsanders
Resolvedmatthiasmullie
Resolvedmatthiasmullie
ResolvedAnomie
Resolvedmatmarex
ResolvedNone
Resolvedmatmarex
ResolvedKrinkle
Resolvedcscott
ResolvedKrinkle
ResolvedKrinkle
There are a very large number of changes, so older changes are hidden. Show Older Changes

Change 344282 had a related patch set uploaded (by Krinkle):
[mediawiki/extensions/Cards@master] tests: Don't assume synchronous jQuery.Deferred

https://gerrit.wikimedia.org/r/344282

Change 344282 merged by jenkins-bot:
[mediawiki/extensions/Cards@master] tests: Don't assume synchronous jQuery.Deferred

https://gerrit.wikimedia.org/r/344282

Change 348031 had a related patch set uploaded (by Krinkle; owner: Jforrester):
[mediawiki/extensions/Citoid@master] tests: Fiddle with templatedata cache insertion to avoid failed XHRs

https://gerrit.wikimedia.org/r/348031

Change 348031 merged by jenkins-bot:
[mediawiki/extensions/Citoid@master] tests: Fiddle with templatedata cache insertion to avoid failed XHRs

https://gerrit.wikimedia.org/r/348031

Krinkle updated the task description. (Show Details)Apr 13 2017, 4:14 AM

Change 322812 merged by jenkins-bot:
[mediawiki/core@master] Upgrade to jQuery v3

https://gerrit.wikimedia.org/r/322812

Change 348123 had a related patch set uploaded (by Krinkle):
[mediawiki/extensions/CentralAuth@master] tests: Don't assume synchronous jQuery.Deferred

https://gerrit.wikimedia.org/r/348123

Change 348123 merged by jenkins-bot:
[mediawiki/extensions/CentralAuth@master] tests: Don't assume synchronous jQuery.Deferred

https://gerrit.wikimedia.org/r/348123

Change 348255 had a related patch set uploaded (by Krinkle):
[mediawiki/extensions/RelatedArticles@master] tests: Don't assume synchronous jQuery.Deferred

https://gerrit.wikimedia.org/r/348255

Change 348255 merged by jenkins-bot:
[mediawiki/extensions/RelatedArticles@master] tests: Don't assume synchronous jQuery.Deferred

https://gerrit.wikimedia.org/r/348255

It seems that this broke few tests in ContentTranslation that I fixed in https://gerrit.wikimedia.org/r/#/c/348693/

It seems that this broke few tests in ContentTranslation that I fixed in https://gerrit.wikimedia.org/r/#/c/348693/

I don't see any failing change sets in Gerrit, got an example for me to inspect?
https://gerrit.wikimedia.org/r/#/projects/mediawiki/extensions/ContentTranslation,dashboards/default

The build logs for previous, failing patchsets of https://gerrit.wikimedia.org/r/#/c/348693/ are still available. Of course other patches are not failing anymore, because the fix was merged.

Gilles added a subscriber: Gilles.Apr 20 2017, 8:24 PM

The build logs for previous, failing patchsets of https://gerrit.wikimedia.org/r/#/c/348693/ are still available. Of course other patches are not failing anymore, because the fix was merged.

Ah, I see. Glad it worked out. I misread your original comment.

It seems that this broke few tests in ContentTranslation that I fixed in https://gerrit.wikimedia.org/r/#/c/348693/

I thought you meant you fixed tests before with https://gerrit.wikimedia.org/r/#/c/348693/, and then they broke when the upgrade landed in master.

Krinkle updated the task description. (Show Details)Apr 25 2017, 8:16 PM
Krinkle updated the task description. (Show Details)Apr 26 2017, 12:41 AM

(Many of the modules you listed do depend on jQuery, some even actually have 'jquery' in their name :) . At a glance, probably around 50% of them currently use jQuery, either for DOM operations, for AJAX functions, or just to add things to $.fn. In many cases they could be rewritten without it, but someone would have to do all that work.)

One way could be to replace the full jQuery by the slim build (or any other custom build without the methods not used anywhere), and extend it to the full version only on demand.

But this should be discussed in a different task, not here.

He7d3r added a subscriber: He7d3r.May 4 2017, 6:21 PM

Change 348120 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[operations/mediawiki-config@master] Enable wgUsejQueryThree in beta

https://gerrit.wikimedia.org/r/348120

Krinkle moved this task from Blocked to Doing on the Performance-Team board.Jun 14 2017, 6:47 PM

The changes to how promises work is causing quite a bit of headache to us, potentially for others as well. The two issues I am encountering are:

Does anyone have any tips how to write code that works with both the old and the new behavior? Given that developers have jQuery 3, but production sites and stable MediaWikis don't?

The changes to how promises work is causing quite a bit of headache to us,

Mainly three changes:

  1. Previously, calling then on a previously resolved Deferred, would synchronously run the callback. Meaning, by the end of the then() call, your callback has already been called. This was inconsistent with when the Deferred isn't yet resolved (something you typically shouldn't know), and can be confusing:
jQuery 1.x
var a = api.post( data ).then( function ( resp ) {
  console.log( a ) ; // can be undefined
} );

The variable being assigned is naturally undefined until the statement is completed. jQuery 3 makes then() consistently asynchronous, which also aligns with the browser's native Promise class.

  1. Previously, returning a non-promise value from a then() handler, would be wrapped in either reject() or resolve(), depending on whether you returned from the first or second parameter callback of then().

This makes code less predictable. When doing filtering or aggregation (e.g. fetch X and show in a dialog), you'll still produce a dialog if the fetch fails. Previously, returning a modal from the fail handler wouldn't work as it got wrapped reject. In jQuery 3 this became consistent with native Promise. If the callback failed (throws an error), the next chain is rejected. If it returns a plain value, that becomes the next resolution value. Regardless of which of the handlers this happens in.

  1. For some reason, jQuery choose not to report all async exceptions from Deferred callbacks by default. See further at T168086.

Does anyone have any tips how to write code that works with both the old and the new behavior?

Yes, these are changes to unsupported/undocumented behaviour. The supported alternatives work in both versions.

For point 1: Don't assume code runs synchronously (this mostly affected the QUnit tests. I actually fixed most of those before jQuery 3 was merged in core.)

For point 2: Explicitly returning a rejected deferred is the supported approach in jQuery 3. This already worked in jQuery 1.

Krinkle updated the task description. (Show Details)
Krinkle removed a project: MW-1.29-release-notes.
ashley added a subscriber: ashley.Jun 29 2017, 10:34 PM

Change 348120 merged by jenkins-bot:
[operations/mediawiki-config@master] Enable wgUsejQueryThree on the Beta Cluster

https://gerrit.wikimedia.org/r/348120

Krinkle updated the task description. (Show Details)Jul 10 2017, 7:07 PM
Nikerabbit updated the task description. (Show Details)Jul 11 2017, 5:57 AM
Krinkle updated the task description. (Show Details)Jul 22 2017, 1:40 AM

Change 366994 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[operations/mediawiki-config@master] Enable jQuery 3 on test.wikipedia.org and test2.wikipedia.org

https://gerrit.wikimedia.org/r/366994

Change 366994 merged by jenkins-bot:
[operations/mediawiki-config@master] Enable jQuery 3 on test.wikipedia.org and test2.wikipedia.org

https://gerrit.wikimedia.org/r/366994

Krinkle updated the task description. (Show Details)Mon, Jul 31, 9:57 PM
Krinkle updated the task description. (Show Details)Tue, Aug 8, 12:07 AM

Change 372485 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[operations/mediawiki-config@master] Enable jQuery 3 on mediawiki.org and test.wikidata.org

https://gerrit.wikimedia.org/r/372485

Change 372494 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Update jQuery Migrate to v3.0.1-pre (9e3dfcb)

https://gerrit.wikimedia.org/r/372494

Change 372496 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] jquery.migrate: Instrument with mw.track()

https://gerrit.wikimedia.org/r/372496

Change 372485 merged by jenkins-bot:
[operations/mediawiki-config@master] Enable jQuery 3 on mediawiki.org and test.wikidata.org

https://gerrit.wikimedia.org/r/372485

Change 372494 merged by jenkins-bot:
[mediawiki/core@master] Update jQuery Migrate to v3.0.1-pre (9e3dfcb)

https://gerrit.wikimedia.org/r/372494

Change 372496 merged by jenkins-bot:
[mediawiki/core@master] jquery.migrate: Instrument with mw.track()

https://gerrit.wikimedia.org/r/372496