Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Made the default home page configurable with `DEFAULT_HOME_VIEW_PAGE`, defaulting to Code Search and supporting Ask. [#1677](https://github.com/sourcebot-dev/sourcebot/pull/1677)
- Require authentication for the streaming and blocking Ask APIs in Public SaaS deployments. [#1679](https://github.com/sourcebot-dev/sourcebot/pull/1679)
- Fixed recently opened files appearing across different browse revisions. [#1686](https://github.com/sourcebot-dev/sourcebot/pull/1686)

## [5.1.14] - 2026-09-17

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { FileSearchCommandDialog } from './fileSearchCommandDialog';

const mocks = vi.hoisted(() => ({
params: { repoName: 'github.com/org/repo', revisionName: 'main' as string | undefined },
navigateToPath: vi.fn(),
updateBrowseState: vi.fn(),
}));

vi.mock('../hooks/useBrowseParams', () => ({ useBrowseParams: () => mocks.params }));
vi.mock('../hooks/useBrowseNavigation', () => ({
useBrowseNavigation: () => ({ navigateToPath: mocks.navigateToPath }),
}));
vi.mock('../hooks/useBrowseState', () => ({
useBrowseState: () => ({
state: { isFileSearchOpen: true },
updateBrowseState: mocks.updateBrowseState,
}),
}));
vi.mock('react-hotkeys-hook', () => ({ useHotkeys: vi.fn() }));
vi.mock('@tanstack/react-query', () => ({
useQuery: () => ({
data: [
{ type: 'blob', name: 'main.ts', path: 'src/main.ts' },
{ type: 'blob', name: 'feature.ts', path: 'src/feature.ts' },
],
isLoading: false,
isError: false,
}),
}));
vi.mock('@/app/api/(client)/client', () => ({ getFiles: vi.fn() }));
vi.mock('@/app/(app)/browse/components/fileTreeItemIcon', () => ({ FileTreeItemIcon: () => null }));

beforeEach(() => {
localStorage.clear();
vi.clearAllMocks();
mocks.params = { repoName: 'github.com/org/repo', revisionName: 'main' };
vi.stubGlobal('ResizeObserver', class {
observe() {}
unobserve() {}
disconnect() {}
});
HTMLElement.prototype.scrollIntoView = vi.fn();
HTMLElement.prototype.scrollTo = vi.fn();
});

afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});

const selectFile = (name: string) => {
fireEvent.change(screen.getByRole('combobox'), { target: { value: name } });
fireEvent.click(screen.getByRole('option'));
fireEvent.change(screen.getByRole('combobox'), { target: { value: '' } });
};

describe('file search recents', () => {
it('keeps separate histories when switching revisions and restores them after remounting', () => {
const view = render(<FileSearchCommandDialog />);
selectFile('main.ts');
expect(mocks.navigateToPath).toHaveBeenLastCalledWith({
repoName: mocks.params.repoName,
revisionName: 'main',
path: 'src/main.ts',
pathType: 'blob',
});

mocks.params.revisionName = 'feature';
view.rerender(<FileSearchCommandDialog />);
expect(screen.queryByText('main.ts')).toBeNull();
selectFile('feature.ts');

mocks.params.revisionName = 'main';
view.rerender(<FileSearchCommandDialog />);
expect(screen.getByText('main.ts')).toBeTruthy();
expect(screen.queryByText('feature.ts')).toBeNull();

view.unmount();
mocks.params.revisionName = 'feature';
render(<FileSearchCommandDialog />);
expect(screen.getByText('feature.ts')).toBeTruthy();
expect(screen.queryByText('main.ts')).toBeNull();
});

it('shares history between the default revision and explicit HEAD', () => {
mocks.params.revisionName = undefined;
const view = render(<FileSearchCommandDialog />);
selectFile('main.ts');

mocks.params.revisionName = 'HEAD';
view.rerender(<FileSearchCommandDialog />);
expect(screen.getByText('main.ts')).toBeTruthy();
});

it('does not inherit legacy history whose revision is unknown', () => {
localStorage.setItem(`recentlyOpenedFiles-${mocks.params.repoName}`, JSON.stringify([
{ type: 'blob', name: 'old.ts', path: 'src/old.ts' },
]));

render(<FileSearchCommandDialog />);

expect(screen.queryByText('old.ts')).toBeNull();
});

it('keeps repository and revision pairs distinct even when names contain separators', () => {
mocks.params = { repoName: 'repo@branch', revisionName: 'feature' };
const view = render(<FileSearchCommandDialog />);
selectFile('main.ts');

mocks.params = { repoName: 'repo', revisionName: 'branch@feature' };
view.rerender(<FileSearchCommandDialog />);
expect(screen.queryByText('main.ts')).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const FileSearchCommandDialog = () => {
const [searchQuery, setSearchQuery] = useState('');
const { navigateToPath } = useBrowseNavigation();

const [recentlyOpened, setRecentlyOpened] = useLocalStorage<FileTreeItem[]>(`recentlyOpenedFiles-${repoName}`, []);
const [recentlyOpened, setRecentlyOpened] = useLocalStorage<FileTreeItem[]>(
`recentlyOpenedFiles-${JSON.stringify([repoName, revisionName ?? 'HEAD'])}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Scoping the key by revision closes the cross-revision case, but the "Recently opened" list is still rendered as a stored snapshot without validating any entry against the files that currently exist at that revision (recentlyOpened.map(...) runs with no cross-check against files). If the revision's content moved since the file was opened — a branch advanced and deleted/renamed the path — selecting the entry calls navigateToPath to a blob that no longer exists, which is the same end-user failure mode #1387 describes, just narrowed to the matching key. Filter recentlyOpened against the current files (or remove missing paths on read), e.g. recentlyOpened.filter(r => files.some(f => f.path === r.path)).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/web/src/app/(app)/browse/components/fileSearchCommandDialog.tsx, line 39:

<comment>Scoping the key by revision closes the cross-revision case, but the "Recently opened" list is still rendered as a stored snapshot without validating any entry against the files that currently exist at that revision (`recentlyOpened.map(...)` runs with no cross-check against `files`). If the revision's content moved since the file was opened — a branch advanced and deleted/renamed the path — selecting the entry calls `navigateToPath` to a blob that no longer exists, which is the same end-user failure mode #1387 describes, just narrowed to the matching key. Filter `recentlyOpened` against the current `files` (or remove missing paths on read), e.g. `recentlyOpened.filter(r => files.some(f => f.path === r.path))`.</comment>

<file context>
@@ -35,7 +35,10 @@ export const FileSearchCommandDialog = () => {
 
-    const [recentlyOpened, setRecentlyOpened] = useLocalStorage<FileTreeItem[]>(`recentlyOpenedFiles-${repoName}`, []);
+    const [recentlyOpened, setRecentlyOpened] = useLocalStorage<FileTreeItem[]>(
+        `recentlyOpenedFiles-${JSON.stringify([repoName, revisionName ?? 'HEAD'])}`,
+        [],
+    );
</file context>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Each distinct (repo, revision) pair — including every commit SHA the user browses at — permanently creates a new localStorage entry that is never evicted, and legacy recentlyOpenedFiles-<repo> keys are intentionally left in place too. Storage clutter grows without bound over time for active browsing. Consider capping the recents array length and pruning keys for revisions no longer reachable, e.g. store one entry per repo holding a Map/object of revision → files instead of one key per revision.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/web/src/app/(app)/browse/components/fileSearchCommandDialog.tsx, line 39:

<comment>Each distinct (repo, revision) pair — including every commit SHA the user browses at — permanently creates a new localStorage entry that is never evicted, and legacy `recentlyOpenedFiles-<repo>` keys are intentionally left in place too. Storage clutter grows without bound over time for active browsing. Consider capping the recents array length and pruning keys for revisions no longer reachable, e.g. store one entry per repo holding a `Map`/object of revision → files instead of one key per revision.</comment>

<file context>
@@ -35,7 +35,10 @@ export const FileSearchCommandDialog = () => {
 
-    const [recentlyOpened, setRecentlyOpened] = useLocalStorage<FileTreeItem[]>(`recentlyOpenedFiles-${repoName}`, []);
+    const [recentlyOpened, setRecentlyOpened] = useLocalStorage<FileTreeItem[]>(
+        `recentlyOpenedFiles-${JSON.stringify([repoName, revisionName ?? 'HEAD'])}`,
+        [],
+    );
</file context>

[],
);

useHotkeys("mod+p", (event) => {
event.preventDefault();
Expand Down Expand Up @@ -265,4 +268,4 @@ const ResultsSkeleton = () => {
))}
</div>
);
};
};