Using .done() and .fail() can lead to some nasty bugs such as T238025. Refactor these to .then().
https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Asynchronous_code
Avoid using jQuery-specific methods like done() or fail(), which could stop working without warning if the method you are calling internally transitions from $.Deferred to native Promise.
Similar to what we did in this patch.
Thanks to @Chlod for pointing this out