Skip to content

Commit fc5e800

Browse files
perf(web): the settings sidebar compiles with the React Compiler
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 70d60e0 commit fc5e800

2 files changed

Lines changed: 62 additions & 72 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/settings/SettingsSidebarNav.tsx",
99100
] as const;

‎apps/web/src/components/settings/SettingsSidebarNav.tsx‎

Lines changed: 61 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {
22
lazy,
33
Suspense,
4-
useCallback,
54
useEffect,
6-
useMemo,
75
useRef,
86
useState,
97
type ComponentType,
@@ -113,22 +111,19 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {
113111
const navigate = useNavigate();
114112
const currentHash = useLocation({ select: (location) => location.hash });
115113
const currentSearch = useLocation({ select: (location) => location.search });
116-
const scopeSearch = useMemo(() => validateSettingsScopeSearch(currentSearch), [currentSearch]);
114+
const scopeSearch = validateSettingsScopeSearch(currentSearch);
117115
const navItems = SETTINGS_NAV_ITEMS.filter(
118116
(item) => item.to !== "/settings/projects" || isSettingsOverviewVisible(scopeSearch),
119117
);
120118
const { isMobile, setOpenMobile, open, setOpen } = useSidebar();
121119
const searchInputRef = useRef<HTMLInputElement>(null);
122120
const [query, setQuery] = useState("");
123-
const [activeResultIndex, setActiveResultIndex] = useState(0);
121+
const [storedActiveResultIndex, setActiveResultIndex] = useState(0);
124122
const searchableItems = useAvailableSettingsSearchItems(scopeSearch);
125-
const results = useMemo(() => searchSettings(query, searchableItems), [query, searchableItems]);
123+
const results = searchSettings(query, searchableItems);
126124
const isSearching = query.trim().length > 0;
127125
const hasResults = results.length > 0;
128-
129-
useEffect(() => {
130-
setActiveResultIndex((index) => Math.min(index, Math.max(results.length - 1, 0)));
131-
}, [results.length]);
126+
const activeResultIndex = Math.min(storedActiveResultIndex, Math.max(results.length - 1, 0));
132127

133128
useEffect(() => {
134129
const result = results[activeResultIndex];
@@ -179,72 +174,66 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {
179174
return () => window.removeEventListener("keydown", handleKeyDown);
180175
}, [isMobile, open, setOpen, setOpenMobile]);
181176

182-
const handleSectionClick = useCallback(
183-
(to: SettingsPath) => {
184-
if (isMobile) {
185-
setOpenMobile(false);
186-
}
187-
void navigate({
188-
to,
189-
hash: "",
190-
replace: true,
191-
hashScrollIntoView: false,
192-
});
193-
},
194-
[isMobile, navigate, setOpenMobile],
195-
);
196-
const clearSearch = useCallback(() => {
177+
const handleSectionClick = (to: SettingsPath) => {
178+
if (isMobile) {
179+
setOpenMobile(false);
180+
}
181+
void navigate({
182+
to,
183+
hash: "",
184+
replace: true,
185+
hashScrollIntoView: false,
186+
});
187+
};
188+
189+
const clearSearch = () => {
197190
setQuery("");
198191
setActiveResultIndex(0);
199-
}, []);
200-
const handleSearchResultClick = useCallback(
201-
(item: SettingsSearchItem) => {
192+
};
193+
const handleSearchResultClick = (item: SettingsSearchItem) => {
194+
clearSearch();
195+
if (isMobile) {
196+
setOpenMobile(false);
197+
}
198+
const targetId = item.targetId ?? item.id;
199+
if (pathname === item.to && currentHash.replace(/^#/, "") === targetId) {
200+
scrollToSettingsTarget(targetId);
201+
return;
202+
}
203+
void navigate({
204+
to: item.to,
205+
hash: targetId,
206+
replace: true,
207+
hashScrollIntoView: false,
208+
state: { settingsTargetHighlight: true },
209+
});
210+
};
211+
212+
const handleSearchKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
213+
if (event.key === "Escape" && isSearching) {
214+
event.preventDefault();
215+
event.stopPropagation();
202216
clearSearch();
203-
if (isMobile) {
204-
setOpenMobile(false);
205-
}
206-
const targetId = item.targetId ?? item.id;
207-
if (pathname === item.to && currentHash.replace(/^#/, "") === targetId) {
208-
scrollToSettingsTarget(targetId);
209-
return;
210-
}
211-
void navigate({
212-
to: item.to,
213-
hash: targetId,
214-
replace: true,
215-
hashScrollIntoView: false,
216-
state: { settingsTargetHighlight: true },
217-
});
218-
},
219-
[clearSearch, currentHash, isMobile, navigate, pathname, setOpenMobile],
220-
);
221-
const handleSearchKeyDown = useCallback(
222-
(event: KeyboardEvent<HTMLInputElement>) => {
223-
if (event.key === "Escape" && isSearching) {
224-
event.preventDefault();
225-
event.stopPropagation();
226-
clearSearch();
227-
return;
228-
}
229-
if (results.length === 0) return;
230-
if (event.key === "ArrowDown") {
231-
event.preventDefault();
232-
setActiveResultIndex((index) => (index + 1) % results.length);
233-
return;
234-
}
235-
if (event.key === "ArrowUp") {
236-
event.preventDefault();
237-
setActiveResultIndex((index) => (index - 1 + results.length) % results.length);
238-
return;
239-
}
240-
if (event.key === "Enter") {
241-
event.preventDefault();
242-
const result = results[activeResultIndex];
243-
if (result) handleSearchResultClick(result);
244-
}
245-
},
246-
[activeResultIndex, clearSearch, handleSearchResultClick, isSearching, results],
247-
);
217+
return;
218+
}
219+
if (results.length === 0) return;
220+
if (event.key === "ArrowDown") {
221+
event.preventDefault();
222+
setActiveResultIndex((activeResultIndex + 1) % results.length);
223+
return;
224+
}
225+
if (event.key === "ArrowUp") {
226+
event.preventDefault();
227+
setActiveResultIndex((activeResultIndex - 1 + results.length) % results.length);
228+
return;
229+
}
230+
if (event.key === "Enter") {
231+
event.preventDefault();
232+
const result = results[activeResultIndex];
233+
if (result) handleSearchResultClick(result);
234+
}
235+
};
236+
248237
return (
249238
<>
250239
<SidebarContent className="overflow-x-hidden">

0 commit comments

Comments
 (0)