Page MenuHomePhabricator

mw.loader "ready" mode is wrong when called from a $.fn.ready handler bound before mediawiki.js loads
Closed, ResolvedPublic

Description

Author: a.d.bergi

Description:
There are a few ways that resource loader is used after DOM ready, but before its handler for this event is invoked. There may be userscripts running in the users browser that can do that. What happens is:

  1. the userscript adds a DOMready-handler
  2. the scripts get loaded, jQuery adds its handler, mw.loader is initialisized
  3. the dom is finished
  4. the userscripts handler gets invoked and from there mw.loader is called
  5. as the loaders "ready" variable is still false, it uses document.write
  6. the document crashes very ugly

To prevent that, the userscript should be able to set the ready variable to true.
I propose to make the function, which is used as the callback argument to jQuery.ready(), a public property of the loader object.


Version: unspecified
Severity: enhancement

Details

Reference
bz31895

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:50 PM
bzimport set Reference to bz31895.

Another solution could be (untested) to fire the document ready event from the bottom of </body> with jQuery.ready().

Another solution would be to have mw.loader use jQuery.isReady directly instead of a local var isReady = false; $(function () { isReady = true; }); which, as you say, will be X invocations behind.

Did that in I146c1d2245aae71c538ce84daee30b4ec490b874.

This bug is still possible since jQuery's domready callback list isn't the only callback list for DOMContentLoaded. The native browser event has this list as well.

Therefor not marking this bug as resolved yet. We can further improve this by firing ready() from the bottom of the </body> (but before </html>). This optimizes overal performance and gets us in right before the native event, still playing safe.

This is actually done now as a solution to bug 47457.