(bug 37331) Modules sometimes execute twice in Firefox
authorCatrope <roan.kattouw@gmail.com>
Tue, 24 Jul 2012 20:24:56 +0000 (13:24 -0700)
committerCatrope <roan.kattouw@gmail.com>
Mon, 30 Jul 2012 20:19:17 +0000 (13:19 -0700)
This seems to have been caused by a weird race condition that caused the
loader to run while the module in question was also running; could also
have been caused by the module calling mw.loader, but that didn't seem
to be the case here.

The fix is to set .state='ready' before executing the module rather than
after. We can't do this in debug mode (where we're loading raw files and
can't execute things at will), but we have to do this in production
mode to prevent these freakish double executions.

Change-Id: I7e8dbd361fb265e520d3935e3a1fc7e3b6710b66

RELEASE-NOTES-1.20
resources/mediawiki/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js

index 1ccfd3a..f2a75c2 100644 (file)
@@ -174,6 +174,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
   was initialized.
 * (bug 38093) Gender of changed user groups missing in Special:Log/rights
 * (bug 35893) Special:Block needs to load mediawiki.special.block.js.
+* (bug 37331) ResourceLoader modules sometimes execute twice in Firefox
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index 21cb7f3..41a5078 100644 (file)
@@ -852,8 +852,9 @@ var mw = ( function ( $, undefined ) {
                                                registry[module].state = 'loading';
                                                nestedAddScript( script, markModuleReady, registry[module].async, 0 );
                                        } else if ( $.isFunction( script ) ) {
+                                               registry[module].state = 'ready';
                                                script( $ );
-                                               markModuleReady();
+                                               handlePending( module );
                                        }
                                } catch ( e ) {
                                        // This needs to NOT use mw.log because these errors are common in production mode
index 00fcf38..bd6c8a7 100644 (file)
@@ -198,7 +198,7 @@ test( 'mw.loader.implement', function () {
                        strictEqual( isJsExecuted, undefined, 'javascript not executed multiple times' );
                        isJsExecuted = true;
 
-                       equal( mw.loader.getState( 'test.implement' ), 'loaded', 'module state is "loaded" while implement() is executing javascript' );
+                       equal( mw.loader.getState( 'test.implement' ), 'ready', 'module state is "ready" while implement() is executing javascript' );
 
                        $element = $( '<div class="mw-test-loaderimplement">Foo bar</div>' ).appendTo( '#qunit-fixture' );