Conversation
Co-authored-by: Chris Bell <chris@cjbell.co>
|
Cursor Agent can help with this pull request. Just |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| const openSidebar = useCallback(() => { | ||
| createNewSession(); | ||
| setIsOpen(true); | ||
| }, [createNewSession]); |
There was a problem hiding this comment.
openSidebar creates new session even when already open
Medium Severity
openSidebar unconditionally calls createNewSession() every time it's invoked, even if the sidebar is already open. This differs from toggleSidebar, which correctly guards with if (!prev) to only create a session when transitioning from closed to open. If openSidebar is called while the user is mid-conversation, it silently discards their current chat and replaces it with an empty session. The previous implementation was idempotent (setIsOpen(true) was a no-op when already open), and this change breaks that contract.
| } | ||
| return !prev; | ||
| }); | ||
| }, [createNewSession]); |
There was a problem hiding this comment.
Side effects inside React state updater function
Medium Severity
createNewSession() is called inside the setIsOpen state updater callback. React requires state updater functions to be pure. createNewSession() triggers multiple side effects (setChatSessions, setCurrentChatId, setMessages, etc.) and calls beforeSessionChangeRef.current?.(). In React Strict Mode (development), updater functions are invoked twice, which would create duplicate empty chat sessions each time the sidebar is toggled open.
| } else { | ||
| localStorage.removeItem(STORAGE_KEYS.currentChatId); | ||
| } | ||
| } |
There was a problem hiding this comment.
Dead code: localStorage write with no reader remaining
Low Severity
The diff removed the code that reads STORAGE_KEYS.currentChatId from localStorage on mount, but left behind the effect that writes it (lines 168–176) and the currentChatId key in STORAGE_KEYS. This effect now runs on every session change, writing to localStorage with no consumer ever reading the value back, making it dead code.


Description
This PR modifies the Ask AI sidebar to always default to a new chat session when opened, rather than resuming the most recently active one. This ensures users consistently start with a fresh conversation, improving clarity and user experience.
This is achieved by:
createNewSession()withinopenSidebarandtoggleSidebarwhen the sidebar transitions to an open state.Users can still access their previous chat history via the dropdown menu in the sidebar header.
Todos
Tasks
Screenshots