Repository navigation
Revisions: Avoid a null error in list-revisions.js and add TypeScript checking - #16116
faisalahammad wants to merge 1 commit into
Conversation
…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.
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Adds
src/js/_enqueues/lib/list-revisions.jsto TypeScript checking and fixes the defect it found.When the script runs on a page without a
#post-revisionselement,prisnulland the load callback throws:Core registers the
list-revisionshandle but does not enqueue it, so this only affects plugins that enqueue it on other screens.Changes:
#post-revisionsis missing.updatefunction, assign it topr.onclick, and call it directly on load. This also fixes the TypeScript error about callingonclick()without an event argument.attachEvent()fallback, which was only needed for IE 8 and below.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
npm run typecheck:jsand confirm there are no errors.npx wp-scripts lint-js src/js/_enqueues/lib/list-revisions.jsand confirm there are no errors.#post-revisionselement, for example withadd_action( 'admin_enqueue_scripts', function () { wp_enqueue_script( 'list-revisions' ); } );.TypeErrorabove. After this change there is no error.#post-revisionstable ofleftandrightradio 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.