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: |
|
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
- Navigate to src/js/_enqueues/wp/api.js
- Locate the trashableTypes array
- Observe duplicate 'Comment' entry
Attachments (2)
Change History (6)
#1
@
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
This ticket was mentioned in Slack in #core-restapi by baikaresandeep007-1. View the logs.
5 weeks ago
#3
@
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 ✅
A patch will be attached to remove the duplicate entry.