Skip to content

Commit d8acfae

Browse files
fix(web): move chat storage keys to constants and clear search scope on thread creation (#1033)
* refactor(web): move chat storage keys to constants and clear search scope on thread creation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: update CHANGELOG for #1033 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * changelog --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 783acaa commit d8acfae

File tree

6 files changed

+16
-5
lines changed

6 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- Fixed reference panel overflow issue in the ask UI. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014)
2727
- Fixed homepage scrolling issue in the ask UI. [#1014](https://github.com/sourcebot-dev/sourcebot/pull/1014)
2828
- 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)
29+
- Fixed issue where the search scope selection persisted after a new thread is created. [#1033](https://github.com/sourcebot-dev/sourcebot/pull/1033)
2930

3031
## [4.15.11] - 2026-03-20
3132

packages/web/src/app/[domain]/chat/[id]/components/chatThreadPanel.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import { ResizablePanel } from '@/components/ui/resizable';
44
import { ChatThread } from '@/features/chat/components/chatThread';
5-
import { LanguageModelInfo, SBChatMessage, SearchScope, SET_CHAT_STATE_SESSION_STORAGE_KEY, SetChatStatePayload } from '@/features/chat/types';
5+
import { LanguageModelInfo, SBChatMessage, SearchScope, SetChatStatePayload } from '@/features/chat/types';
6+
import { SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY, SET_CHAT_STATE_SESSION_STORAGE_KEY } from '@/features/chat/constants';
67
import { RepositoryQuery, SearchContextQuery } from '@/lib/types';
78
import { CreateUIMessage } from 'ai';
89
import { useEffect, useState } from 'react';
@@ -35,6 +36,12 @@ export const ChatThreadPanel = ({
3536
const chatId = useChatId()!;
3637
const [inputMessage, setInputMessage] = useState<CreateUIMessage<SBChatMessage> | undefined>(undefined);
3738
const [chatState, setChatState] = useSessionStorage<SetChatStatePayload | null>(SET_CHAT_STATE_SESSION_STORAGE_KEY, null);
39+
40+
// Clear the landing page's persisted search scope selection so that returning
41+
// to the landing page to start a new thread starts with a clean state.
42+
useEffect(() => {
43+
localStorage.removeItem(SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY);
44+
}, []);
3845

3946
// Use the last user's last message to determine what repos and contexts we should select by default.
4047
const lastUserMessage = messages.findLast((message) => message.role === "user");

packages/web/src/app/[domain]/chat/components/landingPageChatBox.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useCreateNewChatThread } from "@/features/chat/useCreateNewChatThread";
88
import { RepositoryQuery, SearchContextQuery } from "@/lib/types";
99
import { useState } from "react";
1010
import { useLocalStorage } from "usehooks-ts";
11+
import { SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY } from "@/features/chat/constants";
1112
import { SearchModeSelector } from "../../components/searchModeSelector";
1213
import { NotConfiguredErrorBanner } from "@/features/chat/components/notConfiguredErrorBanner";
1314
import { LoginModal } from "@/app/components/loginModal";
@@ -26,7 +27,7 @@ export const LandingPageChatBox = ({
2627
isAuthenticated,
2728
}: LandingPageChatBox) => {
2829
const { createNewChatThread, isLoading, loginWall } = useCreateNewChatThread({ isAuthenticated });
29-
const [selectedSearchScopes, setSelectedSearchScopes] = useLocalStorage<SearchScope[]>("selectedSearchScopes", [], { initializeWithValue: false });
30+
const [selectedSearchScopes, setSelectedSearchScopes] = useLocalStorage<SearchScope[]>(SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY, [], { initializeWithValue: false });
3031
const [isContextSelectorOpen, setIsContextSelectorOpen] = useState(false);
3132
const isChatBoxDisabled = languageModels.length === 0;
3233

packages/web/src/features/chat/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ export const FILE_REFERENCE_REGEX = new RegExp(
66
);
77

88
export const ANSWER_TAG = '<!--answer-->';
9+
10+
export const SELECTED_SEARCH_SCOPES_LOCAL_STORAGE_KEY = 'selectedSearchScopes';
11+
export const SET_CHAT_STATE_SESSION_STORAGE_KEY = 'setChatState';

packages/web/src/features/chat/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ declare module 'slate' {
140140
/////////////////////////
141141

142142
// Misc //
143-
export const SET_CHAT_STATE_SESSION_STORAGE_KEY = 'setChatState';
144-
145143
export type SetChatStatePayload = {
146144
inputMessage: CreateUIMessage<SBChatMessage>;
147145
selectedSearchScopes: SearchScope[];

packages/web/src/features/chat/useCreateNewChatThread.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { useRouter } from "next/navigation";
99
import { createChat, getAskGhLoginWallData } from "./actions";
1010
import { isServiceError } from "@/lib/utils";
1111
import { createPathWithQueryParams } from "@/lib/utils";
12-
import { SearchScope, SET_CHAT_STATE_SESSION_STORAGE_KEY, SetChatStatePayload } from "./types";
12+
import { SearchScope, SetChatStatePayload } from "./types";
13+
import { SET_CHAT_STATE_SESSION_STORAGE_KEY } from "./constants";
1314
import { useSessionStorage } from "usehooks-ts";
1415
import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants";
1516
import type { IdentityProviderMetadata } from "@/lib/identityProviders";

0 commit comments

Comments
 (0)