fix(web): retain terminal PR badges after checkout switch #4755
Mergedsebbonit(GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/4755/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/SidebarV2.tsx line 1441OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1394,4 +1431,11 @@13941431 const supportsSnooze =13951432 serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSnooze === true;13961433 const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));1397- const changeRequestState = changeRequestStateByKey.get(threadKey) ?? null;1434+ const snapshot = changeRequestSnapshotByKey.get(threadKey);1435+ // Same resolved terminal PR the row displays: local thread branch1436+ // metadata follows the shared checkout, while worktree snapshots remain1437+ // scoped to the worktree's branch.1438+ const changeRequestState =1439+ snapshot != null && (thread.worktreePath === null || snapshot.branch === thread.branch)1440+ ? snapshot.pr.state1441+ : null;
- apps/web/src/components/ThreadStatusIndicators.tsx line 143OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -126,3 +128,16 @@126128 return gitStatus.pr ?? null;127129 }128130131+/**132+ * Parent-held PR snapshot for Sidebar V2. Rows remount when settlement133+ * partitions move them, so terminal PR metadata must live above the row.134+ */135+export interface ThreadChangeRequestSnapshot {136+ readonly branch: string;137+ readonly pr: NonNullable<ThreadPr>;138+ readonly sourceControlProvider: VcsStatusResult["sourceControlProvider"] | undefined;139+}140+141+export const threadChangeRequestSnapshotsAtom = Atom.make<142+ ReadonlyMap<string, ThreadChangeRequestSnapshot>143+>(new Map()).pipe(Atom.withLabel("sidebar:thread-change-request-snapshots"));
- apps/web/src/components/ThreadStatusIndicators.test.ts line 455Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -72,0 +388,21 @@388+ ).toBe(true);389+ });390+});391+392+describe("threadChangeRequestSnapshotsAtom", () => {393+ it("retains snapshots while sidebar and chat consumers are unmounted", () => {394+ const registry = AtomRegistry.make();395+ const threadKey = "environment-1:thread-1";396+ const snapshot = snapshotFor("feature/current", mergedFeaturePr());397+398+ const unmount = registry.mount(threadChangeRequestSnapshotsAtom);399+ registry.set(threadChangeRequestSnapshotsAtom, new Map([[threadKey, snapshot]]));400+ unmount();401+402+ const remount = registry.mount(threadChangeRequestSnapshotsAtom);403+ expect(registry.get(threadChangeRequestSnapshotsAtom).get(threadKey)).toEqual(snapshot);404+405+ remount();406+ registry.dispose();407+ });408+});
- apps/web/src/components/ThreadStatusIndicators.tsx lines 210 to 212OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -128,0 +192,21 @@192+ next.set(threadKey, snapshot);193+ return [true, next];194+ });195+}196+197+/**198+ * Authoritative snapshot update from live VCS status.199+ * - `undefined`: missing status, or a local checkout retaining a terminal PR — leave the map alone200+ * - `null`: no PR (without a retained terminal snapshot), or a worktree mismatch — clear201+ * - snapshot: matching branch reports a PR — store/replace202+ */203+export function nextThreadChangeRequestSnapshot(input: {204+ threadBranch: string | null;205+ gitStatus: VcsStatusResult | null;206+ snapshot: ThreadChangeRequestSnapshot | null | undefined;207+ retainTerminalOnBranchMismatch: boolean;208+}): ThreadChangeRequestSnapshot | null | undefined {209+ const { threadBranch, gitStatus, snapshot, retainTerminalOnBranchMismatch } = input;210+ if (threadBranch === null || gitStatus === null) {211+ return undefined;212+ }
- apps/web/src/components/ThreadStatusIndicators.tsx line 214OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -128,0 +194,21 @@194+ });195+}196+197+/**198+ * Authoritative snapshot update from live VCS status.199+ * - `undefined`: missing status, or a local checkout retaining a terminal PR — leave the map alone200+ * - `null`: no PR (without a retained terminal snapshot), or a worktree mismatch — clear201+ * - snapshot: matching branch reports a PR — store/replace202+ */203+export function nextThreadChangeRequestSnapshot(input: {204+ threadBranch: string | null;205+ gitStatus: VcsStatusResult | null;206+ snapshot: ThreadChangeRequestSnapshot | null | undefined;207+ retainTerminalOnBranchMismatch: boolean;208+}): ThreadChangeRequestSnapshot | null | undefined {209+ const { threadBranch, gitStatus, snapshot, retainTerminalOnBranchMismatch } = input;210+ if (threadBranch === null || gitStatus === null) {211+ return undefined;212+ }213+ if (gitStatus.refName !== threadBranch) {214+ return retainTerminalOnBranchMismatch ? undefined : null;
- apps/web/src/components/ThreadStatusIndicators.tsx line 270Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -128,0 +249,21 @@249+ gitStatus: VcsStatusResult | null;250+ snapshot: ThreadChangeRequestSnapshot | null | undefined;251+ retainTerminalOnBranchMismatch: boolean;252+}): ThreadPr | null {253+ const { threadBranch, gitStatus, snapshot, retainTerminalOnBranchMismatch } = input;254+ if (255+ threadBranch !== null &&256+ gitStatus !== null &&257+ gitStatus.refName === threadBranch &&258+ gitStatus.pr != null259+ ) {260+ return gitStatus.pr;261+ }262+263+ if (264+ retainTerminalOnBranchMismatch &&265+ snapshot != null &&266+ isTerminalChangeRequestState(snapshot.pr.state)267+ ) {268+ return snapshot.pr;269+ }
- @@ -128,0 +244,21 @@244+ * survives that metadata changing to the newly checked-out branch. Open PRs245+ * are never retained — their state can still change.246+ */247+export function resolveDisplayedThreadPr(input: {248+ threadBranch: string | null;249+ gitStatus: VcsStatusResult | null;250+ snapshot: ThreadChangeRequestSnapshot | null | undefined;251+ retainTerminalOnBranchMismatch: boolean;252+}): ThreadPr | null {253+ const { threadBranch, gitStatus, snapshot, retainTerminalOnBranchMismatch } = input;254+ if (255+ threadBranch !== null &&256+ gitStatus !== null &&257+ gitStatus.refName === threadBranch &&258+ gitStatus.pr != null259+ ) {260+ return gitStatus.pr;261+ }262+263+ if (264+ threadBranch !== null &&
juliusmarminge approved these changes
juliusmarminge merged thisd5465ae
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
a023e2d7-880f-4e3b-a12f-af7d13dd1f80You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share