Skip to content

Commit 8a9b34e

Browse files
perf(web): highlighted search lines compile without manual memoization
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7111501 commit 8a9b34e

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

‎apps/web/reactCompiledFiles.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ export const REACT_COMPILED_FILES = [
9696
"apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx",
9797
"apps/web/src/components/ThreadTerminalDrawer.tsx",
9898
"apps/web/src/components/settings/SettingsPanels.tsx",
99+
"apps/web/src/components/search/HighlightedSearchLine.tsx",
99100
] as const;

‎apps/web/src/components/search/HighlightedSearchLine.tsx‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getFiletypeFromFileName } from "@pierre/diffs";
22
import type { ProjectContentMatch } from "@t3tools/contracts";
3-
import { memo, Suspense, use, useMemo, type CSSProperties } from "react";
3+
import { memo, Suspense, use, type CSSProperties } from "react";
44

55
import { resolveDiffThemeName } from "~/lib/diffRendering";
66
import { getSyntaxHighlighterPromise } from "~/lib/syntaxHighlighting";
@@ -125,23 +125,28 @@ function HighlightedTokens(props: {
125125
);
126126
}
127127

128+
function firstLineTokens(
129+
highlighter: Awaited<ReturnType<typeof getSyntaxHighlighterPromise>>,
130+
line: string,
131+
language: string,
132+
theme: "light" | "dark",
133+
) {
134+
try {
135+
return highlighter.codeToTokens(line, { lang: language, theme: resolveDiffThemeName(theme) })
136+
.tokens[0];
137+
} catch {
138+
return undefined;
139+
}
140+
}
141+
128142
function SyntaxHighlightedTokens(props: {
129143
readonly line: string;
130144
readonly language: string;
131145
readonly ranges: ReadonlyArray<Range>;
132146
readonly theme: "light" | "dark";
133147
}) {
134148
const highlighter = use(getSyntaxHighlighterPromise(props.language));
135-
const tokens = useMemo(() => {
136-
try {
137-
return highlighter.codeToTokens(props.line, {
138-
lang: props.language,
139-
theme: resolveDiffThemeName(props.theme),
140-
}).tokens[0];
141-
} catch {
142-
return undefined;
143-
}
144-
}, [highlighter, props.language, props.line, props.theme]);
149+
const tokens = firstLineTokens(highlighter, props.line, props.language, props.theme);
145150

146151
return tokens ? (
147152
<HighlightedTokens line={props.line} ranges={props.ranges} tokens={tokens} />
@@ -159,7 +164,7 @@ export const HighlightedSearchLine = memo(function HighlightedSearchLine(props:
159164
readonly path: string;
160165
readonly theme: "light" | "dark";
161166
}) {
162-
const ranges = useMemo(() => normalizeRanges(props.match), [props.match]);
167+
const ranges = normalizeRanges(props.match);
163168
const fallback = (
164169
<HighlightedTokens
165170
line={props.match.lineContent}

0 commit comments

Comments
 (0)