fix: preserve task navigation when compact layout closes chat

This commit is contained in:
bradgroux 2026-09-07 17:49:19 -05:00
parent b2abf44ccf
commit a65bfc6546
2 changed files with 36 additions and 1 deletions

View file

@ -153,6 +153,33 @@ describe('desktop shell recovery', () => {
expect(window.localStorage.getItem('veritas.desktop.rightRailOpen')).toBe('false');
});
it('keeps the task history and focus when resize collapses the chat behind it', async () => {
const user = userEvent.setup();
render(
<DesktopShellProvider>
<ShellProbe />
</DesktopShellProvider>
);
await user.click(screen.getByRole('button', { name: 'Open board chat' }));
const taskState = { ...window.history.state, veritasTaskDetail: 'task-open-above-chat' };
window.history.pushState(taskState, '', '/');
const taskControl = screen.getByRole('button', { name: 'Reset layout' });
taskControl.focus();
const back = vi.spyOn(window.history, 'back').mockImplementation(() => {});
try {
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1180 });
act(() => window.dispatchEvent(new Event('resize')));
expect(screen.getByLabelText('bottom panel').textContent).toBe('closed');
expect(window.history.state.veritasTaskDetail).toBe('task-open-above-chat');
expect(window.history.state.veritasBottomPanel).toBeUndefined();
expect(back).not.toHaveBeenCalled();
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
expect(document.activeElement).toBe(taskControl);
} finally {
back.mockRestore();
}
});
it('minimizes both sidebars before opening Workbench at compact width', async () => {
const user = userEvent.setup();
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1180 });

View file

@ -314,7 +314,15 @@ export function DesktopShellProvider({ children }: { children: ReactNode }) {
setRightRailOpenState(false);
writeStoredValue(LEFT_RAIL_STORAGE_KEY, 'false');
writeStoredValue(RIGHT_RAIL_STORAGE_KEY, 'false');
if (bottomPanel) closeBottomPanel();
if (bottomPanel) {
// A layout collapse is not navigation: a task opened above the dock
// inherits its history marker. Going Back would dismiss that task.
setBottomPanel(null);
removeStoredValue(BOTTOM_PANEL_STORAGE_KEY);
panelTriggerRef.current = null;
const { [BOTTOM_PANEL_HISTORY_STATE_KEY]: _panel, ...rest } = window.history.state ?? {};
window.history.replaceState(rest, '', window.location.href);
}
};
window.addEventListener('keydown', handleKeyDown, true);