Skip to content

fix(comments): clear table selection after bulk moderation#293

Merged
epeicher merged 1 commit into
trunkfrom
fix/comments-clear-selection-after-bulk-action
Jun 4, 2026
Merged

fix(comments): clear table selection after bulk moderation#293
epeicher merged 1 commit into
trunkfrom
fix/comments-clear-selection-after-bulk-action

Conversation

@epeicher
Copy link
Copy Markdown
Collaborator

@epeicher epeicher commented Jun 4, 2026

Summary

Fixes a selection-state bug in the Comments window: after a bulk action, the acted-on comment's id stayed in the table's selection set, so the next selection read as "2 selected" and the following bulk action also hit the previously-actioned comment.

Steps to reproduce

  1. Select a comment, click Trash.
  2. Select a different comment. The bar shows 2 selected (should be 1).
  3. Click Spam. Both the new comment and the previously trashed one are spammed.

Root cause

<wpd-table> deliberately keeps its selection across data refreshes (stale ids are filtered out only at paint time, to support cross-page selection). The Comments window never cleared the selection after a bulk action, so trashed/spammed ids lingered in table.selection. Setting .data doesn't emit wpd-table-selection-change, so the "N selected" chip didn't refresh either.

Fix

After a successful bulk action, runBulk calls state.table.clearSelection(). That emits wpd-table-selection-change, which resets the "N selected" chip and hides the bulk bar. This covers every moderation path (the bulk buttons and the j/k/a/s/d keyboard shortcuts all route through runBulk).

Testing

  • npm run build, npm run lint, npm run typecheck, and npm run test:js (1519 tests) all pass.
  • Verified manually on local dev: trash a comment, select another (reads "1 selected"), spam, and only the intended comment is affected.
Open WordPress Playground Preview

After a bulk action, the acted-on rows leave the current tab but
<wpd-table> intentionally preserves its selection set across data
refreshes (stale ids are only hidden at paint time). The stale ids
lingered in table.selection, so the next row the user selected showed
"2 selected" and a follow-up bulk action operated on the phantom id
too: trashing a comment then spamming a different one also spammed the
already-trashed comment.

Reset the selection after a successful bulk action via
table.clearSelection(), which also emits wpd-table-selection-change to
refresh the "N selected" chip and hide the bulk bar. This covers every
moderation path, since the bulk buttons and the j/k/a/s/d keyboard
shortcuts all route through runBulk.
@epeicher epeicher enabled auto-merge (squash) June 4, 2026 15:31
@epeicher epeicher merged commit 2f35d04 into trunk Jun 4, 2026
5 checks passed
@epeicher epeicher deleted the fix/comments-clear-selection-after-bulk-action branch June 4, 2026 15:32
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