Skip to content
Merged
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 @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed the web process being capped at a ~4GiB heap regardless of how much memory the container has, which caused multi-second garbage collection pauses on larger deployments. [#1569](https://github.com/sourcebot-dev/sourcebot/pull/1569)
- Upgraded `@sentry/*` to `^10.70.0`, fixing memory leaks where spans retained request data indefinitely. [#1572](https://github.com/sourcebot-dev/sourcebot/pull/1572)
- Fixed code search result links occasionally getting stuck during navigation and restored Cmd/Ctrl-click to open matches in preview. [#1574](https://github.com/sourcebot-dev/sourcebot/pull/1574)

## [5.1.6] - 2026-08-10

Expand Down
4 changes: 4 additions & 0 deletions packages/web/src/app/(app)/components/pathHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export const PathHeader = ({

<Link
className={cn("font-medium cursor-pointer hover:underline", repoNameClassName)}
prefetch={false}
href={getBrowsePath({
repoName: repo.name,
path: '/',
Expand All @@ -249,6 +250,7 @@ export const PathHeader = ({
>
<span className="mr-0.5">@</span>
<Link
prefetch={false}
href={getBrowsePath({
repoName: repo.name,
path: '',
Expand Down Expand Up @@ -286,6 +288,7 @@ export const PathHeader = ({
<DropdownMenuContent align="start" className="min-w-[200px]">
{hiddenSegments.map((segment) => (
<Link
prefetch={false}
href={getBrowsePath({
repoName: repo.name,
path: segment.fullPath,
Expand Down Expand Up @@ -317,6 +320,7 @@ export const PathHeader = ({
<VscodeFileIcon fileName={segment.name} className="h-4 w-4 mr-1 flex-shrink-0" />
)}
<Link
prefetch={false}
className={cn(
"font-mono text-sm min-w-0 truncate cursor-pointer hover:underline",
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { cleanup, createEvent, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { FileMatch } from './fileMatch';

vi.mock('next/link', () => ({
default: ({ children, href, prefetch, ...props }: React.AnchorHTMLAttributes<HTMLAnchorElement> & { prefetch?: boolean }) => (
<a {...props} href="#test-target" data-href={href} data-prefetch={String(prefetch)}>
{children}
</a>
),
}));

vi.mock('@/app/(app)/components/lightweightCodeHighlighter', () => ({
LightweightCodeHighlighter: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));

const file = {
fileName: {
text: 'src/index.ts',
matchRanges: [],
},
webUrl: '',
repository: 'github.com/sourcebot-dev/sourcebot',
repositoryId: 1,
language: 'TypeScript',
branches: ['main'],
chunks: [],
};

const match = {
content: 'const result = true;',
contentStart: {
byteOffset: 0,
lineNumber: 10,
column: 1,
},
matchRanges: [{
start: {
byteOffset: 6,
lineNumber: 10,
column: 7,
},
end: {
byteOffset: 12,
lineNumber: 10,
column: 13,
},
}],
};

afterEach(() => {
cleanup();
});

describe('FileMatch', () => {
it('disables prefetching and preserves ordinary link clicks', () => {
const onOpenPreview = vi.fn();
render(<FileMatch file={file} match={match} onOpenPreview={onOpenPreview} />);

const link = screen.getByRole('link');
expect(link.getAttribute('data-prefetch')).toBe('false');

fireEvent.click(link);
expect(onOpenPreview).not.toHaveBeenCalled();
});

it.each([
['Cmd', { metaKey: true }],
['Ctrl', { ctrlKey: true }],
])('opens the preview and cancels navigation for %s-click', (_modifier, eventInit) => {
const onOpenPreview = vi.fn();
render(<FileMatch file={file} match={match} onOpenPreview={onOpenPreview} />);

const link = screen.getByRole('link');
const clickEvent = createEvent.click(link, eventInit);
fireEvent(link, clickEvent);

expect(clickEvent.defaultPrevented).toBe(true);
expect(onOpenPreview).toHaveBeenCalledOnce();
});

it('supports modifier-plus-Enter for keyboard users', () => {
const onOpenPreview = vi.fn();
render(<FileMatch file={file} match={match} onOpenPreview={onOpenPreview} />);

const link = screen.getByRole('link');
const keyDownEvent = createEvent.keyDown(link, { key: 'Enter', metaKey: true });
fireEvent(link, keyDownEvent);

expect(keyDownEvent.defaultPrevented).toBe(true);
expect(onOpenPreview).toHaveBeenCalledOnce();
});
Comment thread
brendan-kellam marked this conversation as resolved.
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { getBrowsePath } from "@/app/(app)/browse/hooks/utils";
interface FileMatchProps {
match: SearchResultChunk;
file: SearchResultFile;
onOpenPreview: () => void;
}

export const FileMatch = ({
match,
file,
onOpenPreview,
}: FileMatchProps) => {
// If it's just the title, don't show a code preview
if (match.matchRanges.length === 0) {
Expand All @@ -24,6 +26,7 @@ export const FileMatch = ({
<Link
tabIndex={0}
className="cursor-pointer focus:ring-inset focus:ring-4 bg-background hover:bg-editor-lineHighlight"
prefetch={false}
href={getBrowsePath({
repoName: file.repository,
revisionName: file.branches?.[0] ?? 'HEAD',
Expand All @@ -38,6 +41,22 @@ export const FileMatch = ({
}
}
})}
onClick={(event) => {
if (!event.metaKey && !event.ctrlKey) {
return;
}

event.preventDefault();
onOpenPreview();
}}
onKeyDown={(event) => {
if (event.key !== 'Enter' || (!event.metaKey && !event.ctrlKey)) {
return;
}

event.preventDefault();
onOpenPreview();
}}
title="open file: click, open file preview: cmd/ctrl + click"
>
<LightweightCodeHighlighter
Expand All @@ -51,4 +70,4 @@ export const FileMatch = ({
</LightweightCodeHighlighter>
</Link>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export const FileMatchContainer = ({
<FileMatch
match={match}
file={file}
onOpenPreview={() => {
const matchIndex = matches.slice(0, index).reduce((acc, previousMatch) => {
return acc + previousMatch.matchRanges.length;
}, 0);
onOpenFilePreview(matchIndex);
}}
/>
{(index !== matches.length - 1 || isMoreContentButtonVisible) && (
<Separator className="bg-accent" />
Expand Down Expand Up @@ -153,4 +159,4 @@ export const FileMatchContainer = ({
)}
</div>
);
}
}
Loading