Skip to content

Commit 25ecb02

Browse files
fix(web): lazy-load search code preview
1 parent d9d252b commit 25ecb02

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

packages/web/src/app/(app)/search/components/searchResultsPage.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,42 @@ import { RepositoryInfo, SearchResultFile, SearchStats } from "@/features/search
1515
import useCaptureEvent from "@/hooks/useCaptureEvent";
1616
import { useNonEmptyQueryParam } from "@/hooks/useNonEmptyQueryParam";
1717
import { useSearchHistory } from "@/hooks/useSearchHistory";
18+
import { getCodeParserByLanguageName } from "@/lib/codeHighlight";
1819
import { ServiceErrorException } from "@/lib/serviceError";
1920
import { SearchQueryParams } from "@/lib/types";
2021
import { createPathWithQueryParams } from "@/lib/utils";
2122
import { InfoCircledIcon } from "@radix-ui/react-icons";
2223
import { useLocalStorage } from "@uidotdev/usehooks";
2324
import { AlertTriangleIcon, BugIcon, FilterIcon, RefreshCwIcon } from "lucide-react";
24-
import { Session } from "next-auth";
25+
import dynamic from "next/dynamic";
2526
import { useRouter } from "next/navigation";
2627
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2728
import { useHotkeys } from "react-hotkeys-hook";
2829
import { ImperativePanelHandle } from "react-resizable-panels";
2930
import { CopyIconButton } from "../../components/copyIconButton";
3031
import { SearchBar } from "../../components/searchBar";
3132
import { useStreamedSearch } from "../useStreamedSearch";
32-
import { CodePreviewPanel } from "./codePreviewPanel";
3333
import { FilterPanel } from "./filterPanel";
3434
import { useFilteredMatches } from "./filterPanel/useFilterMatches";
3535
import { SearchResultsPanel, SearchResultsPanelHandle } from "./searchResultsPanel";
3636

37+
const CodePreviewPanel = dynamic(
38+
() => import("./codePreviewPanel").then(module => ({ default: module.CodePreviewPanel })),
39+
{ ssr: false },
40+
);
41+
42+
const commonSearchResultLanguages = [
43+
"TypeScript",
44+
"JavaScript",
45+
"Python",
46+
"Go",
47+
"Rust",
48+
"Java",
49+
"C++",
50+
"C#",
51+
"JSON",
52+
];
53+
3754
interface SearchResultsPageProps {
3855
searchQuery: string;
3956
defaultMaxMatchCount: number;
@@ -54,6 +71,12 @@ export const SearchResultsPage = ({
5471
const { toast } = useToast();
5572
const captureEvent = useCaptureEvent();
5673

74+
useEffect(() => {
75+
void Promise.allSettled(
76+
commonSearchResultLanguages.map(getCodeParserByLanguageName),
77+
);
78+
}, []);
79+
5780
// Encodes the number of matches to return in the search response.
5881
const _maxMatchCount = parseInt(useNonEmptyQueryParam(SearchQueryParams.matches) ?? `${defaultMaxMatchCount}`);
5982
const maxMatchCount = isNaN(_maxMatchCount) ? defaultMaxMatchCount : _maxMatchCount;

0 commit comments

Comments
 (0)