Make WordPress Core

Opened 5 weeks ago

Last modified 4 weeks ago

#65045 new defect (bug)

Duplicate 'Comment' entry in trashableTypes array in wp/api.js

Reported by: baikaresandeep007's profile baikare.sandeep007 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: REST API Keywords: has-patch
Focuses: javascript, rest-api, coding-standards Cc:

Description

While reviewing the file src/js/_enqueues/wp/api.js, I noticed that the trashableTypes array contains a duplicate entry for 'Comment'.

Current code:
trashableTypes = [ 'Comment', 'Media', 'Post', 'Page', 'Status', 'Taxonomy', 'Type' ];

The presence of duplicate values in this array is unnecessary and may lead to redundant checks or confusion during maintenance.

Proposed fix:
Remove the duplicate 'Comment' entry to ensure the array contains only unique values.

This change improves code clarity and avoids potential redundancy in logic that relies on this array.

Steps to reproduce

  1. Navigate to src/js/_enqueues/wp/api.js
  2. Locate the trashableTypes array
  3. Observe duplicate 'Comment' entry

Attachments (2)

trashable-types-fix.patch (503 bytes) - added by baikare.sandeep007 5 weeks ago.
A patch will be attached to remove the duplicate entry.
trashable-types-fix.2.patch (503 bytes) - added by baikare.sandeep007 5 weeks ago.
A patch will be attached to remove the duplicate entry.

Download all attachments as: .zip

Change History (6)

@baikare.sandeep007
5 weeks ago

A patch will be attached to remove the duplicate entry.

@baikare.sandeep007
5 weeks ago

A patch will be attached to remove the duplicate entry.

#1 @gaurangsondagar
5 weeks ago

Tested patch: https://core.trac.wordpress.org/attachment/ticket/65045/trashable-types-fix.patch

Steps I followed:

  • Located the 'trashableTypes' array in 'wp/api.js' and confirmed the duplicate 'Comment' entry.
  • Applied the patch and verified the duplicate entry has been removed.
  • Tested comment trash, restore, and delete actions from the admin panel.
  • Confirmed no JavaScript errors and no regressions in functionality.

Environment:

  • WordPress: 7.1-alpha-62161-src
  • PHP: 8.3.30
  • Browser: Chrome
  • Database: MySQL 8.4.8
  • OS: Ubuntu

As this is a minor code duplication issue with no visible UI impact, the fix improves code clarity without affecting behavior.

Screenshot reference of the file: src/js/_enqueues/wp/api.js
https://kommodo.ai/i/6czUCkf7CGmkmBe0Naoh

Last edited 5 weeks ago by gaurangsondagar (previous) (diff)

This ticket was mentioned in Slack in #core-restapi by baikaresandeep007-1. View the logs.


5 weeks ago

#3 @darshitrajyaguru97
4 weeks ago

Patch Tested

https://core.trac.wordpress.org/attachment/ticket/65045/trashable-types-fix.2.patch

Testing Summary

I tested the updated patch and can confirm that it correctly removes the duplicate 'Comment' entry from the trashableTypes array in src/js/_enqueues/wp/api.js.

Steps Performed

# Located the trashableTypes array in wp/api.js and verified the duplicate 'Comment' entry in the original code.
# Applied the trashable-types-fix.2.patch.
# Confirmed that the duplicate 'Comment' entry was removed and the array now contains only unique values.
# Tested the following actions in the WordPress admin:

# Trash comment
# Restore comment
# Permanently delete comment

# Checked the browser console for JavaScript errors.

Results

  • ✅ Duplicate entry successfully removed
  • ✅ No JavaScript errors observed
  • ✅ No regression in functionality
  • ✅ Trash-related operations for comments and other post types work as expected

Environment

  • WordPress: 7.0 RC2
  • PHP: 8.3.30
  • Browser: Chrome
  • OS: Windows

Conclusion

The patch works as expected.

This change improves code clarity by removing redundant data without affecting functionality.

Recommendation: Patch is good to commit ✅

#4 @baikare.sandeep007
4 weeks ago

Thanks for testing @darshitrajyaguru97 @gaurangsondagar

Note: See TracTickets for help on using tickets.