Skip to content

Conversation

@gcsecsey
Copy link
Contributor

  • Update site selection logic to preserve the currently selected site if it still exists after deletion.
  • Add tests to verify that the first remaining site is selected when the currently selected site is deleted, and that selection remains unchanged when a different site is deleted.

Related issues

Proposed Changes

  • Updated onDeleteSite to check if the currently selected site still exists after deletion
  • If the selected site still exists (user switched to another site), the selection is preserved
  • If the selected site was deleted, it switches to the first remaining site
  • Added unit tests to verify both scenarios

Testing Instructions

  1. Start Studio with npm start
  2. Create three sites (Site 1, Site 2, Site 3)
  3. Delete Site 3
  4. While the deletion is going on, quickly select Site 2
  5. Check that Site 2 remains selected, and the selection doesn't change to Site 1

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

- Update site selection logic to preserve the currently selected site if it still exists after deletion.
- Add tests to verify that the first remaining site is selected when the currently selected site is deleted, and that selection remains unchanged when a different site is deleted.
@gcsecsey gcsecsey requested a review from a team January 22, 2026 14:00
@gcsecsey gcsecsey changed the title Update site deletion behavior in useSiteDetails hook Update site selection behavior after site deletion Jan 22, 2026
@wpmobilebot
Copy link

wpmobilebot commented Jan 22, 2026

📊 Performance Test Results

Comparing 17075a3 vs trunk

site-editor

Metric trunk 17075a3 Diff Change
load 2883.00 ms 2876.00 ms -7.00 ms 🟢 -0.2%

site-startup

Metric trunk 17075a3 Diff Change
siteCreation 7092.00 ms 7082.00 ms -10.00 ms 🟢 -0.1%
siteStartup 3938.00 ms 3934.00 ms -4.00 ms 🟢 -0.1%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change

Copy link
Contributor

@ivan-ottinger ivan-ottinger left a comment

Choose a reason for hiding this comment

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

Nice! Works well and the change looks good. Thank you for adding the test as well.

CleanShot.2026-01-22.at.15.38.30.mp4

Copy link
Contributor

@epeicher epeicher left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this @gcsecsey! I have tested it, and it works as advertised. I can see that the second site remains selected using this branch while it selects the first site in trunk. LGTM! :shipit:

Trunk This branch
Image Image

@gcsecsey gcsecsey merged commit 0d745fc into trunk Jan 23, 2026
9 checks passed
@gcsecsey gcsecsey deleted the stu-1241-when-deleting-site-focus-always-moves-to-the-first-site branch January 23, 2026 09:55
@wojtekn
Copy link
Contributor

wojtekn commented Jan 23, 2026

It seems it still changes the tab to Overview for the selected site.

@gcsecsey
Copy link
Contributor Author

It seems it still changes the tab to Overview for the selected site.

Good catch, I added a follow-up for this in #2468

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.

6 participants