Repository navigation
fix(web-shell): persist collapsed session group sections across reload #6878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
samuelhsin
merged 7 commits into
QwenLM:main
from
samuelhsin:fix/web-shell-persist-collapsed-session-groups
Jul 15, 2026
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0b1ddfe
fix(web-shell): persist collapsed session group sections across reload
samuelhsin e6897f0
docs(web-shell): clarify collapsed-groups demo GIF storyboard
samuelhsin ed458e7
fix(web-shell): address collapsed-groups CR feedback
samuelhsin 4a0a7aa
fix(web-shell): harden collapsed-groups persistence for CR feedback
samuelhsin 5899ad2
refactor(web-shell): drop demo-capture tooling from collapsed-groups …
claude dee8fc6
fix(web-shell): keep collapse latch armed until catalogs settle succe…
claude 5bed453
Merge branch 'main' into fix/web-shell-persist-collapsed-session-groups
samuelhsin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
287 changes: 287 additions & 0 deletions
287
packages/web-shell/client/components/sidebar/WebShellSidebar.collapse-persist.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,287 @@ | ||
| // @vitest-environment jsdom | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { act } from 'react'; | ||
| import { createRoot, type Root } from 'react-dom/client'; | ||
| import type { DaemonSessionSummary } from '@qwen-code/sdk/daemon'; | ||
|
|
||
| const COLLAPSED_SESSION_SECTIONS_STORAGE_KEY = | ||
| 'qwen-code-web-shell-collapsed-session-groups'; | ||
|
|
||
| const { connection, workspace, workspaceActions, active, pinned, archived } = | ||
| vi.hoisted(() => { | ||
| const makeSessions = () => ({ | ||
| sessions: [] as DaemonSessionSummary[], | ||
| loading: false, | ||
| error: null, | ||
| reload: vi.fn().mockResolvedValue(undefined), | ||
| deleteSession: vi.fn().mockResolvedValue(true), | ||
| archiveSession: vi.fn().mockResolvedValue(true), | ||
| unarchiveSession: vi.fn().mockResolvedValue(true), | ||
| exportSession: vi.fn(), | ||
| }); | ||
| return { | ||
| connection: { | ||
| status: 'connected', | ||
| sessionId: null as string | null, | ||
| workspaceCwd: '/tmp/project', | ||
| capabilities: undefined as | ||
| | { | ||
| qwenCodeVersion: string; | ||
| features: string[]; | ||
| } | ||
| | undefined, | ||
| }, | ||
| workspace: { | ||
| capabilities: undefined as | ||
| | { | ||
| qwenCodeVersion: string; | ||
| features: string[]; | ||
| } | ||
| | undefined, | ||
| client: { | ||
| workspaceByCwd: vi.fn(() => ({ | ||
| listWorkspaceSessions: vi.fn().mockResolvedValue([]), | ||
| listSessionGroups: vi.fn().mockResolvedValue({ | ||
| groups: [], | ||
| colorOptions: [ | ||
| 'red', | ||
| 'orange', | ||
| 'yellow', | ||
| 'green', | ||
| 'blue', | ||
| 'purple', | ||
| ], | ||
| }), | ||
| })), | ||
| }, | ||
| refreshCapabilities: vi.fn(), | ||
| }, | ||
| workspaceActions: { | ||
| addWorkspace: vi.fn(), | ||
| removeWorkspace: vi.fn(), | ||
| listSessionGroups: vi.fn().mockResolvedValue({ | ||
| groups: [], | ||
| colorOptions: ['red', 'orange', 'yellow', 'green', 'blue', 'purple'], | ||
| }), | ||
| createSessionGroup: vi.fn(), | ||
| updateSessionGroup: vi.fn(), | ||
| deleteSessionGroup: vi.fn(), | ||
| updateSessionOrganization: vi.fn(), | ||
| }, | ||
| active: makeSessions(), | ||
| pinned: makeSessions(), | ||
| archived: makeSessions(), | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock('@qwen-code/webui/daemon-react-sdk', () => ({ | ||
| useConnection: () => connection, | ||
| useActions: () => ({ renameSession: vi.fn() }), | ||
| useWorkspace: () => workspace, | ||
| useWorkspaceActions: () => workspaceActions, | ||
| useSessions: (options?: { archiveState?: string; group?: string }) => { | ||
| if (options?.archiveState === 'archived') return archived; | ||
| if (options?.group === 'pinned') return pinned; | ||
| return active; | ||
| }, | ||
| })); | ||
|
|
||
| const { I18nProvider } = await import('../../i18n'); | ||
| const { WebShellSidebar } = await import('./WebShellSidebar'); | ||
|
|
||
| globalThis.IS_REACT_ACT_ENVIRONMENT = true; | ||
| if (!globalThis.PointerEvent) { | ||
| globalThis.PointerEvent = MouseEvent as typeof PointerEvent; | ||
| } | ||
| if (!Element.prototype.hasPointerCapture) { | ||
| Element.prototype.hasPointerCapture = () => false; | ||
| } | ||
| if (!Element.prototype.setPointerCapture) { | ||
| Element.prototype.setPointerCapture = () => {}; | ||
| } | ||
| if (!Element.prototype.releasePointerCapture) { | ||
| Element.prototype.releasePointerCapture = () => {}; | ||
| } | ||
| if (!Element.prototype.scrollIntoView) { | ||
| Element.prototype.scrollIntoView = () => {}; | ||
| } | ||
|
|
||
| function makeSession( | ||
| sessionId: string, | ||
| over: Partial<DaemonSessionSummary> = {}, | ||
| ): DaemonSessionSummary { | ||
| return { | ||
| sessionId, | ||
| workspaceCwd: '/tmp/project', | ||
| displayName: `Session ${sessionId}`, | ||
| createdAt: '2026-01-01T00:00:00.000Z', | ||
| updatedAt: '2026-01-01T00:00:00.000Z', | ||
| clientCount: 0, | ||
| hasActivePrompt: false, | ||
| isArchived: false, | ||
| isPinned: false, | ||
| groupId: null, | ||
| color: null, | ||
| ...over, | ||
| } as DaemonSessionSummary; | ||
| } | ||
|
|
||
| const organizationCapabilities = { | ||
| qwenCodeVersion: '1.2.3', | ||
| features: ['session_organization'], | ||
| }; | ||
|
|
||
| const namedGroup = { | ||
| id: 'group-1', | ||
| name: 'Backend', | ||
| color: 'green' as const, | ||
| order: 0, | ||
| createdAt: '2026-07-04T00:00:00.000Z', | ||
| updatedAt: '2026-07-04T00:00:00.000Z', | ||
| }; | ||
|
|
||
| let root: Root; | ||
| let container: HTMLDivElement; | ||
|
|
||
| function renderSidebar() { | ||
| act(() => { | ||
| root.render( | ||
| <I18nProvider language="en"> | ||
| <WebShellSidebar | ||
| collapsed={false} | ||
| onCollapsedChange={() => {}} | ||
| onOpenSettings={() => {}} | ||
| onOpenDaemonStatus={() => {}} | ||
| onOpenScheduledTasks={() => {}} | ||
| onOpenSessions={() => {}} | ||
| onOpenSplitView={() => {}} | ||
| onNewSession={() => false} | ||
| onLoadSession={() => {}} | ||
| onError={() => {}} | ||
| /> | ||
| </I18nProvider>, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| async function flushSidebar() { | ||
| await act(async () => { | ||
| await Promise.resolve(); | ||
| await Promise.resolve(); | ||
| }); | ||
| } | ||
|
|
||
| function groupHeader(label: string): HTMLButtonElement { | ||
| const section = container.querySelector<HTMLElement>( | ||
| `section[aria-label="${label}"]`, | ||
| ); | ||
| expect(section).not.toBeNull(); | ||
| const header = section!.querySelector<HTMLButtonElement>( | ||
| 'button[aria-expanded]', | ||
| ); | ||
| expect(header).not.toBeNull(); | ||
| return header!; | ||
| } | ||
|
|
||
| function click(element: HTMLElement): void { | ||
| element.dispatchEvent(new MouseEvent('click', { bubbles: true })); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| window.localStorage.clear(); | ||
| container = document.createElement('div'); | ||
| document.body.appendChild(container); | ||
| root = createRoot(container); | ||
| connection.sessionId = null; | ||
| connection.workspaceCwd = '/tmp/project'; | ||
| connection.capabilities = organizationCapabilities; | ||
| workspace.capabilities = organizationCapabilities; | ||
| workspaceActions.listSessionGroups.mockReset(); | ||
| workspaceActions.listSessionGroups.mockResolvedValue({ | ||
| groups: [namedGroup], | ||
| colorOptions: ['red', 'orange', 'yellow', 'green', 'blue', 'purple'], | ||
| }); | ||
| active.sessions = [ | ||
| makeSession('session-a', { | ||
| displayName: 'API review', | ||
| groupId: 'group-1', | ||
| }), | ||
| makeSession('session-b', { | ||
| displayName: 'Release notes', | ||
| groupId: null, | ||
| }), | ||
| ]; | ||
| pinned.sessions = []; | ||
| archived.sessions = []; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| act(() => root.unmount()); | ||
| container.remove(); | ||
| window.localStorage.clear(); | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| describe('WebShellSidebar collapsed session group persistence', () => { | ||
| it('writes collapsed section ids with the qwen-code-web-shell-* key', async () => { | ||
| renderSidebar(); | ||
| await flushSidebar(); | ||
|
|
||
| const backend = container.querySelector<HTMLElement>( | ||
| 'section[aria-label="Backend"]', | ||
| ); | ||
| expect(backend?.textContent).toContain('API review'); | ||
| act(() => click(groupHeader('Backend'))); | ||
| await flushSidebar(); | ||
|
|
||
| expect(groupHeader('Backend').getAttribute('aria-expanded')).toBe('false'); | ||
| expect(backend?.textContent).not.toContain('API review'); | ||
| expect( | ||
| window.localStorage.getItem(COLLAPSED_SESSION_SECTIONS_STORAGE_KEY), | ||
| ).toBe(JSON.stringify(['group:group-1'])); | ||
| }); | ||
|
|
||
| it('keeps a collapsed named group collapsed across remount', async () => { | ||
| window.localStorage.setItem( | ||
| COLLAPSED_SESSION_SECTIONS_STORAGE_KEY, | ||
| JSON.stringify(['group:group-1']), | ||
| ); | ||
|
|
||
| renderSidebar(); | ||
| await flushSidebar(); | ||
|
|
||
| expect(groupHeader('Backend').getAttribute('aria-expanded')).toBe('false'); | ||
| const backend = container.querySelector<HTMLElement>( | ||
| 'section[aria-label="Backend"]', | ||
| ); | ||
| expect(backend?.textContent).not.toContain('API review'); | ||
| expect(container.textContent).toContain('Release notes'); | ||
| }); | ||
|
|
||
| it('keeps an expanded group expanded across remount after clearing collapse', async () => { | ||
| window.localStorage.setItem( | ||
| COLLAPSED_SESSION_SECTIONS_STORAGE_KEY, | ||
| JSON.stringify(['group:group-1']), | ||
| ); | ||
|
|
||
| renderSidebar(); | ||
| await flushSidebar(); | ||
| act(() => click(groupHeader('Backend'))); | ||
| await flushSidebar(); | ||
| expect(container.textContent).toContain('API review'); | ||
| expect( | ||
| window.localStorage.getItem(COLLAPSED_SESSION_SECTIONS_STORAGE_KEY), | ||
| ).toBe(JSON.stringify([])); | ||
|
|
||
| act(() => root.unmount()); | ||
| container.remove(); | ||
| container = document.createElement('div'); | ||
| document.body.appendChild(container); | ||
| root = createRoot(container); | ||
| renderSidebar(); | ||
| await flushSidebar(); | ||
|
|
||
| expect(groupHeader('Backend').getAttribute('aria-expanded')).toBe('true'); | ||
| expect(container.textContent).toContain('API review'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] Every persistence assertion covers only one named
group:*ID. Concrete failure scenario: a refactor that retains only the last toggled ID would keep all current unit and browser tests green, yet collapsing two groups would make the first reopen after reload;recentandcolor:*restoration are likewise untested. Add a remount case that preserves multiple IDs and at least one non-group section kind, including removal of one ID without losing the other.— Codex $qreview via Qwen Code /review