Guard against undefined $container element in initMobile.js

In order to prevent spikes in JS errors, ensure that the $container
element exists before initializing the mobile media viewer.

Bug: T360781
Change-Id: I48a57e8008e7bd90e9fcfc783f3720f6f75520a7
This commit is contained in:
Jan Drewniak 2024-03-25 09:38:11 -04:00
parent 278b5189bd
commit cf723c00c3

View file

@ -444,7 +444,12 @@ module.exports = function () {
// setup toc icons
mw.hook( 'wikipage.content' ).add( function ( $container ) {
// If the MMV module is missing or disabled from the page, initialise our version
if ( desktopMMV === null || desktopMMV === 'registered' ) {
if (
desktopMMV === null ||
desktopMMV === 'registered' &&
// T360781
$container &&
$container[ 0 ] ) {
initMediaViewer( $container[ 0 ] );
}