-
Notifications
You must be signed in to change notification settings - Fork 320
fix(web): lazy-load search code preview #1433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
| 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 }, | ||
| ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank preview while chunk loadsMedium Severity When the preview panel is opened, the resizable panel mounts immediately. However, because 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; | ||
|
|
@@ -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; | ||
|
|
||


There was a problem hiding this comment.
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:
Repository: sourcebot-dev/sourcebot
Length of output: 13635
Dynamically import
@/lib/codeHighlighthereThis 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