resourceloader: Support isKnownEmpty for general modules

It was already supported for only=scripts and only=styles, but
not yet for general modules loaded as 'combined'.

This is especially useful for general modules that are private/embedded,
as this allows us to skip the loader.implement() boilerplate.

Bug: T176159
Change-Id: I83e9f74dad75867c10ebd0a94b87c31e4adbb57f
This commit is contained in:
Timo Tijhof 2017-09-18 18:37:13 +01:00
parent 83020dbf41
commit 0b1a7d4c59
2 changed files with 10 additions and 0 deletions

View file

@ -149,6 +149,13 @@ class ResourceLoaderClientHtml {
continue;
}
$context = $this->getContext( $module->getGroup(), ResourceLoaderModule::TYPE_COMBINED );
if ( $module->isKnownEmpty( $context ) ) {
// Avoid needless request or embed for empty module
$data['states'][$name] = 'ready';
continue;
}
if ( $module->shouldEmbedModule( $this->context ) ) {
// Embed via mw.loader.implement per T36907.
$data['embed']['general'][] = $name;

View file

@ -43,6 +43,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
'test.top' => [ 'position' => 'top' ],
'test.private.top' => [ 'group' => 'private', 'position' => 'top' ],
'test.private.bottom' => [ 'group' => 'private', 'position' => 'bottom' ],
'test.shouldembed.empty' => [ 'shouldEmbed' => true, 'isKnownEmpty' => true ],
'test.shouldembed' => [ 'shouldEmbed' => true ],
'test.styles.pure' => [ 'type' => ResourceLoaderModule::LOAD_STYLES ],
@ -115,6 +116,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
'test.private.bottom',
'test.private.top',
'test.top',
'test.shouldembed.empty',
'test.shouldembed',
'test.unregistered',
] );
@ -138,6 +140,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
'states' => [
'test.private.top' => 'loading',
'test.private.bottom' => 'loading',
'test.shouldembed.empty' => 'ready',
'test.shouldembed' => 'loading',
'test.styles.pure' => 'ready',
'test.styles.user.empty' => 'ready',