Skip to content

Agentic UI: Return to the last visited site instead of the first site - #4130

Merged
bcotrim merged 12 commits into
trunkfrom
restore-last-visited-on-launch
Jul 21, 2026
Merged

Agentic UI: Return to the last visited site instead of the first site#4130
bcotrim merged 12 commits into
trunkfrom
restore-last-visited-on-launch

Conversation

@bcotrim

@bcotrim bcotrim commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

The core change was cherry-picked from #3998 (authored there with AI assistance). Claude Code ported it onto trunk, resolved merge conflicts (including the moves to id-based session↔site matching from #4131 and the signed-out gates from #4183), addressed review feedback, and wrote the unit tests for the redirect logic. All code was reviewed and verified locally (lint, typecheck, apps/ui test suite).

Proposed Changes

Studio's agentic UI always lands on the first site (in raw fetch order) at launch, regardless of where the user was working. This PR makes the app reopen on the site the user last worked with:

  • The dashboard remembers the last visited site in localStorage.
  • On launch, the / index route opens that site's newest active chat (or a new chat if it has none) — matching exactly what clicking the site in the site-centric sidebar (Agentic UI: Make the sidebar site-centric #4191) does.
  • If the remembered site no longer exists (deleted) or nothing is stored yet, it falls back to the top site in sidebar order, respecting the manual ordering from Add drag-to-reorder for sites in the agentic UI sidebar #4134 instead of raw fetch order.
  • The sidebar auto-scrolls to keep the restored site's row visible when it sits below the fold (thanks @sejas for catching this!).

An earlier revision restored the exact last-visited session. We simplified to site-level restore to stay consistent with the site-centric sidebar model: sites are the primary navigation unit, and a site always opens its newest active chat.

No launch-time cost: the index route already fetched sites and sessions before redirecting; this adds only a synchronous localStorage read.

Testing Instructions

  1. Launch Studio with the agentic UI and open a chat on a site other than the top one in the sidebar.
  2. Quit and relaunch — you should land on that same site (its newest active chat).
  3. With enough sites to make the sidebar scroll, work on a site near the bottom, relaunch — the sidebar should scroll so the selected site's row is visible.
  4. Archive the chat you were on, relaunch — you should land on that site's newest remaining active chat, or a new chat if none are left.
  5. Delete the site you were on, relaunch — you should land on your sidebar's top site, with no errors.
  6. Drag a different site to the top of the sidebar, clear the app's localStorage, relaunch — the fallback should follow your sidebar order.

Pre-merge Checklist

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

🤖 Generated with Claude Code

@bcotrim
bcotrim marked this pull request as ready for review July 9, 2026 19:32
@bcotrim
bcotrim requested review from a team and katinthehatsite July 9, 2026 19:32
@wpmobilebot

wpmobilebot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing f6486cb vs trunk

app-size

Metric trunk f6486cb Diff Change
App Size (Mac) 1361.88 MB 1355.58 MB 6.30 MB 🟢 -0.5%

site-editor

Metric trunk f6486cb Diff Change
load 1113 ms 752 ms 361 ms 🟢 -32.4%

site-startup

Metric trunk f6486cb Diff Change
siteCreation 6500 ms 6526 ms +26 ms ⚪ 0.0%
siteStartup 2380 ms 2394 ms +14 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@katinthehatsite

Copy link
Copy Markdown
Contributor

Delete the site you were on without archiving the session, relaunch — you land back on that session with a name-only header (see Notes above), with no errors.

I seem to land on name-only session for that canse but then I can still send messages and they go into the Unassigned section (so the local site is deleted but I can send messages):

Screenshot 2026-07-13 at 3 47 56 PM

When I am asking the chat about it, it says the site no longer exists (I guess it makes sense that it is now Unassigned):

Screenshot 2026-07-13 at 3 49 22 PM

But I am finding the experience a bit strange, should be disable the input field in that case? I am guessing part of the problem will be solved when we delete the sessions when the user deletes the site in a different PR I review earlier.

@bcotrim bcotrim changed the title Return to the last visited session instead of the first site Jul 16, 2026
@bcotrim bcotrim changed the title Return to the last visited site instead of the first site Jul 16, 2026
@bcotrim

bcotrim commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @katinthehatsite! 🙌

Can you take another look at this PR, please?

@bcotrim
bcotrim requested review from nightnei and sejas July 20, 2026 12:56

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. I confirmed the last selected site is the one that is selected when Studio starts again.
I have two suggestions to consider:

  1. Change the PR title to say last visited site, instead of last visited session.
  2. If the left sidebar has scroll and the selected site is at the bottom, then the selected site row is not visible when starting Studio.
latest-selected-site.mp4
@bcotrim bcotrim changed the title Agentic UI: Return to the last visited session instead of the first site Jul 21, 2026
@nightnei

nightnei commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Delete the site you were on, relaunch — you should land on your sidebar's top site, with no errors.

I spotted another bug here - when we delete a site, the chat remains active. We should probably auto-select another site instead.
But after restarting Studio - it works well - I indeed see the first website in the list is auto-selected.
Screenshot 2026-07-21 at 18 19 04

@bcotrim

bcotrim commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Delete the site you were on, relaunch — you should land on your sidebar's top site, with no errors.

I spotted another bug here - when we delete a site, the chat remains active. We should probably auto-select another site instead. But after restarting Studio - it works well - I indeed see the first website in the list is auto-selected. Screenshot 2026-07-21 at 18 19 04

Let's address that in #4132

@bcotrim
bcotrim enabled auto-merge (squash) July 21, 2026 17:23
@bcotrim

bcotrim commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Looks good. I confirmed the last selected site is the one that is selected when Studio starts again. I have two suggestions to consider:

1. Change the PR title to say last visited site, instead of last visited session.

2. If the left sidebar has scroll and the selected site is at the bottom, then the selected site row is not visible when starting Studio.

Done, thanks for catching that! 🙇

@bcotrim
bcotrim merged commit 7687ded into trunk Jul 21, 2026
13 checks passed
@bcotrim
bcotrim deleted the restore-last-visited-on-launch branch July 21, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants