Skip to content

Build/Test Tools: Add TypeScript checking for zxcvbn-async.js - #16302

Closed
shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:add/66751-typecheck-zxcvbn-async
Closed

shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:add/66751-typecheck-zxcvbn-async

Conversation

@shail-mehta

@shail-mehta shail-mehta commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

What

Trac ticket: #66751

Adds src/js/_enqueues/lib/zxcvbn-async.js to TypeScript checking and fixes the defects it found.

Why

  • _zxcvbnSettings was an undeclared global
  • first.parentNode can be null, which would throw when inserting the script
  • window.attachEvent is not on the Window type (IE 8 leftover)

How

  • Return early when _zxcvbnSettings is missing or has no src, and when there is no first <script> with a parent node.
  • Load the script with addEventListener( 'load', ... ) only. Drop attachEvent(), which was only needed for IE 8 and below.
  • Replace var with const, use arrow functions, and reformat to the JavaScript coding standards.
  • Declare optional _zxcvbnSettings in typings/browser-globals.
  • Add the file to tsconfig.json, keeping the list sorted.

Testing Instructions

  1. Run npm run typecheck:js and confirm there are no errors.
  2. Run npx wp-scripts lint-js src/js/_enqueues/lib/zxcvbn-async.js and npx prettier --check src/js/_enqueues/lib/zxcvbn-async.js and confirm there are no errors.
  3. Open a screen that uses the password strength meter, for example Users → Add New User.
  4. Confirm the password field still shows strength feedback after typing a password (zxcvbn still loads).
  5. In DevTools, confirm a zxcvbn.min.js script is added after page load.

Use of AI Tools

  • Cursor

Guard missing settings and a null script parent so the loader can be type-checked under the existing strict tsconfig.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the changes adding TypeScript coverage and defensive guards to the asynchronous zxcvbn loader.

No open issues 🎉

What changed in this PR

Adds TypeScript checking for the asynchronous zxcvbn loader, continuing the file-by-file coverage effort for #66751 while preserving normal password-strength library loading.

Changes:

  • Adds the loader to TypeScript checking and declares its optional localized settings global.
  • Guards against missing settings, an empty source URL, and an unavailable script insertion point.
  • Removes legacy IE event handling and modernizes JavaScript syntax and formatting.
File Description
typings/​browser-globals/​index.d.ts Declares optional _zxcvbnSettings and its source URL.
tsconfig.json Includes zxcvbn-async.js in TypeScript checking.
src/​js/​_enqueues/​lib/​zxcvbn-async.js Adds defensive guards and modernizes the load handler.

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review November 28, 2026 15:58
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shailu25, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript passes, and I checked the password-strength meter in Chromium on the password reset and Add New User screens. One change before landing: please drop the hard-coded '1.0' from the zxcvbn-async registration so the loader uses the Core version, like password-strength-meter just below it.

Both trunk and this patch serve the changed loader at zxcvbn-async.min.js?ver=1.0. A browser with a fresh cached copy can keep running the old code after an upgrade. Only the loader needs a new cache key.

AI review · gpt-6.2-astra

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache-key fix works. I checked the registered minified loader URL on both commits. It changed from ?ver=1.0 to the checkout’s Core version. The JavaScript is identical to the version I tested on the password screens, and the TypeScript build passes on 4a433d4. Approved.

AI review · gpt-6.2-astra

@lancewillett lancewillett moved this from In progress to In review in WordPress Project Build Tooling Nov 29, 2026
wporg-sync pushed a commit that referenced this pull request Nov 29, 2026
Guard against missing loader settings or an unavailable insertion point. Use the Core version for the `zxcvbn-async` script URL.

Developed in: #16302

Props shailu25.
See #66751.


git-svn-id: https://develop.svn.wordpress.org/trunk@65822 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 29, 2026
Guard against missing loader settings or an unavailable insertion point. Use the Core version for the `zxcvbn-async` script URL.

Developed in: WordPress/wordpress-develop#16302

Props shailu25.
See #66751.

Built from https://develop.svn.wordpress.org/trunk@65822


git-svn-id: http://core.svn.wordpress.org/trunk@64851 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants