Repository navigation
Revisions: Avoid a null error in list-revisions.js and add TypeScript checking - #16116
faisalahammad wants to merge 5 commits 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:
|
westonruter
left a comment
There was a problem hiding this comment.
Let's also reformat this JS file to follow JS coding standards while we're at it. This includes the use of braces for if statements.
…revisions-typecheck # Conflicts: # tsconfig.json
…ons.js`. Attach the click handler with `addEventListener()` instead of `onclick`. Replace `var` with `const` and `let`, and return early when `#post-revisions` is missing or has no `input` elements. Reformat the file to follow the JavaScript coding standards, including braces for `if` statements and strict equality checks. See #66751.
|
@westonruter I reformatted the file with the WordPress Prettier config in a36bb32. All |
…revisions-typecheck
…ons.js`. - Use arrow functions for the IIFE, `init`, and `update`. - Use `window` directly instead of the `w` parameter. Addresses PR feedback. Refs WordPress#16116
|
@westonruter I applied your suggestions in c63367d. The IIFE, |
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 or has noinputelements.addEventListener()and call it directly on load. This also fixes the TypeScript error about callingonclick()without an event argument.varwithconstandlet, use arrow functions, drop thewalias forwindow, and reformat the file to follow the JavaScript coding standards, including braces forifstatements and strict equality checks.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.jsandnpx prettier --check 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.