Skip to content

Fix Recycle Bin Sync - #432

Merged
AllTerrainDeveloper merged 4 commits into
WordPress:trunkfrom
CookieDarb:fix/recycle-bin-sync
Jul 28, 2026
Merged

Fix Recycle Bin Sync#432
AllTerrainDeveloper merged 4 commits into
WordPress:trunkfrom
CookieDarb:fix/recycle-bin-sync

Conversation

@CookieDarb

Copy link
Copy Markdown
Contributor

What?

Closes #421

Fixes cross-window live sync for Recycle Bin and My WordPress when items (posts, pages, media, and custom post types) are trashed, restored, or permanently deleted.

Why?

Previously, dragging an item into the Recycle Bin or restoring an item while My WordPress was open did not trigger cross-window updates. Additionally, broadcast topic subscriptions were hardcoded to built-in post types (post, page, attachment), leaving custom post types and My WordPress root folder counters out of sync until a manual page reload.

How?

  • includes/my-wordpress/window.php & src/my-wordpress/types.ts:
    • Added post_type attribute to default entities (post, page, attachment) and updated MyWordPressEntity interface so custom post types can register their post type slug via desktop_mode_my_wordpress_entities.
  • includes/recycle-bin/window.php:
    • Injected recycleBinPostTypes into desktopModeConfig from desktop_mode_recycle_bin_capture_post_types().
  • src/recycle-bin/badge.ts & src/recycle-bin/index.ts:
    • Refactored Recycle Bin window and Dock Badge to dynamically subscribe to broadcast change topics (desktop-mode.<post_type>.changed) for all registered post types.
  • src/recycle-bin/rest.ts:
    • Emitted broadcast events (untrashed / deleted) upon successful restore or permanent deletion REST requests.
  • src/my-wordpress/index.ts:
    • Subscribed to mapped entity broadcast topics to trigger debounced list view refreshes.
    • Subscribed to broadcast topics in renderRoot to dynamically update entity folder counters (e.g., Posts · X, Pages · Y).
  • docs/hooks-reference.md:
    • Documented post_type property in desktop_mode_my_wordpress_entities filter reference.
  • tests/:
    • Added Vitest suites (my-wordpress-sync.test.ts, recycle-bin-badge-subscriptions.test.ts) for broadcast subscriptions and debouncing.
    • Added PHPUnit tests in myWordpress.php and recycleBinStore.php verifying entity schemas and localized script configurations.

Testing Instructions

  1. Open both Recycle Bin and My WordPress windows simultaneously.
  2. Trash an item (post, page, or custom post type) by dragging it into the Recycle Bin or via an action menu.
  3. Verify that:
    • The Recycle Bin window updates instantly to show the trashed item.
    • The Dock/Tile Recycle Bin badge counter increments.
    • The My WordPress list view and root folder counter update reactively.
  4. In the Recycle Bin window, click Restore on the item.
  5. Verify that:
    • The item disappears from the Recycle Bin.
    • The Recycle Bin badge counter decrements.
    • The My WordPress window reactively updates its list and folder counter without a manual browser reload.

Screencast

Screen.Recording.2026-07-28.at.3.57.39.PM.mov

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Reviewing the existing implementation, evaluating approaches and suggesting the changes. Final decisions and edits were made by me.

- Inject captured post types from PHP to JS (shell config and local config)
- Refactor Recycle Bin window and Dock Badge to subscribe dynamically to changes in these post types
- Map post types to My WordPress entities using a new 'post_type' attribute
- Broadcast trash events from My WordPress and listen to external changes to trigger debounced refreshes
- Update hooks documentation to explain 'post_type' usage for custom post types
- Verify My WordPress subscribes to mapped post types and debounces refresh on broadcast
- Verify Dock Badge dynamically registers custom post type listeners from config
- Assert post type property mappings on My WordPress entity array in PHPUnit
- Assert shell config filter and localized scripts include captured post types
- Subscribe to cross-window broadcast change signals in the root view.

- Reactively refresh folder counters without a page reload.
@CookieDarb
CookieDarb marked this pull request as ready for review July 28, 2026 10:43

@AllTerrainDeveloper AllTerrainDeveloper left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful! Thanks again for your contributions!

Screen.Recording.2026-07-28.at.16.05.25.mov

@AllTerrainDeveloper
AllTerrainDeveloper enabled auto-merge (squash) July 28, 2026 14:09
@AllTerrainDeveloper
AllTerrainDeveloper merged commit b1df7fc into WordPress:trunk Jul 28, 2026
5 checks passed
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.

Dropping a post to the recycle bin does not refresh it

2 participants