Skip to content

Revisions: Avoid a null error in list-revisions.js and add TypeScript checking - #16116

Open
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:ticket/66751-list-revisions-typecheck
Open

faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:ticket/66751-list-revisions-typecheck

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Nov 19, 2026 •

Copy link
Copy Markdown

Adds src/js/_enqueues/lib/list-revisions.js to TypeScript checking and fixes the defect it found.

When the script runs on a page without a #post-revisions element, pr is null and the load callback throws:

Uncaught TypeError: Cannot set properties of null (setting 'onclick')

Core registers the list-revisions handle but does not enqueue it, so this only affects plugins that enqueue it on other screens.

Changes:

  • Return early from the load callback when #post-revisions is missing.
  • Move the click handler into a named update function, assign it to pr.onclick, and call it directly on load. This also fixes the TypeScript error about calling onclick() without an event argument.
  • Remove the attachEvent() fallback, which was only needed for IE 8 and below.
  • Add the file to tsconfig.json, keeping the list sorted.

Behavior on pages that do have the revisions table is unchanged.

Trac ticket: https://core.trac.wordpress.org/ticket/66751

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/list-revisions.js and confirm there are no errors.
  3. Enqueue the script on an admin screen that has no #post-revisions element, for example with add_action( 'admin_enqueue_scripts', function () { wp_enqueue_script( 'list-revisions' ); } );.
  4. Load the screen. Before this change the console shows the TypeError above. After this change there is no error.
  5. On a page with a #post-revisions table of left and right radio buttons, confirm the buttons are hidden and shown on load and on click the same way as before.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude desktop app (Claude Code)
Model(s): Claude Opus 5.5
Used for: Measuring TypeScript errors per file, finding the null defect in list-revisions.js, drafting the fix, running the type, lint, and browser checks, and writing this description.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…pt checking.

Return early from the `list-revisions` load callback when the `#post-revisions` element is not on the page, instead of throwing a `TypeError` when setting `onclick` on `null`. The click handler is now a named function so it can be called directly on load without a missing event argument. The `attachEvent()` fallback for IE 8 and below is removed.

This also adds `list-revisions.js` to `tsconfig.json`.

See #66751.
@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.

@faisalahammad
faisalahammad marked this pull request as ready for review November 19, 2026 21:07
@github-actions

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 faisalahammad.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant