The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 06:45 UTC
perf(web): highlighted search lines compile without manual memoization (#20571)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 22:05 UTC
242ec0ea2b89a1d5f28a5baa8bf5f89fe9835cbf
1 file changed
+17
-12
apps/web/src/components/search/HighlightedSearchLine.tsx
+17
-12
@@ -1,6 +1,6 @@
1
import { getFiletypeFromFileName } from "@pierre/diffs";
2
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";
4
5
import { resolveDiffThemeName } from "~/lib/diffRendering";
6
import { getSyntaxHighlighterPromise } from "~/lib/syntaxHighlighting";
@@ -125,6 +125,20 @@ function HighlightedTokens(props: {
125
);
126
}
127
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
+
142
function SyntaxHighlightedTokens(props: {
143
readonly line: string;
144
readonly language: string;
@@ -132,16 +146,7 @@ function SyntaxHighlightedTokens(props: {
146
readonly theme: "light" | "dark";
147
}) {
148
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);
150
151
return tokens ? (
152
<HighlightedTokens line={props.line} ranges={props.ranges} tokens={tokens} />
@@ -159,7 +164,7 @@ export const HighlightedSearchLine = memo(function HighlightedSearchLine(props:
164
readonly path: string;
165
readonly theme: "light" | "dark";
166
}) {
162
- const ranges = useMemo(() => normalizeRanges(props.match), [props.match]);
167
+ const ranges = normalizeRanges(props.match);
168
const fallback = (
169
<HighlightedTokens
170
line={props.match.lineContent}