@devries-cameron20 / t3code-1 / commits / e6ec114128
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): pull request page reacts to turns and sweep Escape without effects (#25523)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 26, 2026 at 09:07 UTC e6ec114128122832098fbe0d3793423dc141aa9e
1 file changed +48 -36
apps/web/src/components/pullRequest/PullRequestsPage.tsx
+48 -36
@@ -78,6 +78,7 @@ import { RightPanelTabs } from "../RightPanelTabs";
78 import { isCommandPaletteOpen } from "~/commandPaletteBus";
79 import { isElectron } from "~/env";
80 import { resolveShortcutCommand, shortcutLabelForCommand } from "~/keybindings";
81 +import { registerCommands } from "~/shortcuts/dispatcher";
82 import { isTerminalFocused } from "~/lib/terminalFocus";
83 import { PanelLayoutControls, RightPanelMaximizeControl } from "../chat/PanelLayoutControls";
84 import { Button } from "../ui/button";
@@ -286,13 +287,21 @@ export function PullRequestsPage() {
287 * host forever.
288 */
289 regrown: ReadonlyArray<string>;
289 - }>({ key: filterKey, size: PAGE_SIZE, cursors: null, regrown: [] });
290 + /** The turn refreshes a continuation was read under; a later turn makes its cursors stale. */
291 + turn: string;
292 + }>({ key: filterKey, size: PAGE_SIZE, cursors: null, regrown: [], turn: turnRefreshToken });
293 const pageSize = page.key === filterKey ? page.size : PAGE_SIZE;
294 const sentCursors = page.key === filterKey ? page.cursors : null;
295 const sentRegrown = page.key === filterKey ? page.regrown : [];
296
297 if (page.key !== filterKey) {
295 - setPage({ key: filterKey, size: PAGE_SIZE, cursors: null, regrown: [] });
298 + setPage({
299 + key: filterKey,
300 + size: PAGE_SIZE,
301 + cursors: null,
302 + regrown: [],
303 + turn: turnRefreshToken,
304 + });
305 }
306
307 const listTargets = environmentQueries.flatMap(({ environmentId, projectIds }) => {
@@ -591,6 +600,7 @@ export function PullRequestsPage() {
600 size: regrown.length === 0 ? pageSize : Math.min(pageSize + PAGE_SIZE, MAX_PAGE_SIZE),
601 cursors: nextCursors,
602 regrown,
603 + turn: turnRefreshToken,
604 });
605 return;
606 }
@@ -599,9 +609,28 @@ export function PullRequestsPage() {
609 size: Math.min(pageSize + PAGE_SIZE, MAX_PAGE_SIZE),
610 cursors: null,
611 regrown: [],
612 + turn: turnRefreshToken,
613 });
614 };
615
616 + const collapsedPage = () => {
617 + const loadedCount =
618 + ordered?.key === filterKey ? largestPullRequestReadCount(ordered.entries) : pageSize;
619 + return {
620 + key: filterKey,
621 + regrown: [],
622 + size: Math.min(
623 + Math.max(pageSize, Math.ceil(loadedCount / PAGE_SIZE) * PAGE_SIZE),
624 + MAX_PAGE_SIZE,
625 + ),
626 + cursors: null,
627 + turn: turnRefreshToken,
628 + };
629 + };
630 + // Every list read refetches itself when a turn completes, but a continuation would refetch only
631 + // its later page and strand the rows before it, so the whole loaded list is asked for again.
632 + if (sentCursors !== null && page.turn !== turnRefreshToken) setPage(collapsedPage());
633 +
634 const refreshList = (includeRelated = false, actedEnvironmentId?: EnvironmentId) => {
635 const related = (
636 includeRelated
@@ -627,31 +656,9 @@ export function PullRequestsPage() {
656 return;
657 }
658 if (related.length > 0) listQuery.refresh(related);
630 - const loadedCount =
631 - ordered?.key === filterKey ? largestPullRequestReadCount(ordered.entries) : pageSize;
632 - setPage({
633 - key: filterKey,
634 - regrown: [],
635 - size: Math.min(
636 - Math.max(pageSize, Math.ceil(loadedCount / PAGE_SIZE) * PAGE_SIZE),
637 - MAX_PAGE_SIZE,
638 - ),
639 - cursors: null,
640 - });
659 + setPage(collapsedPage());
660 };
661
643 - const appliedTurnRefreshToken = useRef("");
644 - const refreshAfterTurn = useEffectEvent(() => {
645 - if (sentCursors !== null) refreshList();
646 - });
647 - useEffect(() => {
648 - if (turnRefreshToken.length === 0 || appliedTurnRefreshToken.current === turnRefreshToken) {
649 - return;
650 - }
651 - appliedTurnRefreshToken.current = turnRefreshToken;
652 - refreshAfterTurn();
653 - }, [turnRefreshToken]);
654 -
662 useLiveRefresh(
663 () => {
664 refreshList(true);
@@ -917,15 +924,6 @@ export function PullRequestsPage() {
924 // oxlint-disable-next-line react/exhaustive-effect-dependencies -- The pointer sensor lives outside React; a new list under a sweep in progress must end it.
925 [filterKey, search.q, sort],
926 );
920 - useEffect(() => {
921 - const onKeyDown = (event: KeyboardEvent) => {
922 - if (event.key !== "Escape" || closeSensorRef.current === null) return;
923 - event.preventDefault();
924 - closeSensorRef.current.cancel();
925 - };
926 - document.addEventListener("keydown", onKeyDown, true);
927 - return () => document.removeEventListener("keydown", onKeyDown, true);
928 - }, []);
927 const startCloseSweep = useStableCallback(
928 (entry: EnvironmentPullRequestEntry, event: PointerEvent) => {
929 closeSensorRef.current?.cancel();
@@ -957,14 +955,27 @@ export function PullRequestsPage() {
955 sweptKeys = resolveSidebarSweepKeys(orderedKeys, originKey, key, canClose);
956 setCloseSweepKeys(new Set(sweptKeys));
957 };
960 - closeSensorRef.current = new SidebarPointerSensor({
958 + // Only while a sweep runs: Escape ends it, ahead of any other scope that would also take it.
959 + const releaseEscape = registerCommands(
960 + {},
961 + {
962 + capture: true,
963 + onKeyDown: (keyEvent) => {
964 + if (keyEvent.key !== "Escape") return false;
965 + keyEvent.preventDefault();
966 + sensor.cancel();
967 + },
968 + },
969 + );
970 + const sensor = new SidebarPointerSensor({
971 active: originKey,
972 event,
973 options: {
974 distance: 6,
975 onAttach: () => {},
976 onFinish: () => {
967 - closeSensorRef.current = null;
977 + releaseEscape();
978 + if (closeSensorRef.current === sensor) closeSensorRef.current = null;
979 setCloseSweepKeys(new Set());
980 },
981 },
@@ -992,6 +1003,7 @@ export function PullRequestsPage() {
1003 onCancel: () => {},
1004 onAbort: () => {},
1005 });
1006 + closeSensorRef.current = sensor;
1007 },
1008 );
1009 const rightPanelAvailable = selectedPullRequestSurface !== null;