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 @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [EE] Fixed connector setup dialogs to add scrolling when connector setup content goes out of view.
- Fixed Gitea sync failing with `ERR_STREAM_PREMATURE_CLOSE` by forcing identity encoding on the Gitea API fetch and guarding against null repository responses. [#1405](https://github.com/sourcebot-dev/sourcebot/pull/1405)
- [EE] Fixed Ask connector MCP tools with provider-invalid names failing to run by sanitizing model-facing tool names while preserving raw names in the UI.
- Lazy-loaded the search result code preview and pre-warmed common language parsers to improve initial search page load performance. [#1433](https://github.com/sourcebot-dev/sourcebot/pull/1433)

## [5.0.4] - 2026-06-18

Expand Down
27 changes: 25 additions & 2 deletions packages/web/src/app/(app)/search/components/searchResultsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,42 @@ import { RepositoryInfo, SearchResultFile, SearchStats } from "@/features/search
import useCaptureEvent from "@/hooks/useCaptureEvent";
import { useNonEmptyQueryParam } from "@/hooks/useNonEmptyQueryParam";
import { useSearchHistory } from "@/hooks/useSearchHistory";
import { getCodeParserByLanguageName } from "@/lib/codeHighlight";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## searchResultsPage.tsx\n'
sed -n '1,220p' 'packages/web/src/app/(app)/search/components/searchResultsPage.tsx'

printf '\n## codeHighlight.ts\n'
sed -n '1,260p' 'packages/web/src/lib/codeHighlight.ts'

printf '\n## usages of getCodeParserByLanguageName\n'
rg -n "getCodeParserByLanguageName|codeHighlight" packages/web/src -g '!**/*.map'

Repository: sourcebot-dev/sourcebot

Length of output: 13635


Dynamically import @/lib/codeHighlight here

This client page statically pulls the CodeMirror parser helpers into the initial chunk. Load them inside the pre-warming effect instead so the parser bundle is fetched only when the search page mounts.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/web/src/app/`(app)/search/components/searchResultsPage.tsx at line
18, Replace the top-level getCodeParserByLanguageName import with a dynamic
import inside the search page’s pre-warming effect, and invoke the loaded helper
there so `@/lib/codeHighlight` and its CodeMirror parser dependencies are fetched
only when the page mounts.

import { ServiceErrorException } from "@/lib/serviceError";
import { SearchQueryParams } from "@/lib/types";
import { createPathWithQueryParams } from "@/lib/utils";
import { InfoCircledIcon } from "@radix-ui/react-icons";
import { useLocalStorage } from "@uidotdev/usehooks";
import { AlertTriangleIcon, BugIcon, FilterIcon, RefreshCwIcon } from "lucide-react";
import { Session } from "next-auth";
import dynamic from "next/dynamic";
import { useRouter } from "next/navigation";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useHotkeys } from "react-hotkeys-hook";
import { ImperativePanelHandle } from "react-resizable-panels";
import { CopyIconButton } from "../../components/copyIconButton";
import { SearchBar } from "../../components/searchBar";
import { useStreamedSearch } from "../useStreamedSearch";
import { CodePreviewPanel } from "./codePreviewPanel";
import { FilterPanel } from "./filterPanel";
import { useFilteredMatches } from "./filterPanel/useFilterMatches";
import { SearchResultsPanel, SearchResultsPanelHandle } from "./searchResultsPanel";

const CodePreviewPanel = dynamic(
() => import("./codePreviewPanel").then(module => ({ default: module.CodePreviewPanel })),
{ ssr: false },
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Blank preview while chunk loads

Medium Severity

When the preview panel is opened, the resizable panel mounts immediately. However, because CodePreviewPanel is dynamically loaded with ssr: false and lacks a loading fallback, users see an empty panel until the component's chunk finishes loading, which is noticeable on slower networks.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4a5c1a7. Configure here.


const commonSearchResultLanguages = [
"TypeScript",
"JavaScript",
"Python",
"Go",
"Rust",
"Java",
"C++",
"C#",
"JSON",
];

interface SearchResultsPageProps {
searchQuery: string;
defaultMaxMatchCount: number;
Expand All @@ -54,6 +71,12 @@ export const SearchResultsPage = ({
const { toast } = useToast();
const captureEvent = useCaptureEvent();

useEffect(() => {
void Promise.allSettled(
commonSearchResultLanguages.map(getCodeParserByLanguageName),
);
}, []);

// Encodes the number of matches to return in the search response.
const _maxMatchCount = parseInt(useNonEmptyQueryParam(SearchQueryParams.matches) ?? `${defaultMaxMatchCount}`);
const maxMatchCount = isNaN(_maxMatchCount) ? defaultMaxMatchCount : _maxMatchCount;
Expand Down
Loading