From: Timo Tijhof Date: Fri, 17 Feb 2017 23:21:59 +0000 (-0800) Subject: resourceloader: Consistent stylesheet order for debug and non-debug X-Git-Tag: 1.31.0-rc.0~4060^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=44f3f068df0f35e7b276afbb6347537ed82e2683;p=lhc%2Fweb%2Fwiklou.git resourceloader: Consistent stylesheet order for debug and non-debug Previously, style modules were only in a predictable order for production mode. In debug mode, the order was determined by order in which modules were added to queue at run time. This made it sometimes hard to debug, especially when dealing with gadgets that apply in a different order among each other. Change-Id: I4bff0c91d127e4ad8015cd8c1775220fe460cbc3 --- diff --git a/includes/resourceloader/ResourceLoaderClientHtml.php b/includes/resourceloader/ResourceLoaderClientHtml.php index ef2827c9b6..29f8cfe66d 100644 --- a/includes/resourceloader/ResourceLoaderClientHtml.php +++ b/includes/resourceloader/ResourceLoaderClientHtml.php @@ -365,7 +365,11 @@ class ResourceLoaderClientHtml { $rl = $mainContext->getResourceLoader(); $chunks = []; + // Sort module names so requests are more uniform + sort( $modules ); + if ( $mainContext->getDebug() && count( $modules ) > 1 ) { + $chunks = []; // Recursively call us for every item foreach ( $modules as $name ) { @@ -374,8 +378,6 @@ class ResourceLoaderClientHtml { return new WrappedStringList( "\n", $chunks ); } - // Sort module names so requests are more uniform - sort( $modules ); // Create keyed-by-source and then keyed-by-group list of module objects from modules list $sortedModules = []; foreach ( $modules as $name ) { diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php index 528c3220e8..2db3c1692c 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php @@ -246,8 +246,14 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase { 'context' => [ 'debug' => true ], 'modules' => [ 'test.styles.pure', 'test.styles.mixed' ], 'only' => ResourceLoaderModule::TYPE_STYLES, - 'output' => '' . "\n" - . '', + 'output' => '' . "\n" + . '', + ], + [ + 'context' => [ 'debug' => false ], + 'modules' => [ 'test.styles.pure', 'test.styles.mixed' ], + 'only' => ResourceLoaderModule::TYPE_STYLES, + 'output' => '', ], [ 'context' => [],