diff --git a/resources/dist/index.js b/resources/dist/index.js index 36cd466f0..0b6d0fcf2 100644 Binary files a/resources/dist/index.js and b/resources/dist/index.js differ diff --git a/resources/dist/index.js.map.json b/resources/dist/index.js.map.json index 433d6edc5..22819519c 100644 Binary files a/resources/dist/index.js.map.json and b/resources/dist/index.js.map.json differ diff --git a/src/index.js b/src/index.js index 0f2a6a89f..30bfc4ad0 100644 --- a/src/index.js +++ b/src/index.js @@ -135,17 +135,30 @@ function registerChangeListeners( */ function handleDOMEventIfEligible( handler ) { return function ( event ) { - // if the element is a text node, as events can be triggered on text nodes - // it won't have a closest method, so we get its parent element (T340081) - if ( event.target.nodeType === 3 ) { - event.target = event.target.parentNode; - } - // If the event bubbles up all the way, - // document does not have closest method, so exit early (T336650). - if ( event.target === document ) { + let target = event && event.target; + if ( !target ) { return; } - const target = findNearestEligibleTarget( event.target ); + // if the element is a text node, as events can be triggered on text nodes + // it won't have a closest method, so we get its parent element (T340081) + if ( target.nodeType === 3 ) { + target = target.parentNode; + } + + // If the closest method is not defined, let's return early and + // understand this better by logging an error. (T340081) + if ( target && !target.closest ) { + const err = new Error( `T340081: Unexpected DOM element ${target.tagName} with nodeType ${target.nodeType}` ); + mw.errorLogger.logError( err, 'error.web-team' ); + return; + } + + // If the event bubbles up all the way, + // document does not have closest method, so exit early (T336650). + if ( target === document ) { + return; + } + target = findNearestEligibleTarget( target ); if ( target === null ) { return; } diff --git a/webpack.config.js b/webpack.config.js index 65651fc5a..3b9a45adc 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -118,8 +118,8 @@ module.exports = ( env, argv ) => ( { // Minified uncompressed size limits for chunks / assets and entrypoints. Keep these numbers // up-to-date and rounded to the nearest 10th of a kibibyte so that code sizing costs are // well understood. Related to bundlesize minified, gzipped compressed file size tests. - maxAssetSize: 46.4 * 1024, - maxEntrypointSize: 46.4 * 1024, + maxAssetSize: 46.5 * 1024, + maxEntrypointSize: 46.5 * 1024, // The default filter excludes map files but we rename ours. assetFilter: ( filename ) => !filename.endsWith( srcMapExt )