From 715a8261eee493bb0a848b008b0f131bfcad0511 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 28 Nov 2026 15:52:06 +0000 Subject: [PATCH 1/2] Build/Test Tools: Add TypeScript checking for zxcvbn-async.js. Guard missing settings and a null script parent so the loader can be type-checked under the existing strict tsconfig. --- src/js/_enqueues/lib/zxcvbn-async.js | 38 +++++++++++++++------------- tsconfig.json | 1 + typings/browser-globals/index.d.ts | 6 +++++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/js/_enqueues/lib/zxcvbn-async.js b/src/js/_enqueues/lib/zxcvbn-async.js index 114cb5a0d698e..d974f775acc29 100644 --- a/src/js/_enqueues/lib/zxcvbn-async.js +++ b/src/js/_enqueues/lib/zxcvbn-async.js @@ -9,22 +9,26 @@ * script tag on the page. * * This makes sure zxcvbn isn't blocking loading the page as it is a big - * library. The source for zxcvbn is read from the _zxcvbnSettings global. + * library. The source for zxcvbn is read from the `_zxcvbnSettings` global. */ -(function() { - var async_load = function() { - var first, s; - s = document.createElement('script'); - s.src = _zxcvbnSettings.src; - s.type = 'text/javascript'; - s.async = true; - first = document.getElementsByTagName('script')[0]; - return first.parentNode.insertBefore(s, first); - }; +( () => { + const asyncLoad = () => { + if ( typeof _zxcvbnSettings === 'undefined' || ! _zxcvbnSettings.src ) { + return; + } - if (window.attachEvent != null) { - window.attachEvent('onload', async_load); - } else { - window.addEventListener('load', async_load, false); - } -}).call(this); + const script = document.createElement( 'script' ); + script.src = _zxcvbnSettings.src; + script.type = 'text/javascript'; + script.async = true; + + const first = document.getElementsByTagName( 'script' )[ 0 ]; + if ( ! first || ! first.parentNode ) { + return; + } + + first.parentNode.insertBefore( script, first ); + }; + + window.addEventListener( 'load', asyncLoad ); +} )(); diff --git a/tsconfig.json b/tsconfig.json index 2a72ff4c550c2..710e3ddbb1d16 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -41,6 +41,7 @@ "src/js/_enqueues/lib/codemirror/javascript-lint.js", "src/js/_enqueues/lib/emoji-loader.js", "src/js/_enqueues/lib/language-chooser.js", + "src/js/_enqueues/lib/zxcvbn-async.js", "src/js/_enqueues/wp/code-editor.js", "src/js/_enqueues/wp/emoji.js", "src/js/_enqueues/wp/sanitize.js", diff --git a/typings/browser-globals/index.d.ts b/typings/browser-globals/index.d.ts index d79c4e8499f8b..271d212f99de6 100644 --- a/typings/browser-globals/index.d.ts +++ b/typings/browser-globals/index.d.ts @@ -12,3 +12,9 @@ * two conflict. Code which may run in either context therefore has to declare it. */ declare var WorkerGlobalScope: Function | undefined; + +/** + * Localized onto `zxcvbn-async` by `WP_Scripts::localize()`. + * Present only when that script is enqueued. + */ +declare var _zxcvbnSettings: { src: string } | undefined; From 4a433d42dcc52e6eb129578654b7b5f7c2a4fbf6 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sun, 29 Nov 2026 05:11:50 +0000 Subject: [PATCH 2/2] Use Core version for zxcvbn-async script registration --- src/wp-includes/script-loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index b37f2d5717e0e..ef9b05b0a43a5 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -1197,7 +1197,7 @@ function wp_default_scripts( $scripts ) { $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 ); - $scripts->add( 'zxcvbn-async', "/wp-includes/js/zxcvbn-async$suffix.js", array(), '1.0' ); + $scripts->add( 'zxcvbn-async', "/wp-includes/js/zxcvbn-async$suffix.js" ); did_action( 'init' ) && $scripts->localize( 'zxcvbn-async', '_zxcvbnSettings',