Automattic / Automattic/wp-calypso

Full-screen site switcher sets incorrect initial selection when loading a large number of sites

Open
#97,342 10 comments 0 reactions 0 assignees View on GitHub
[Experiment] AI labels added [Feature Group] Accessibility & Navigation [Feature] Site Navigation [Feature] User Management [Platform] Atomic [Platform] Simple [Pri] Low [Status] Auto-allocated [Status] Needs Author Reply Bug Groundskeeping Quality Sprint: Week 2
Dominant language
TypeScript
Stars
12.6k
Forks
2k
Avg merge
1d 17h
Merged PRs (30d)
538

Description

### Quick summary

When the _full-screen variant_ of the site switcher initially loads, it sets the initial selection to the first site listed. However, if the current user has many sites, when additional sites (lazily?) load, the site switcher erroneously moves selection to a site hidden outside of the currently visible sites in the scroll view.

This results in unexpected or incorrect site selection when attempting to navigate with a keyboard. E.g., pressing the Return key selects the out-of-view site, and pressing the down arrow key dow not move selection to the first visible site in the list.

The issue does not occur for accounts with a small number of sites, presumably because all of the sites are loaded in one step, rather than lazily loaded. It also only occurs for the full-screen version of the site switcher that is used when selecting _Switch site_ from a WP Admin page, the issue does not occur when using the _Switch site_ command from a WordPress.com page.

| Affected | Unaffected |
| - | - |
| Image | Image |

### Steps to reproduce

1. With an account the possesses many sites, visit a WordPress.com site's WP Admin _Dashboard_—e.g., `https:///wp-admin/`.
2. Press Command + K.
3. Select the site switcher command.
4. Wait for the site list to load.
5. Press the keyboard down arrow key.

### What you expected to happen

The site switcher selection is moved to the second item.

### What actually happened

The site switcher selection is moved a site somewhere much further down the list.

### Impact

Some (< 50%)

### Available workarounds?

Yes, easy to implement

### If the above answer is "Yes...", outline the workaround.

Typing a search query causes the site switcher to refresh the current selection, resetting the current selection to the expected location.

### Platform (Simple and/or Atomic)

Simple, Atomic, Self-hosted

### Logs or notes

macOS 15.1.1
Safari 18.1.1

Contributor guide

Open the contributing guide

Research direction

Start from the WP Admin Dashboard flow opened with Command-K, then select the site switcher and reproduce the behavior with an account containing many sites. Check the full-screen site list while lazy-loaded sites appear, and verify that the initial selection stays on the first visible item, the down arrow selects the second item, and Return does not select an out-of-view site.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.