Load per-component JS init modules so tooltip/popover open on MediaWiki 1.43+#79
Closed
malberts wants to merge 1 commit into
Closed
Load per-component JS init modules so tooltip/popover open on MediaWiki 1.43+#79malberts wants to merge 1 commit into
malberts wants to merge 1 commit into
Conversation
The per-component JS init modules (tooltip.fix, popover.fix, carousel.fix) each declare a scripts entry in extension.json that calls the Bootstrap library on the trigger elements. Without these modules reaching the page, hover on a .bootstrap-tooltip and click on a data-toggle="popover" element do nothing. HooksHandler::onParserAfterParse iterates getActiveComponents() and calls addModuleStyles() per component, but getActiveComponents() is only populated by ImageModal — tooltip, popover, and carousel never register themselves as active. So the foreach never reaches their .fix modules at all; even if it did, addModuleStyles loads only CSS. Queue the per-component init modules unconditionally on OutputPage from the OutputPageParserOutput hook. addModules is the right call (loads the JS via mw.loader). Each init script is a no-op on pages without the corresponding trigger markup. Verified on a fresh MW 1.39.17 + Vector + BC stack and on a MW 1.43.8 + Chameleon BS4 + BC stack: tooltip hover and popover click both produce the expected popups. PHPUnit unit suite remains green relative to baseline (6 pre-existing failures unchanged). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
c3fac79 to
a38f83f
Compare
Collaborator
Author
|
Superseded by #80 — that PR closes the same #68 sub-bugs but takes the architecturally-correct path: restores BC's intended sparse-loading scheme via the AbstractComponent chokepoint, rather than this PR's unconditional-load workaround in Net: #80 is +5 lines / -0 (vs #79's +37 / -7), with no workaround-flavour code, and on a tooltip-only page only |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #68.
Completes the fix for #68 by resolving the tooltip, popover and carousel sub-bugs left out of #75 (which addressed only the modal symptom).
Root cause
The per-component JS init modules
ext.bootstrapComponents.{tooltip,popover,carousel}.fixeach declare ascripts:entry inextension.jsonthat initialises the Bootstrap library on the trigger elements (.tooltip(),.popover(),.carousel()). Without these modules reaching the page, hover on a.bootstrap-tooltipand click on a[data-toggle="popover"]do nothing.HooksHandler::onParserAfterParseis supposed to load them via thegetActiveComponents()foreach, but two issues break that path:ImageModalregisters itself as active. Tooltip, popover, and carousel parser hooks never callregisterComponentAsActive(), sogetActiveComponents()never contains them and the foreach never iterates over their modules.addModuleStyles()— which loads only the CSS half. Thescripts:half of a module never reaches the page through that call.Fix
Move per-component init module loading to
OutputPageParserOutput::process(), where the three init modules are added unconditionally to the persistentOutputPageviaaddModules(). Each init script is a single jQuery selector + initializer call ($('[data-toggle="tooltip"]').tooltip()etc.); on a page without the matching trigger markup the selector returns an empty collection and the initializer no-ops. Per-request cost on tooltip/popover/carousel-free pages: three small DOM queries served from a cached ResourceLoader bundle — negligible.Scope
src/Hooks/OutputPageParserOutput.php— adds oneaddModulescall inprocess()listing the three per-component init modulestests/phpunit/Unit/Hooks/OutputPageParserOutputTest.php(rewritten the twoprocess()cases to assert the union ofaddModulescalls — same mocking pattern PR Fix modal trigger not opening modals on MediaWiki 1.43+ #75 used intestHookOutputPageParserOutputLoadsModules)Net: +37 / −7 lines.
Verification
Tested on MW 1.43.8 + Chameleon BS4 (where the bug manifests) and on the oldest supported floor MW 1.39.17 across three BS4 skins — Vector, Chameleon BS4, and Medik:
Module + instance state on both stacks after page load:
Tests
PHPUnit (
--group mediawiki-databaseless) on MW 1.39:Same 6 pre-existing failures in
BootstrapComponentsServiceTest/ImageModalTriggerTest/ImageModalTest(manual-thumbnail variants). All unrelated to the JS-init module path.🤖 Generated with Claude Code