Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🧭 fix: Land on Chat History Instead of the Last Sidebar Panel (#17083)
Marco Berettab7d096f991e7
diff --git a/client/src/Providers/ActivePanelContext.tsx b/client/src/Providers/ActivePanelContext.tsxindex 9db0a3242c..36c4e6ae97 100644--- a/client/src/Providers/ActivePanelContext.tsx+++ b/client/src/Providers/ActivePanelContext.tsx@@ -1,12 +1,14 @@-import { createContext, useCallback, useContext, useMemo, useState, ReactNode } from 'react';+import { createContext, useContext, useEffect, useMemo, ReactNode } from 'react';+import { atom, useAtom } from 'jotai';-const STORAGE_KEY = 'side:active-panel';export const DEFAULT_PANEL = 'conversations';-function getInitialActivePanel(): string {- const saved = localStorage.getItem(STORAGE_KEY);- return saved ? saved : DEFAULT_PANEL;-}+/**+ * Held in memory for the life of the document rather than in Web Storage, so every entry+ * (a new visit, a reload, a tab opened from the app or duplicated) starts on chat history,+ * while the sidebar remounting its provider at the mobile breakpoint keeps the selection.+ */+export const activePanelAtom = atom<string>(DEFAULT_PANEL);interface ActivePanelContextType {active: string;@@ -16,12 +18,17 @@ interface ActivePanelContextType {const ActivePanelContext = createContext<ActivePanelContextType | undefined>(undefined);export function ActivePanelProvider({ children }: { children: ReactNode }) {- const [active, _setActive] = useState<string>(getInitialActivePanel);-- const setActive = useCallback((id: string) => {- localStorage.setItem(STORAGE_KEY, id);- _setActive(id);- }, []);+ const [active, setActive] = useAtom(activePanelAtom);++ useEffect(() => {+ const onPageShow = (event: PageTransitionEvent) => {+ if (event.persisted) {+ setActive(DEFAULT_PANEL);+ }+ };+ window.addEventListener('pageshow', onPageShow);+ return () => window.removeEventListener('pageshow', onPageShow);+ }, [setActive]);const value = useMemo(() => ({ active, setActive }), [active, setActive]);diff --git a/client/src/Providers/__tests__/ActivePanelContext.spec.tsx b/client/src/Providers/__tests__/ActivePanelContext.spec.tsxindex 0f2f89e8f7..a2e3a03019 100644--- a/client/src/Providers/__tests__/ActivePanelContext.spec.tsx+++ b/client/src/Providers/__tests__/ActivePanelContext.spec.tsx@@ -1,13 +1,16 @@import React from 'react';-import { render, fireEvent, screen } from '@testing-library/react';+import { getDefaultStore } from 'jotai';+import { act, render, fireEvent, screen } from '@testing-library/react';import '@testing-library/jest-dom/extend-expect';import {- ActivePanelProvider,- resolveActivePanel,+ DEFAULT_PANEL,+ activePanelAtom,useActivePanel,+ resolveActivePanel,+ ActivePanelProvider,} from '~/Providers/ActivePanelContext';-const STORAGE_KEY = 'side:active-panel';+const LEGACY_KEY = 'side:active-panel';function TestConsumer() {const { active, setActive } = useActivePanel();@@ -19,39 +22,64 @@ function TestConsumer() {);}+const dispatchPageShow = (persisted: boolean) =>+ act(() => {+ window.dispatchEvent(Object.assign(new Event('pageshow'), { persisted }));+ });+describe('ActivePanelContext', () => {beforeEach(() => {localStorage.clear();+ sessionStorage.clear();+ getDefaultStore().set(activePanelAtom, DEFAULT_PANEL);});- it('defaults to conversations when no localStorage value exists', () => {+ const renderProvider = () =>render(<ActivePanelProvider><TestConsumer /></ActivePanelProvider>,);++ it('lands a first visit on conversations', () => {+ renderProvider();expect(screen.getByTestId('active')).toHaveTextContent('conversations');});- it('reads initial value from localStorage', () => {- localStorage.setItem(STORAGE_KEY, 'memories');- render(- <ActivePanelProvider>- <TestConsumer />- </ActivePanelProvider>,- );- expect(screen.getByTestId('active')).toHaveTextContent('memories');+ it('ignores a panel persisted by an earlier version and leaves it for older tabs', () => {+ localStorage.setItem(LEGACY_KEY, 'skills');+ sessionStorage.setItem(LEGACY_KEY, 'skills');+ renderProvider();+ expect(screen.getByTestId('active')).toHaveTextContent('conversations');+ expect(localStorage.getItem(LEGACY_KEY)).toBe('skills');});- it('setActive updates state and writes to localStorage', () => {- render(- <ActivePanelProvider>- <TestConsumer />- </ActivePanelProvider>,- );+ it('keeps the chosen panel when the provider remounts in the same document', () => {+ const { unmount } = renderProvider();+ fireEvent.click(screen.getByTestId('switch-btn'));+ unmount();++ renderProvider();+ expect(screen.getByTestId('active')).toHaveTextContent('bookmarks');+ });++ it('returns to conversations when the page is restored from the back-forward cache', () => {+ renderProvider();+ fireEvent.click(screen.getByTestId('switch-btn'));++ dispatchPageShow(false);+ expect(screen.getByTestId('active')).toHaveTextContent('bookmarks');++ dispatchPageShow(true);+ expect(screen.getByTestId('active')).toHaveTextContent('conversations');+ });++ it('setActive updates state without writing to Web Storage', () => {+ renderProvider();fireEvent.click(screen.getByTestId('switch-btn'));expect(screen.getByTestId('active')).toHaveTextContent('bookmarks');- expect(localStorage.getItem(STORAGE_KEY)).toBe('bookmarks');+ expect(localStorage.getItem(LEGACY_KEY)).toBeNull();+ expect(sessionStorage.getItem(LEGACY_KEY)).toBeNull();});it('throws when useActivePanel is called outside provider', () => {diff --git a/client/src/components/UnifiedSidebar/__tests__/ExpandedPanel.spec.tsx b/client/src/components/UnifiedSidebar/__tests__/ExpandedPanel.spec.tsxindex 034c990083..b7f2158e4d 100644--- a/client/src/components/UnifiedSidebar/__tests__/ExpandedPanel.spec.tsx+++ b/client/src/components/UnifiedSidebar/__tests__/ExpandedPanel.spec.tsx@@ -1,12 +1,13 @@import React from 'react';import { RecoilRoot } from 'recoil';+import { getDefaultStore } from 'jotai';import '@testing-library/jest-dom/extend-expect';import { MemoryRouter } from 'react-router-dom';import { MessagesSquare, NotebookPen } from 'lucide-react';import { render, fireEvent, screen } from '@testing-library/react';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import type { NavLink } from '~/common';-import { ActivePanelProvider, DEFAULT_PANEL } from '~/Providers';+import { ActivePanelProvider, DEFAULT_PANEL, activePanelAtom } from '~/Providers';const mockNewConversation = jest.fn();const mockClearMessagesCache = jest.fn();@@ -114,9 +115,7 @@ function renderPanel({initialPanel?: string;switchToHistory?: boolean;} = {}) {- if (initialPanel !== DEFAULT_PANEL) {- localStorage.setItem('side:active-panel', initialPanel);- }+ getDefaultStore().set(activePanelAtom, initialPanel);const result = render(<MemoryRouter>@@ -159,7 +158,7 @@ describe('ExpandedPanel', () => {const inactiveButton = screen.getByRole('button', { name: 'com_ui_prompts' });fireEvent.click(inactiveButton);expect(onCollapse).not.toHaveBeenCalled();- expect(localStorage.getItem('side:active-panel')).toBe('prompts');+ expect(getDefaultStore().get(activePanelAtom)).toBe('prompts');});it('expands sidebar when clicking any icon while collapsed', () => {@@ -174,7 +173,7 @@ describe('ExpandedPanel', () => {const inactiveButton = screen.getByRole('button', { name: 'com_ui_prompts' });fireEvent.click(inactiveButton);expect(onExpand).toHaveBeenCalledTimes(1);- expect(localStorage.getItem('side:active-panel')).toBe('prompts');+ expect(getDefaultStore().get(activePanelAtom)).toBe('prompts');});it('notifies mobile navigation after a route link is selected', () => {@@ -234,7 +233,7 @@ describe('ExpandedPanel', () => {fireEvent.click(newChatLink);expect(mockNewConversation).toHaveBeenCalledTimes(1);- expect(localStorage.getItem('side:active-panel')).toBe(DEFAULT_PANEL);+ expect(getDefaultStore().get(activePanelAtom)).toBe(DEFAULT_PANEL);});it('does not switch panel on new chat click when setting is disabled', () => {@@ -248,7 +247,7 @@ describe('ExpandedPanel', () => {fireEvent.click(newChatLink);expect(mockNewConversation).toHaveBeenCalledTimes(1);- expect(localStorage.getItem('side:active-panel')).toBe('prompts');+ expect(getDefaultStore().get(activePanelAtom)).toBe('prompts');});});});diff --git a/client/src/components/UnifiedSidebar/mobile/__tests__/ShortcutTargets.spec.tsx b/client/src/components/UnifiedSidebar/mobile/__tests__/ShortcutTargets.spec.tsxindex cf43700a2d..d3729d3530 100644--- a/client/src/components/UnifiedSidebar/mobile/__tests__/ShortcutTargets.spec.tsx+++ b/client/src/components/UnifiedSidebar/mobile/__tests__/ShortcutTargets.spec.tsx@@ -1,7 +1,12 @@+import { getDefaultStore } from 'jotai';import { render, screen, fireEvent } from '@testing-library/react';import { BarChart3, MessagesSquare, NotebookPen } from 'lucide-react';import type { NavLink } from '~/common';-import { ActivePanelProvider } from '~/Providers/ActivePanelContext';+import {+ DEFAULT_PANEL,+ activePanelAtom,+ ActivePanelProvider,+} from '~/Providers/ActivePanelContext';import ShortcutTargets from '../ShortcutTargets';const links = [@@ -29,7 +34,7 @@ const renderTargets = ({);describe('ShortcutTargets', () => {- beforeEach(() => localStorage.clear());+ beforeEach(() => getDefaultStore().set(activePanelAtom, DEFAULT_PANEL));/*** `useKeyboardShortcuts` locates panels by these ids, reads `aria-pressed`,@@ -56,7 +61,7 @@ describe('ShortcutTargets', () => {fireEvent.click(screen.getByTestId('nav-panel-prompts'));expect(screen.getByTestId('nav-panel-prompts')).toHaveAttribute('aria-pressed', 'true');- expect(localStorage.getItem('side:active-panel')).toBe('prompts');+ expect(getDefaultStore().get(activePanelAtom)).toBe('prompts');});it('uses a route link callback without changing the active panel', () => {@@ -75,7 +80,7 @@ describe('ShortcutTargets', () => {fireEvent.click(screen.getByTestId('nav-panel-insights'));expect(onClick).toHaveBeenCalledTimes(1);- expect(localStorage.getItem('side:active-panel')).toBeNull();+ expect(getDefaultStore().get(activePanelAtom)).toBe(DEFAULT_PANEL);});it('leaves a route when a panel target is selected', () => {@@ -85,7 +90,7 @@ describe('ShortcutTargets', () => {fireEvent.click(screen.getByTestId('nav-panel-prompts'));expect(onLeaveInsights).toHaveBeenCalledTimes(1);- expect(localStorage.getItem('side:active-panel')).toBe('prompts');+ expect(getDefaultStore().get(activePanelAtom)).toBe('prompts');});it('offers no target for a panel this endpoint does not have', () => {diff --git a/e2e/specs/mock/scenarios/entry-panel.spec.ts b/e2e/specs/mock/scenarios/entry-panel.spec.tsnew file mode 100644index 0000000000..e69f237aab--- /dev/null+++ b/e2e/specs/mock/scenarios/entry-panel.spec.ts@@ -0,0 +1,114 @@+import { expect, test } from '@playwright/test';+import { NEW_CHAT_PATH } from '../helpers';++/**+ * Entering the app, by a new visit, a reload or a tab opened from it, lands on chat history+ * whatever panel was open before, while the sidebar crossing the mobile breakpoint keeps it.+ */++test.describe('sidebar panel on entry', () => {+ test.use({ viewport: { width: 1280, height: 800 } });++ test('a returning visit lands on chat history, not the last persisted panel @scenario:entry-lands-on-chat-history', async ({+ page,+ }) => {+ await page.addInitScript(() => {+ localStorage.setItem('unifiedSidebarExpanded', JSON.stringify(true));+ localStorage.setItem('side:active-panel', 'bookmarks');+ });+ await page.goto(NEW_CHAT_PATH, { timeout: 15000 });++ await expect(page).toHaveURL(/\/c\/new$/);+ await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({+ timeout: 30000,+ });+ await expect(page.getByTestId('nav-panel-conversations')).toHaveAttribute(+ 'aria-pressed',+ 'true',+ );+ await expect(page.getByTestId('nav-panel-bookmarks')).toHaveAttribute('aria-pressed', 'false');+ });++ test('a reload lands on chat history @scenario:entry-reload-lands-on-chat', async ({ page }) => {+ await page.addInitScript(() => {+ localStorage.setItem('unifiedSidebarExpanded', JSON.stringify(true));+ });+ await page.goto(NEW_CHAT_PATH, { timeout: 15000 });+ const bookmarks = page.getByTestId('nav-panel-bookmarks');+ await bookmarks.click();+ await expect(bookmarks).toHaveAttribute('aria-pressed', 'true');++ await page.reload();++ await expect(page.getByTestId('nav-panel-conversations')).toHaveAttribute(+ 'aria-pressed',+ 'true',+ );+ await expect(page.getByTestId('nav-panel-bookmarks')).toHaveAttribute('aria-pressed', 'false');+ });++ test('a tab opened from the app lands on chat history @scenario:entry-opened-tab-lands-on-chat', async ({+ page,+ }) => {+ await page.addInitScript(() => {+ localStorage.setItem('unifiedSidebarExpanded', JSON.stringify(true));+ });+ await page.goto(NEW_CHAT_PATH, { timeout: 15000 });+ const bookmarks = page.getByTestId('nav-panel-bookmarks');+ await bookmarks.click();+ await expect(bookmarks).toHaveAttribute('aria-pressed', 'true');++ const [opened] = await Promise.all([+ page.waitForEvent('popup'),+ page.evaluate((path) => {+ window.open(path, '_blank');+ }, NEW_CHAT_PATH),+ ]);++ await expect(opened.getByRole('textbox', { name: 'Message input' })).toBeVisible({+ timeout: 30000,+ });+ await expect(opened.getByTestId('nav-panel-conversations')).toHaveAttribute(+ 'aria-pressed',+ 'true',+ );+ await expect(opened.getByTestId('nav-panel-bookmarks')).toHaveAttribute(+ 'aria-pressed',+ 'false',+ );++ await opened.reload();++ await expect(opened.getByTestId('nav-panel-conversations')).toHaveAttribute(+ 'aria-pressed',+ 'true',+ );+ await expect(opened.getByTestId('nav-panel-bookmarks')).toHaveAttribute(+ 'aria-pressed',+ 'false',+ );+ });++ test('crossing the mobile breakpoint keeps the chosen panel @scenario:entry-resize-keeps-panel', async ({+ page,+ }) => {+ await page.addInitScript(() => {+ localStorage.setItem('unifiedSidebarExpanded', JSON.stringify(true));+ });+ await page.goto(NEW_CHAT_PATH, { timeout: 15000 });+ const bookmarks = page.getByTestId('nav-panel-bookmarks');+ await bookmarks.click();+ await expect(bookmarks).toHaveAttribute('aria-pressed', 'true');++ await page.setViewportSize({ width: 390, height: 800 });+ await expect(page.getByTestId('nav-panel-bookmarks')).toHaveCount(1);+ await expect(page.getByTestId('nav-panel-bookmarks')).toHaveAttribute('aria-pressed', 'true');+ await page.setViewportSize({ width: 1280, height: 800 });++ await expect(page.getByTestId('nav-panel-bookmarks')).toHaveAttribute('aria-pressed', 'true');+ await expect(page.getByTestId('nav-panel-conversations')).toHaveAttribute(+ 'aria-pressed',+ 'false',+ );+ });+});