Skip to content

Commit d729f8c

Browse files
maria-rcksclaude
andcommitted
fix(web): write the row's answer as the action is sent, and clear it only when the host agrees
The override is written the moment the detail panel sends a state action and taken back if the host refuses, so the row answers on the click rather than after the round trip. It is cleared by a whole-page answer that agrees with it, not by any read that happens to land after it. The acted row is looked up among every held row, so a pull request reopened from an open list is found even though it left the screen. A refresh that only reordered rows no longer hands back the old order. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 0aadddf commit d729f8c

4 files changed

Lines changed: 107 additions & 13 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,12 @@ export function PullRequestDetailPanel({
458458
* An action changed this pull request on the host, so a list showing it is now out of date.
459459
* Told rather than assumed: only the page knows whether it is showing one.
460460
*/
461-
/** The action that just succeeded, or nothing for one the caller cannot name. */
462-
onActed?: (action?: PullRequestAction) => void;
461+
/**
462+
* Each host action as it goes: "sent" the moment it leaves, so a list can answer before the
463+
* host does; "done" or "failed" when the host has spoken. Undefined for one the caller cannot
464+
* name, which is only ever "done".
465+
*/
466+
onActed?: (action?: PullRequestAction, phase?: "sent" | "done" | "failed") => void;
463467
/** Page-owned detail columns use this to clear the selected pull request. */
464468
onClose?: () => void;
465469
/**
@@ -962,6 +966,7 @@ export function PullRequestDetailPanel({
962966
method?: PullRequestMergeMethod,
963967
updateMethod?: PullRequestUpdateMethod,
964968
) => {
969+
onActed?.(action, "sent");
965970
const result = await runAction({
966971
environmentId,
967972
input: {
@@ -989,6 +994,7 @@ export function PullRequestDetailPanel({
989994
title: ACTION_FAILURE_LABELS[action],
990995
description: readableFailure(failure, hint),
991996
});
997+
onActed?.(action, "failed");
992998
return false;
993999
}
9941000
toastManager.add({ type: "success", title: ACTION_SUCCESS_LABELS[action] });
@@ -1002,7 +1008,7 @@ export function PullRequestDetailPanel({
10021008
} else {
10031009
refreshDetail();
10041010
}
1005-
onActed?.(action);
1011+
onActed?.(action, "done");
10061012
return true;
10071013
};
10081014

‎apps/web/src/components/pullRequest/pullRequestList.logic.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
applyPullRequestOverrides,
3636
pullRequestOverrideAfterAction,
3737
reusePullRequestEntries,
38+
settlePullRequestOverrides,
3839
} from "./pullRequestList.logic";
3940
import {
4041
pullRequestListPreferences,
@@ -1656,3 +1657,29 @@ describe("pull request list overrides", () => {
16561657
).toBe(previous);
16571658
});
16581659
});
1660+
1661+
describe("pull request list override settlement", () => {
1662+
const entry = (number: number, state: "open" | "closed" | "merged") =>
1663+
({ number, state, isDraft: false, labels: [] }) as unknown as PullRequestListEntry;
1664+
const key = (row: { number: number }) => `#${row.number}`;
1665+
1666+
it("keeps an override until an answer agrees with it", () => {
1667+
const closed = { state: "closed" as const, updatedAt: "2026-07-03T00:00:00Z" };
1668+
const overrides = new Map([["#1", closed]]);
1669+
// A read from before the action still says open: the override stands.
1670+
expect(settlePullRequestOverrides(overrides, [entry(1, "open")], key, "open")).toBe(overrides);
1671+
// The row is gone from an open list: that is the host agreeing.
1672+
expect(settlePullRequestOverrides(overrides, [entry(2, "open")], key, "open").size).toBe(0);
1673+
// Absent from an "all" list says nothing, so the override stays.
1674+
expect(settlePullRequestOverrides(overrides, [entry(2, "open")], key, "all").size).toBe(1);
1675+
// Present as closed: confirmed.
1676+
expect(settlePullRequestOverrides(overrides, [entry(1, "closed")], key, "all").size).toBe(0);
1677+
});
1678+
1679+
it("does not hand back the old order when only the order changed", () => {
1680+
const previous = [entry(1, "open"), entry(2, "open")];
1681+
const swapped = reusePullRequestEntries(previous, [entry(2, "open"), entry(1, "open")], key);
1682+
expect(swapped).not.toBe(previous);
1683+
expect(swapped.map((row) => row.number)).toEqual([2, 1]);
1684+
});
1685+
});

‎apps/web/src/components/pullRequest/pullRequestList.logic.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,5 +1218,36 @@ export function reusePullRequestEntries<Entry extends PullRequestListEntry>(
12181218
}
12191219
return entry;
12201220
});
1221-
return reused === next.length && previous.length === next.length ? previous : out;
1221+
return reused === next.length &&
1222+
previous.length === next.length &&
1223+
previous.every((entry, index) => keyOf(entry) === keyOf(next[index]!))
1224+
? previous
1225+
: out;
1226+
}
1227+
1228+
/**
1229+
* The overrides a whole-page answer has confirmed, dropped; the rest kept. A read that started
1230+
* before the action can land after it and still say the old thing, so an override is not
1231+
* cleared because an answer arrived but because the answer agrees: the row is there in the
1232+
* state the override said, or it is gone from a list whose state filter no longer holds it.
1233+
*/
1234+
export function settlePullRequestOverrides<Entry extends PullRequestListEntry>(
1235+
overrides: ReadonlyMap<string, PullRequestListOverride>,
1236+
answered: ReadonlyArray<Entry>,
1237+
keyOf: (entry: Entry) => string,
1238+
state: PullRequestListState,
1239+
): ReadonlyMap<string, PullRequestListOverride> {
1240+
if (overrides.size === 0) return overrides;
1241+
const byKey = new Map(answered.map((entry) => [keyOf(entry), entry]));
1242+
const kept = new Map<string, PullRequestListOverride>();
1243+
for (const [key, override] of overrides) {
1244+
const row = byKey.get(key);
1245+
const confirmed =
1246+
row === undefined
1247+
? state !== "all" && override.state !== state
1248+
: row.state === override.state &&
1249+
(override.isDraft === undefined || row.isDraft === override.isDraft);
1250+
if (!confirmed) kept.set(key, override);
1251+
}
1252+
return kept.size === overrides.size ? overrides : kept;
12221253
}

‎apps/web/src/routes/_chat.pull-requests.tsx‎

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
type PullRequestListOverride,
8383
pullRequestOverrideAfterAction,
8484
reusePullRequestEntries,
85+
settlePullRequestOverrides,
8586
} from "../components/pullRequest/pullRequestList.logic";
8687
import {
8788
pullRequestListPreferences,
@@ -1103,9 +1104,13 @@ function PullRequestsRouteView() {
11031104
),
11041105
};
11051106
});
1106-
// A whole answer read after the action is the host's word, which outranks the reader's.
1107-
setOverrides((current) => (current.size === 0 ? current : new Map()));
1107+
// The host's word outranks the reader's, once it has actually said it: an override is
1108+
// cleared by an answer that agrees with it, not by any answer that happens to land.
1109+
setOverrides((current) =>
1110+
settlePullRequestOverrides(current, answered.entries, pullRequestEntryKey, search.state),
1111+
);
11081112
}, [
1113+
search.state,
11091114
answered,
11101115
filterKey,
11111116
sentCursors,
@@ -1504,6 +1509,15 @@ function PullRequestsRouteView() {
15041509
search.involvement,
15051510
);
15061511
}, [groups, search.involvement, sort, statsByRow, typedParsed.text]);
1512+
const heldPullRequestsBySurface = useMemo(
1513+
() =>
1514+
new Map(
1515+
(ordered?.key === filterKey ? ordered.entries : (listData?.entries ?? [])).map(
1516+
(entry) => [pullRequestListEntryId(entry), entry] as const,
1517+
),
1518+
),
1519+
[filterKey, listData, ordered],
1520+
);
15071521
const listedPullRequestsBySurface = useMemo(
15081522
() =>
15091523
new Map(
@@ -2100,17 +2114,33 @@ function PullRequestsRouteView() {
21002114
refreshToken={detailRefreshToken}
21012115
// Host actions can change both readiness and diff size, so refresh the counts
21022116
// alongside the list. The panel already refreshes itself after each action.
2103-
onActed={(action) => {
2104-
// An action that only moves a row's state is written onto the row at once; the
2105-
// host has invalidated its caches, so the next scheduled read confirms it. The
2106-
// rest change what the counts and checks say, and those need the reads now.
2107-
const acted = listedPullRequestsBySurface.get(
2117+
onActed={(action, phase = "done") => {
2118+
// An action that only moves a row's state is written onto the row as it is
2119+
// sent, and taken back if the host refuses; the host invalidates its caches,
2120+
// so the next scheduled read confirms it. The rest change what the counts and
2121+
// checks say, and those need the reads once they are done.
2122+
// From every row held, not the ones on screen: a pull request closed from an
2123+
// open list has left the screen, and reopening it has to find it anyway.
2124+
const acted = heldPullRequestsBySurface.get(
21082125
pullRequestListEntryId(renderedPullRequestSurface),
21092126
);
2110-
if (action !== undefined && acted !== undefined && overrideEntry(acted, action)) {
2127+
const stateOnly =
2128+
action !== undefined &&
2129+
acted !== undefined &&
2130+
pullRequestOverrideAfterAction(acted, action, "") !== null;
2131+
if (stateOnly) {
2132+
if (phase === "sent") overrideEntry(acted, action);
2133+
if (phase === "failed") {
2134+
const key = pullRequestEntryKey(acted);
2135+
setOverrides((current) => {
2136+
const next = new Map(current);
2137+
next.delete(key);
2138+
return next;
2139+
});
2140+
}
21112141
return;
21122142
}
2113-
refreshListAndStats(undefined, panelEnvironmentId);
2143+
if (phase === "done") refreshListAndStats(undefined, panelEnvironmentId);
21142144
}}
21152145
/>
21162146
</RightPanelTabs>

0 commit comments

Comments
 (0)