Fix Race-Condition in mediawiki.page.ready OOJs-UI infusion
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Thu, 7 Jan 2016 16:46:16 +0000 (17:46 +0100)
committerFlorian <florian.schmidt.stargatewissen@gmail.com>
Thu, 7 Jan 2016 16:56:49 +0000 (17:56 +0100)
It's possible, that the "catlinks" $nodes variable is re-assigned, before
mw.loader.using finished loading the mediawiki.widgets modules (which will
trigger the execution of the passed function). The function inside the
mw.loader.using call uses the $nodes variable and expects a set of infusable
OOUI elements, but (depending on the loading time of the modules) it's already
re-assigned with the .catlinks element.

Fix this by renaming the variable $nodes to $oouiNodes to break this race
condition. It's possible to rename the variable used for catlinks, but $nodes is
used in other places of the code, too, so I think this is the nicer solution.

Bug: T123074
Change-Id: Ie18b576a16c33645ab04e2957b23169bc2e17202

resources/src/mediawiki/page/ready.js

index 4385a2e..9b3458b 100644 (file)
@@ -36,7 +36,7 @@
 
        // Things outside the wikipage content
        $( function () {
-               var $nodes;
+               var $nodes, $oouiNodes;
 
                if ( !supportsPlaceholder ) {
                        // Exclude content to avoid hitting it twice for the (first) wikipage content
                $nodes.updateTooltipAccessKeys();
 
                // Infuse OOUI widgets, if any are present
-               $nodes = $( '[data-ooui]' );
-               if ( $nodes.length ) {
+               $oouiNodes = $( '[data-ooui]' );
+               if ( $oouiNodes.length ) {
                        // FIXME: We should only load the widgets that are being infused
                        mw.loader.using( [ 'mediawiki.widgets', 'mediawiki.widgets.UserInputWidget' ] ).done( function () {
-                               $nodes.each( function () {
+                               $oouiNodes.each( function () {
                                        OO.ui.infuse( this );
                                } );
                        } );