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 @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Upgraded `nodemailer` to `^9.0.1`. [#1356](https://github.com/sourcebot-dev/sourcebot/pull/1356)
- Upgraded `@opentelemetry/core` to `^2.8.0`. [#1413](https://github.com/sourcebot-dev/sourcebot/pull/1413)
- [EE] Fixed connector setup dialogs to add scrolling when connector setup content goes out of view.
- Fixed file-search recents from one browse revision appearing when viewing another revision. [#1392](https://github.com/sourcebot-dev/sourcebot/pull/1392)

## [5.0.4] - 2026-06-18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { useLocalStorage } from "usehooks-ts";
import { Skeleton } from "@/components/ui/skeleton";
import { FileTreeItem } from "@/features/git";
import { getFiles } from "@/app/api/(client)/client";
import {
getLegacyRecentlyOpenedFilesStorageKey,
getRecentlyOpenedFilesStorageKey,
shouldMigrateLegacyRecentlyOpenedFiles,
} from "./fileSearchRecents";

const MAX_RESULTS = 100;

Expand All @@ -35,7 +40,32 @@ export const FileSearchCommandDialog = () => {
const [searchQuery, setSearchQuery] = useState('');
const { navigateToPath } = useBrowseNavigation();

const [recentlyOpened, setRecentlyOpened] = useLocalStorage<FileTreeItem[]>(`recentlyOpenedFiles-${repoName}`, []);
const [recentlyOpened, setRecentlyOpened] = useLocalStorage<FileTreeItem[]>(getRecentlyOpenedFilesStorageKey({
repoName,
revisionName,
}), []);

useEffect(() => {
if (!shouldMigrateLegacyRecentlyOpenedFiles({ revisionName }) || recentlyOpened.length > 0) {
return;
}

const legacyStorageKey = getLegacyRecentlyOpenedFilesStorageKey({ repoName });
const legacyValue = window.localStorage.getItem(legacyStorageKey);
if (!legacyValue) {
return;
}

try {
const parsed = JSON.parse(legacyValue);
if (Array.isArray(parsed) && parsed.length > 0) {
setRecentlyOpened(parsed as FileTreeItem[]);
window.localStorage.removeItem(legacyStorageKey);
}
} catch {
// Ignore malformed legacy localStorage entries.
}
}, [recentlyOpened.length, repoName, revisionName, setRecentlyOpened]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

useHotkeys("mod+p", (event) => {
event.preventDefault();
Expand Down Expand Up @@ -265,4 +295,4 @@ const ResultsSkeleton = () => {
))}
</div>
);
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { describe, expect, test } from 'vitest';
import {
getLegacyRecentlyOpenedFilesStorageKey,
getRecentlyOpenedFilesStorageKey,
shouldMigrateLegacyRecentlyOpenedFiles,
} from './fileSearchRecents';

describe('getRecentlyOpenedFilesStorageKey', () => {
test('scopes recently opened files by repo and revision', () => {
const mainKey = getRecentlyOpenedFilesStorageKey({
repoName: 'github.com/sourcebot-dev/sourcebot',
revisionName: 'main',
});
const featureKey = getRecentlyOpenedFilesStorageKey({
repoName: 'github.com/sourcebot-dev/sourcebot',
revisionName: 'feature/file-search',
});

expect(mainKey).not.toBe(featureKey);
});

test('uses HEAD when revision is omitted', () => {
expect(getRecentlyOpenedFilesStorageKey({
repoName: 'github.com/sourcebot-dev/sourcebot',
revisionName: undefined,
})).toBe('recentlyOpenedFiles:github.com%2Fsourcebot-dev%2Fsourcebot:HEAD');
});

test('encodes repo and revision delimiters before building the key', () => {
expect(getRecentlyOpenedFilesStorageKey({
repoName: 'example.com/org:repo@name',
revisionName: 'feature:one/two',
})).toBe('recentlyOpenedFiles:example.com%2Forg%3Arepo%40name:feature%3Aone%2Ftwo');
});

test('keeps the legacy repo-scoped key available for migration', () => {
expect(getLegacyRecentlyOpenedFilesStorageKey({
repoName: 'github.com/sourcebot-dev/sourcebot',
})).toBe('recentlyOpenedFiles-github.com/sourcebot-dev/sourcebot');
});

test('only migrates legacy recents into the default revision context', () => {
expect(shouldMigrateLegacyRecentlyOpenedFiles({ revisionName: undefined })).toBe(true);
expect(shouldMigrateLegacyRecentlyOpenedFiles({ revisionName: null })).toBe(true);
expect(shouldMigrateLegacyRecentlyOpenedFiles({ revisionName: 'HEAD' })).toBe(true);
expect(shouldMigrateLegacyRecentlyOpenedFiles({ revisionName: 'main' })).toBe(false);
expect(shouldMigrateLegacyRecentlyOpenedFiles({ revisionName: 'feature/file-search' })).toBe(false);
});
});
30 changes: 30 additions & 0 deletions packages/web/src/app/(app)/browse/components/fileSearchRecents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const defaultRevisionName = 'HEAD';

export const getLegacyRecentlyOpenedFilesStorageKey = ({
repoName,
}: {
repoName: string;
}) => {
return `recentlyOpenedFiles-${repoName}`;
}

export const getRecentlyOpenedFilesStorageKey = ({
repoName,
revisionName,
}: {
repoName: string;
revisionName?: string | null;
}) => {
const encodedRepoName = encodeURIComponent(repoName);
const encodedRevisionName = encodeURIComponent(revisionName ?? defaultRevisionName);

return `recentlyOpenedFiles:${encodedRepoName}:${encodedRevisionName}`;
}

export const shouldMigrateLegacyRecentlyOpenedFiles = ({
revisionName,
}: {
revisionName?: string | null;
}) => {
return revisionName === undefined || revisionName === null || revisionName === defaultRevisionName;
}