Skip to content

Commit 9b5cb7e

Browse files
malbertsclaude
andcommitted
Restore per-component vector-fix module loading
`AbstractComponent::augmentParserOutput()` used to load each component's per-skin module variants by calling `getModulesFor()` with a hard-coded `'vector'` skin name, which the JSON registry treats as "always include the vector entry alongside the default". That published the `modal.vector-fix` and `popover.vector-fix` CSS to every skin's output, hiding the `.modal-backdrop` element on Vector-family chromes that would otherwise overlay the page. MediaWiki 1.43's ParserOutputAccess lifecycle change broke that publication path: the modules attached via the augment hook no longer reach the OutputPage. The earlier sparse-loading patch in `HooksHandler::onParserAfterParse` (5.2.3) routed the default modules through `ParserAfterParse` instead, but its foreach didn't pass any skin argument, so the per-skin entries stopped loading on every skin. Users on Vector, Vector 2022, MonoBook, and Timeless all end up with the BS4 modal backdrop covering the page once a modal opens. Pass the same hard-coded `'vector'` into the post-parse foreach so the registry returns the per-skin variants exactly as it did pre-1.43. The redesign of this path (route by active skin name, audit per-skin requirements) belongs in the next major release. Drop the heavy mock-based unit test that landed alongside the original sparse-loading patch. Per the reviewer comment at #80 (review) the test pinned a single argument literal through deep mocks of every collaborator on `HooksHandler`, coupling to call signatures rather than behaviour. Integration verification on the running rig covers the regression more reliably. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 8b3ce9a commit 9b5cb7e

2 files changed

Lines changed: 1 addition & 48 deletions

File tree

‎src/HooksHandler.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function onParserAfterParse( $parser, &$text, $stripState ): bool {
226226
if ( !$this->getComponentLibrary()->isRegistered( $activeComponent ) ) {
227227
continue;
228228
}
229-
foreach ( $this->getComponentLibrary()->getModulesFor( $activeComponent ) as $module ) {
229+
foreach ( $this->getComponentLibrary()->getModulesFor( $activeComponent, 'vector' ) as $module ) {
230230
$parser->getOutput()->addModuleStyles( [ $module ] );
231231
$parser->getOutput()->addModules( [ $module ] );
232232
}

‎tests/phpunit/Unit/HooksHandlerTest.php‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use MediaWiki\Extension\BootstrapComponents\ComponentLibrary;
77
use MediaWiki\Extension\BootstrapComponents\HooksHandler;
88
use MediaWiki\Extension\BootstrapComponents\NestingController;
9-
use Parser;
10-
use ParserOutput;
119
use PHPUnit\Framework\TestCase;
1210

1311
/**
@@ -75,49 +73,4 @@ public function testOnOutputPageParserOutput() {
7573
$this->assertTrue( true );
7674
}
7775

78-
public function testOnParserAfterParseLoadsActiveComponentScriptsAndStyles() {
79-
$loadedStyles = [];
80-
$loadedModules = [];
81-
82-
$parserOutput = $this->createMock( ParserOutput::class );
83-
$parserOutput->method( 'addModuleStyles' )
84-
->willReturnCallback( function ( $m ) use ( &$loadedStyles ) {
85-
$loadedStyles = array_merge( $loadedStyles, (array)$m );
86-
} );
87-
$parserOutput->method( 'addModules' )
88-
->willReturnCallback( function ( $m ) use ( &$loadedModules ) {
89-
$loadedModules = array_merge( $loadedModules, (array)$m );
90-
} );
91-
92-
$parser = $this->createMock( Parser::class );
93-
$parser->method( 'getOutput' )->willReturn( $parserOutput );
94-
95-
$service = $this->createMock( BootstrapComponentsService::class );
96-
$service->method( 'getNameOfActiveSkin' )->willReturn( 'vector' );
97-
$service->method( 'getActiveComponents' )->willReturn( [ 'tooltip', 'popover' ] );
98-
99-
$library = $this->createMock( ComponentLibrary::class );
100-
$library->method( 'isRegistered' )->willReturn( true );
101-
$library->method( 'getModulesFor' )
102-
->willReturnCallback( function ( $name ) {
103-
return [ 'ext.bootstrapComponents.' . $name . '.fix' ];
104-
} );
105-
106-
$handler = new HooksHandler(
107-
$service,
108-
$library,
109-
$this->createMock( NestingController::class )
110-
);
111-
112-
$text = '';
113-
$handler->onParserAfterParse( $parser, $text, null );
114-
115-
// Per-component fix modules must reach BOTH addModuleStyles and addModules
116-
// (style-only modules treat addModules as a no-op; modules with a scripts
117-
// entry get their JS init via that call).
118-
$this->assertContains( 'ext.bootstrapComponents.tooltip.fix', $loadedStyles );
119-
$this->assertContains( 'ext.bootstrapComponents.popover.fix', $loadedStyles );
120-
$this->assertContains( 'ext.bootstrapComponents.tooltip.fix', $loadedModules );
121-
$this->assertContains( 'ext.bootstrapComponents.popover.fix', $loadedModules );
122-
}
12376
}

0 commit comments

Comments
 (0)