From dcda403667968a255e0325117d062b83e2691881 Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 23 Mar 2026 15:42:49 -0700 Subject: [PATCH 1/3] refactor(web): move chat storage keys to constants and clear search scope on thread creation Co-Authored-By: Claude Sonnet 4.6 --- .../[domain]/chat/[id]/components/chatThreadPanel.tsx | 9 ++++++++- .../app/[domain]/chat/components/landingPageChatBox.tsx | 3 ++- packages/web/src/features/chat/constants.ts | 3 +++ packages/web/src/features/chat/types.ts | 2 -- packages/web/src/features/chat/useCreateNewChatThread.ts | 3 ++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/web/src/app/[domain]/chat/[id]/components/chatThreadPanel.tsx b/packages/web/src/app/[domain]/chat/[id]/components/chatThreadPanel.tsx index 05db3a244..d801fc07d 100644 --- a/packages/web/src/app/[domain]/chat/[id]/components/chatThreadPanel.tsx +++ b/packages/web/src/app/[domain]/chat/[id]/components/chatThreadPanel.tsx @@ -2,7 +2,8 @@ import { ResizablePanel } from '@/components/ui/resizable'; import { ChatThread } from '@/features/chat/components/chatThread'; -import { LanguageModelInfo, SBChatMessage, SearchScope, SET_CHAT_STATE_SESSION_STORAGE_KEY, SetChatStatePayload } from '@/features/chat/types'; +import { LanguageModelInfo, SBChatMessage, SearchScope, SetChatStatePayload } from '@/features/chat/types'; +import { SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY, SET_CHAT_STATE_SESSION_STORAGE_KEY } from '@/features/chat/constants'; import { RepositoryQuery, SearchContextQuery } from '@/lib/types'; import { CreateUIMessage } from 'ai'; import { useEffect, useState } from 'react'; @@ -35,6 +36,12 @@ export const ChatThreadPanel = ({ const chatId = useChatId()!; const [inputMessage, setInputMessage] = useState | undefined>(undefined); const [chatState, setChatState] = useSessionStorage(SET_CHAT_STATE_SESSION_STORAGE_KEY, null); + + // Clear the landing page's persisted search scope selection so that returning + // to the landing page to start a new thread starts with a clean state. + useEffect(() => { + localStorage.removeItem(SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY); + }, []); // Use the last user's last message to determine what repos and contexts we should select by default. const lastUserMessage = messages.findLast((message) => message.role === "user"); diff --git a/packages/web/src/app/[domain]/chat/components/landingPageChatBox.tsx b/packages/web/src/app/[domain]/chat/components/landingPageChatBox.tsx index 8e43730ec..9d6b92381 100644 --- a/packages/web/src/app/[domain]/chat/components/landingPageChatBox.tsx +++ b/packages/web/src/app/[domain]/chat/components/landingPageChatBox.tsx @@ -8,6 +8,7 @@ import { useCreateNewChatThread } from "@/features/chat/useCreateNewChatThread"; import { RepositoryQuery, SearchContextQuery } from "@/lib/types"; import { useState } from "react"; import { useLocalStorage } from "usehooks-ts"; +import { SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY } from "@/features/chat/constants"; import { SearchModeSelector } from "../../components/searchModeSelector"; import { NotConfiguredErrorBanner } from "@/features/chat/components/notConfiguredErrorBanner"; import { LoginModal } from "@/app/components/loginModal"; @@ -26,7 +27,7 @@ export const LandingPageChatBox = ({ isAuthenticated, }: LandingPageChatBox) => { const { createNewChatThread, isLoading, loginWall } = useCreateNewChatThread({ isAuthenticated }); - const [selectedSearchScopes, setSelectedSearchScopes] = useLocalStorage("selectedSearchScopes", [], { initializeWithValue: false }); + const [selectedSearchScopes, setSelectedSearchScopes] = useLocalStorage(SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY, [], { initializeWithValue: false }); const [isContextSelectorOpen, setIsContextSelectorOpen] = useState(false); const isChatBoxDisabled = languageModels.length === 0; diff --git a/packages/web/src/features/chat/constants.ts b/packages/web/src/features/chat/constants.ts index b2e5de742..b84e9d922 100644 --- a/packages/web/src/features/chat/constants.ts +++ b/packages/web/src/features/chat/constants.ts @@ -6,3 +6,6 @@ export const FILE_REFERENCE_REGEX = new RegExp( ); export const ANSWER_TAG = ''; + +export const SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY = 'selectedSearchScopes'; +export const SET_CHAT_STATE_SESSION_STORAGE_KEY = 'setChatState'; diff --git a/packages/web/src/features/chat/types.ts b/packages/web/src/features/chat/types.ts index 04cb60777..6e990f5c2 100644 --- a/packages/web/src/features/chat/types.ts +++ b/packages/web/src/features/chat/types.ts @@ -140,8 +140,6 @@ declare module 'slate' { ///////////////////////// // Misc // -export const SET_CHAT_STATE_SESSION_STORAGE_KEY = 'setChatState'; - export type SetChatStatePayload = { inputMessage: CreateUIMessage; selectedSearchScopes: SearchScope[]; diff --git a/packages/web/src/features/chat/useCreateNewChatThread.ts b/packages/web/src/features/chat/useCreateNewChatThread.ts index 74d46f23b..e43f5063b 100644 --- a/packages/web/src/features/chat/useCreateNewChatThread.ts +++ b/packages/web/src/features/chat/useCreateNewChatThread.ts @@ -9,7 +9,8 @@ import { useRouter } from "next/navigation"; import { createChat, getAskGhLoginWallData } from "./actions"; import { isServiceError } from "@/lib/utils"; import { createPathWithQueryParams } from "@/lib/utils"; -import { SearchScope, SET_CHAT_STATE_SESSION_STORAGE_KEY, SetChatStatePayload } from "./types"; +import { SearchScope, SetChatStatePayload } from "./types"; +import { SET_CHAT_STATE_SESSION_STORAGE_KEY } from "./constants"; import { useSessionStorage } from "usehooks-ts"; import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants"; import type { IdentityProviderMetadata } from "@/lib/identityProviders"; From 595a1003addde01308be0971ad77212322cc9fcb Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 23 Mar 2026 15:43:20 -0700 Subject: [PATCH 2/3] chore: update CHANGELOG for #1033 Co-Authored-By: Claude Sonnet 4.6 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6020fb3b..7d2b86bae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed the ask search scope selector to allow submitting questions with no search scope selected. When no selection is made, the agent will be able to search over all repos the user has access to. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014) - Renamed the `search_code` tool to `grep` for ask and mcp. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014) - Improved auto-scroll behavior in the ask chat thread. [#1031](https://github.com/sourcebot-dev/sourcebot/pull/1031) +- Cleared the search scope selection on the ask landing page after a new thread is created. [#1033](https://github.com/sourcebot-dev/sourcebot/pull/1033) ### Added - Added `glob`, `find_symbol_definitions`, and `find_symbol_references` tools to the ask agent and MCP server. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014) From b9ecba1ad1f740f8476cbea506a4283d60914ae2 Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Mon, 23 Mar 2026 15:44:13 -0700 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d2b86bae..dab0d8aff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed the ask search scope selector to allow submitting questions with no search scope selected. When no selection is made, the agent will be able to search over all repos the user has access to. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014) - Renamed the `search_code` tool to `grep` for ask and mcp. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014) - Improved auto-scroll behavior in the ask chat thread. [#1031](https://github.com/sourcebot-dev/sourcebot/pull/1031) -- Cleared the search scope selection on the ask landing page after a new thread is created. [#1033](https://github.com/sourcebot-dev/sourcebot/pull/1033) ### Added - Added `glob`, `find_symbol_definitions`, and `find_symbol_references` tools to the ask agent and MCP server. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014) @@ -27,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed reference panel overflow issue in the ask UI. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014) - Fixed homepage scrolling issue in the ask UI. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014) - Fixed UI freeze when the `grep` tool returns a large number of results with `groupByRepo=true`. [#1032](https://github.com/sourcebot-dev/sourcebot/pull/1032) +- Fixed issue where the search scope selection persisted after a new thread is created. [#1033](https://github.com/sourcebot-dev/sourcebot/pull/1033) ## [4.15.11] - 2026-03-20