The best way to control Claude Code, Codex and more from any computer or phone
perf(web): project content search compiles with the React Compiler (#20641)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 21:58 UTC
f22415a075ca3ac24ab0c853f39126678a1bdb66
2 files changed
+28
-26
apps/web/src/components/search/ProjectContentSearchDialog.test.tsx
+12
-12
@@ -10,6 +10,17 @@ const state = vi.hoisted(() => ({
10
error: null as string | null,
11
readScope: vi.fn(),
12
openFile: vi.fn(),
13
+ // The real query hands back the same result array until the search changes.
14
+ matches: [
15
+ {
16
+ resultIndex: 0,
17
+ path: "src/index.ts",
18
+ lineNumber: 3,
19
+ lineContent: "match",
20
+ matchRanges: [],
21
+ },
22
+ ],
23
+ noMatches: [],
24
}));
25
26
const target = {
@@ -37,18 +48,7 @@ vi.mock("~/state/queries", () => ({
48
hasQuery: query.length > 0,
49
truncated: false,
50
invalidRegex: false,
40
- matches:
41
- state.canReadFiles && query.length > 0
42
- ? [
43
- {
44
- resultIndex: 0,
45
- path: "src/index.ts",
46
- lineNumber: 3,
47
- lineContent: "match",
48
- matchRanges: [],
49
- },
50
- ]
51
- : [],
51
+ matches: state.canReadFiles && query.length > 0 ? state.matches : state.noMatches,
52
}),
53
}));
54
vi.mock("../CommandPaletteContent", () => ({ CommandPaletteContent: "section" }));
apps/web/src/components/search/ProjectContentSearchDialog.tsx
+16
-14
@@ -1,7 +1,7 @@
1
import { Spinner } from "~/components/ui/spinner";
2
import { AuthFilesystemReadScope, type ProjectContentMatch } from "@t3tools/contracts";
3
4
-import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react";
4
+import { useEffect, useState, type ReactNode } from "react";
5
6
import { useActiveProjectTarget, type ActiveProjectTarget } from "~/hooks/useActiveProjectTarget";
7
import { useTheme } from "~/hooks/useTheme";
@@ -124,25 +124,27 @@ function OpenContentSearchDialog(props: {
124
});
125
const canOpenMatches = search.canReadFiles && !search.isPending && search.error === null;
126
const matches = search.matches;
127
- const visibleMatches = useMemo(() => matches.slice(0, visibleCount), [matches, visibleCount]);
128
- const groups = useMemo(() => groupMatches(visibleMatches), [visibleMatches]);
129
-
130
- useEffect(() => {
127
+ // New results restart the selection and the rendered window.
128
+ const [resultsFor, setResultsFor] = useState(matches);
129
+ if (resultsFor !== matches) {
130
+ setResultsFor(matches);
131
setSelectedIndex(0);
132
setVisibleCount(VISIBLE_MATCH_WINDOW);
133
- }, [matches]);
133
+ }
134
+ // Keyboard selection past the window grows it before the row has to scroll into view.
135
+ if (selectedIndex >= visibleCount) {
136
+ setVisibleCount(selectedIndex + VISIBLE_MATCH_WINDOW);
137
+ }
138
+ const visibleMatches = matches.slice(0, visibleCount);
139
+ const groups = groupMatches(visibleMatches);
140
141
useEffect(() => {
136
- if (selectedIndex >= visibleCount) {
137
- setVisibleCount(selectedIndex + VISIBLE_MATCH_WINDOW);
138
- return;
139
- }
142
document
143
.querySelector<HTMLElement>(`[data-content-search-result="${selectedIndex}"]`)
144
?.scrollIntoView({ block: "nearest" });
143
- }, [selectedIndex, visibleCount]);
145
+ }, [selectedIndex]);
146
145
- const observeLoadMoreSentinel = useCallback((sentinel: HTMLElement | null) => {
147
+ const observeLoadMoreSentinel = (sentinel: HTMLElement | null) => {
148
if (!sentinel) return;
149
const observer = new IntersectionObserver((entries) => {
150
if (entries.some((entry) => entry.isIntersecting)) {
@@ -151,7 +153,7 @@ function OpenContentSearchDialog(props: {
153
});
154
observer.observe(sentinel);
155
return () => observer.disconnect();
154
- }, []);
156
+ };
157
158
const openMatch = (match: ProjectContentMatch) => {
159
if (!canOpenMatches || !readEnvironmentScope(target.environmentId, AuthFilesystemReadScope)) {
@@ -160,7 +162,7 @@ function OpenContentSearchDialog(props: {
162
props.onOpenChange(false);
163
useRightPanelStore.getState().openFile(target.threadRef, match.path, match.lineNumber);
164
};
163
- const fileCount = useMemo(() => new Set(matches.map((match) => match.path)).size, [matches]);
165
+ const fileCount = new Set(matches.map((match) => match.path)).size;
166
const showSearchStatus =
167
search.canReadFiles &&
168
(search.hasQuery || search.isPending || search.error !== null || search.invalidRegex);