Skip to content

Commit 0290927

Browse files
perf(web): Shift re-renders only each row's quick-action group
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bcb74b5 commit 0290927

4 files changed

Lines changed: 136 additions & 106 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestListGroups.tsx‎

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { EyeIcon, LayersIcon, PenLineIcon, UsersIcon, type LucideIcon } from "lu
33
import type { RefCallback } from "react";
44

55
import { cn } from "~/lib/utils";
6-
import { useShortcutModifierState } from "~/shortcutModifierState";
76
import { Separator } from "../ui/separator";
87
import {
98
pullRequestEntryKey,
@@ -12,7 +11,10 @@ import {
1211
type PullRequestGroup,
1312
} from "./pullRequestList.logic";
1413
import { PullRequestRow, type PullRequestRowTarget } from "./PullRequestRow";
15-
import type { PullRequestSpeedActionResult } from "./PullRequestSpeedActions";
14+
import {
15+
PullRequestSpeedModeProvider,
16+
type PullRequestSpeedActionResult,
17+
} from "./PullRequestSpeedActions";
1618

1719
const GROUP_ICONS: Record<string, LucideIcon> = {
1820
authored: PenLineIcon,
@@ -38,10 +40,6 @@ function PullRequestGroupHeader({
3840
);
3941
}
4042

41-
/**
42-
* The grouped rows. Holding Shift turns rows into speed actions, so the modifier subscription lives
43-
* here: a key press re-renders the rows, not the page and its open pull request.
44-
*/
4543
export function PullRequestListGroups({
4644
groups,
4745
environmentLabels,
@@ -75,47 +73,46 @@ export function PullRequestListGroups({
7573
sweepingKeys: ReadonlySet<string>;
7674
onCloseSweepStart: (entry: EnvironmentPullRequestEntry, event: PointerEvent) => void;
7775
}) {
78-
const modifiers = useShortcutModifierState(true);
79-
const speedMode =
80-
modifiers.shiftKey && !modifiers.metaKey && !modifiers.ctrlKey && !modifiers.altKey;
8176
return (
82-
<div className={cn("space-y-3", sweepingKeys.size > 0 && "**:pointer-events-none")}>
83-
{groups.map((group) => (
84-
<div key={group.key} className="space-y-0.5">
85-
{group.label ? <PullRequestGroupHeader group={group} /> : null}
86-
{group.entries.map((entry) => {
87-
const entryKey = pullRequestEntryKey(entry);
88-
const environmentLabel = environmentLabels?.get(entry.environmentId);
89-
return (
90-
<PullRequestRow
91-
key={entryKey}
92-
statsKey={entryKey}
93-
statsRef={statsRef}
94-
entry={entry}
95-
showProjectTitle
96-
showProvider={showProvider}
97-
{...(environmentLabel !== undefined ? { environmentLabel } : {})}
98-
matchedElsewhere={
99-
query.length > 0 && scorePullRequestMatch(entry, query) <= MATCHED_ELSEWHERE_SCORE
100-
}
101-
selected={
102-
selected?.environmentId === entry.environmentId &&
103-
selected.repository === entry.repository &&
104-
selected.host?.toLowerCase() === entry.host.toLowerCase() &&
105-
selected.number === entry.number
106-
}
107-
onSelect={onSelect}
108-
speedMode={speedMode}
109-
hostActions={hostActionsOf(entry)}
110-
onActed={onActed}
111-
closing={closingKeys.has(entryKey)}
112-
sweeping={sweepingKeys.has(entryKey)}
113-
onCloseSweepStart={onCloseSweepStart}
114-
/>
115-
);
116-
})}
117-
</div>
118-
))}
119-
</div>
77+
<PullRequestSpeedModeProvider>
78+
<div className={cn("space-y-3", sweepingKeys.size > 0 && "**:pointer-events-none")}>
79+
{groups.map((group) => (
80+
<div key={group.key} className="space-y-0.5">
81+
{group.label ? <PullRequestGroupHeader group={group} /> : null}
82+
{group.entries.map((entry) => {
83+
const entryKey = pullRequestEntryKey(entry);
84+
const environmentLabel = environmentLabels?.get(entry.environmentId);
85+
return (
86+
<PullRequestRow
87+
key={entryKey}
88+
statsKey={entryKey}
89+
statsRef={statsRef}
90+
entry={entry}
91+
showProjectTitle
92+
showProvider={showProvider}
93+
{...(environmentLabel !== undefined ? { environmentLabel } : {})}
94+
matchedElsewhere={
95+
query.length > 0 &&
96+
scorePullRequestMatch(entry, query) <= MATCHED_ELSEWHERE_SCORE
97+
}
98+
selected={
99+
selected?.environmentId === entry.environmentId &&
100+
selected.repository === entry.repository &&
101+
selected.host?.toLowerCase() === entry.host.toLowerCase() &&
102+
selected.number === entry.number
103+
}
104+
onSelect={onSelect}
105+
hostActions={hostActionsOf(entry)}
106+
onActed={onActed}
107+
closing={closingKeys.has(entryKey)}
108+
sweeping={sweepingKeys.has(entryKey)}
109+
onCloseSweepStart={onCloseSweepStart}
110+
/>
111+
);
112+
})}
113+
</div>
114+
))}
115+
</div>
116+
</PullRequestSpeedModeProvider>
120117
);
121118
}

‎apps/web/src/components/pullRequest/PullRequestRow.tsx‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ function PullRequestRowImpl({
7878
statsKey,
7979
statsRef,
8080
onSelect,
81-
speedMode,
8281
hostActions,
8382
onActed,
8483
closing = false,
@@ -95,7 +94,6 @@ function PullRequestRowImpl({
9594
statsKey?: string;
9695
statsRef?: RefCallback<HTMLDivElement>;
9796
onSelect: (entry: PullRequestRowTarget) => void;
98-
speedMode: boolean;
9997
hostActions: ReadonlySet<PullRequestAction>;
10098
onActed: (result: PullRequestSpeedActionResult) => void;
10199
closing?: boolean;
@@ -243,7 +241,6 @@ function PullRequestRowImpl({
243241
<PullRequestSpeedActions
244242
entry={entry}
245243
hostActions={hostActions}
246-
visible={speedMode}
247244
onActed={onActed}
248245
closing={closing}
249246
sweeping={sweeping}

‎apps/web/src/components/pullRequest/PullRequestSpeedActions.tsx‎

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { useAtomValue } from "@effect/atom-react";
22
import type { PullRequestAction } from "@t3tools/contracts";
3+
import { createContext, use, type ReactNode } from "react";
4+
5+
import { useShortcutModifierState } from "~/shortcutModifierState";
36
import { pullRequestEnvironment } from "~/state/pullRequests";
47
import { useUiStateStore } from "~/uiStateStore";
58
import { Button } from "../ui/button";
@@ -26,15 +29,13 @@ export interface PullRequestSpeedActionResult<Entry = EnvironmentPullRequestEntr
2629
export function PullRequestSpeedActions<Entry extends PullRequestSpeedActionEntry>({
2730
entry,
2831
hostActions,
29-
visible,
3032
onActed,
3133
closing = false,
3234
sweeping = false,
3335
onCloseSweepStart,
3436
}: {
3537
entry: Entry;
3638
hostActions: ReadonlySet<PullRequestAction>;
37-
visible: boolean;
3839
onActed?: (result: PullRequestSpeedActionResult<Entry>) => void;
3940
closing?: boolean;
4041
sweeping?: boolean;
@@ -75,12 +76,10 @@ export function PullRequestSpeedActions<Entry extends PullRequestSpeedActionEntr
7576
const busy = actionPending || closing || sweeping;
7677
if (actions.length === 0) return null;
7778
return (
78-
<div
79-
className="shrink-0 items-center gap-1 pr-3"
80-
style={{ display: visible || busy ? "flex" : "none" }}
81-
role="group"
82-
aria-label={`Quick actions for pull request #${entry.number}`}
83-
data-pull-request-action-pending={actionPending || closing}
79+
<SpeedModeGroup
80+
busy={busy}
81+
pending={actionPending || closing}
82+
label={`Quick actions for pull request #${entry.number}`}
8483
>
8584
{actions.map((action) => {
8685
const label = ACTIONS[action].label;
@@ -116,6 +115,45 @@ export function PullRequestSpeedActions<Entry extends PullRequestSpeedActionEntr
116115
</Tooltip>
117116
);
118117
})}
118+
</SpeedModeGroup>
119+
);
120+
}
121+
122+
/**
123+
* Whether Shift is held, as context rather than a row prop: a Shift press then re-renders each
124+
* row's action group, not the rows or their buttons, in one commit.
125+
*/
126+
export const PullRequestSpeedModeContext = createContext(false);
127+
128+
/** Tracks Shift for the quick actions below it. */
129+
export function PullRequestSpeedModeProvider({ children }: { children: ReactNode }) {
130+
const modifiers = useShortcutModifierState(true);
131+
const speedMode =
132+
modifiers.shiftKey && !modifiers.metaKey && !modifiers.ctrlKey && !modifiers.altKey;
133+
return <PullRequestSpeedModeContext value={speedMode}>{children}</PullRequestSpeedModeContext>;
134+
}
135+
136+
function SpeedModeGroup({
137+
busy,
138+
pending,
139+
label,
140+
children,
141+
}: {
142+
busy: boolean;
143+
pending: boolean;
144+
label: string;
145+
children: ReactNode;
146+
}) {
147+
const speedMode = use(PullRequestSpeedModeContext);
148+
return (
149+
<div
150+
className="shrink-0 items-center gap-1 pr-3"
151+
style={{ display: speedMode || busy ? "flex" : "none" }}
152+
role="group"
153+
aria-label={label}
154+
data-pull-request-action-pending={pending}
155+
>
156+
{children}
119157
</div>
120158
);
121159
}

‎apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx‎

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
} from "./pullRequestPresentation";
5555
import { PullRequestGlyph } from "./pullRequestIcons";
5656
import { pullRequestQuickActions } from "./pullRequestList.logic";
57-
import { PullRequestSpeedActions } from "./PullRequestSpeedActions";
57+
import { PullRequestSpeedActions, PullRequestSpeedModeContext } from "./PullRequestSpeedActions";
5858

5959
const SOURCE_LABELS: Record<ThreadPullRequestLink["source"], string> = {
6060
manual: "Linked by you",
@@ -278,11 +278,7 @@ function LinkRowImpl({
278278
/>
279279
</a>
280280
{actionEntry !== null ? (
281-
<PullRequestSpeedActions
282-
entry={actionEntry}
283-
hostActions={linkHostActions}
284-
visible={speedMode}
285-
/>
281+
<PullRequestSpeedActions entry={actionEntry} hostActions={linkHostActions} />
286282
) : null}
287283
<span
288284
className={cn(
@@ -448,48 +444,50 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
448444
}
449445

450446
return (
451-
<div className="flex h-full min-h-0 flex-col">
452-
{/* Threads that run a stack or a sweep link hundreds of pull requests; only the rows in
447+
<PullRequestSpeedModeContext value={speedMode}>
448+
<div className="flex h-full min-h-0 flex-col">
449+
{/* Threads that run a stack or a sweep link hundreds of pull requests; only the rows in
453450
view are mounted. */}
454-
<LegendList<PullRequestListLine>
455-
data={lines}
456-
keyExtractor={lineKey}
457-
extraData={rowInputs}
458-
renderItem={({ item: line }) => (
459-
<LinkRow
460-
line={line}
461-
threadRef={threadRef}
462-
projectId={
463-
capabilities?.pullRequests === true
464-
? (findProjectForChangeRequest(environmentProjects, line.link)?.id ??
465-
thread?.projectId ??
466-
null)
467-
: null
468-
}
469-
speedMode={speedMode}
470-
onUnlink={handleUnlink}
471-
onSetWatching={supportsWatch ? handleSetWatching : null}
472-
/>
473-
)}
474-
estimatedItemSize={44}
475-
drawDistance={440}
476-
className="min-h-0 flex-1 overscroll-contain p-1.5"
477-
/>
478-
<footer className="flex items-center justify-between border-t border-border/60 px-2 py-1.5 text-2xs text-muted-foreground">
479-
<span>
480-
{openCount} open · {linkCount} linked
481-
{lastSynced ? (
482-
<>
483-
{" · synced "}
484-
<RelativeTime timestamp={lastSynced} />
485-
</>
486-
) : null}
487-
</span>
488-
<Button size="xs" variant="ghost" onClick={openLinkDialog}>
489-
<PlusIcon className="size-3.5" />
490-
Link
491-
</Button>
492-
</footer>
493-
</div>
451+
<LegendList<PullRequestListLine>
452+
data={lines}
453+
keyExtractor={lineKey}
454+
extraData={rowInputs}
455+
renderItem={({ item: line }) => (
456+
<LinkRow
457+
line={line}
458+
threadRef={threadRef}
459+
projectId={
460+
capabilities?.pullRequests === true
461+
? (findProjectForChangeRequest(environmentProjects, line.link)?.id ??
462+
thread?.projectId ??
463+
null)
464+
: null
465+
}
466+
speedMode={speedMode}
467+
onUnlink={handleUnlink}
468+
onSetWatching={supportsWatch ? handleSetWatching : null}
469+
/>
470+
)}
471+
estimatedItemSize={44}
472+
drawDistance={440}
473+
className="min-h-0 flex-1 overscroll-contain p-1.5"
474+
/>
475+
<footer className="flex items-center justify-between border-t border-border/60 px-2 py-1.5 text-2xs text-muted-foreground">
476+
<span>
477+
{openCount} open · {linkCount} linked
478+
{lastSynced ? (
479+
<>
480+
{" · synced "}
481+
<RelativeTime timestamp={lastSynced} />
482+
</>
483+
) : null}
484+
</span>
485+
<Button size="xs" variant="ghost" onClick={openLinkDialog}>
486+
<PlusIcon className="size-3.5" />
487+
Link
488+
</Button>
489+
</footer>
490+
</div>
491+
</PullRequestSpeedModeContext>
494492
);
495493
}

0 commit comments

Comments
 (0)