Skip to content

Commit 59197ad

Browse files
committed
perf(sidebar): eliminate unnecessary re-renders in workspace switcher for non-search users
- onMouseEnter: only set highlightedIndex when showSearch is true, preventing a state update + re-render on every workspace row hover for users with ≤ 3 workspaces where the search is never shown - onOpenChange: only reset workspaceSearch and highlightedIndex when showSearch is true, since both values are always already at their defaults for non-search users and setting them triggers a pointless re-render during dropdown close - data-workspace-row-idx: only set when showSearch is true since the scroll effect that reads this attribute is already gated on showSearch
1 parent 0f9ea0a commit 59197ad

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function WorkspaceHeaderImpl({
355355
if (open && showSearch) {
356356
requestAnimationFrame(() => searchInputRef.current?.focus())
357357
}
358-
if (!open) {
358+
if (!open && showSearch) {
359359
setWorkspaceSearch('')
360360
setHighlightedIndex(0)
361361
}
@@ -479,8 +479,8 @@ function WorkspaceHeaderImpl({
479479
return (
480480
<div
481481
key={workspace.id}
482-
data-workspace-row-idx={idx}
483-
onMouseEnter={() => setHighlightedIndex(idx)}
482+
data-workspace-row-idx={showSearch ? idx : undefined}
483+
onMouseEnter={showSearch ? () => setHighlightedIndex(idx) : undefined}
484484
>
485485
{editingWorkspaceId === workspace.id ? (
486486
<div

0 commit comments

Comments
 (0)