Skip to content

Commit ef0c035

Browse files
refactor(web): branch toolbar, git actions and pickers derive state
The branch toolbar and pickers, git actions, open-in picker, device panel, project content search and worktree setup derive defaults and measure from ref callbacks. Terminal focus becomes an explicit request that handlers make, and VCS status reads come from a revisioned atom. Effect categories removed: - branch toolbar label overflow and FLIP run from the strip's ref callback and resize/mutation observers, not a per-commit measure - picker scroll fades, search result scrolling and dialog focus moved to ref callbacks and dialog initialFocus - a draft's branch derived with selectEffectiveDraftBranch instead of a default written into the draft, and no git branch mirror for drafts - git action elapsed labels and inline success use shared clocks and deadlines; copy timers drop their unmount cleanup - editor.openFavorite moved from a window keydown effect to a dispatcher capture scope - terminal focus counter props replaced by focusTerminal requests that a viewport consumes when it attaches or is shown - VCS status read through a revisioned atom that records whether the checkout is a repository, replacing the remember effect - reconnect grace generalized to a held-for deadline Bugs fixed: - Opening an empty server thread no longer sends a background metadata update just to persist a default branch. - Closing the device panel, or a panel terminal, now focuses the terminal the panel falls back to. - Add-project-to-machine requests no longer leave a stale hidden request behind for a project that is gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ca5a59a commit ef0c035

27 files changed

Lines changed: 746 additions & 540 deletions

‎apps/web/src/components/AddProjectToMachineDialog.tsx‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
cloneUrlProtocol,
1818
} from "@t3tools/shared/cloneUrl";
1919
import { ArrowRightIcon } from "lucide-react";
20-
import { useEffect, useId, useState } from "react";
20+
import { useId, useState } from "react";
2121
import { create } from "zustand";
2222

2323
import { type DraftId, useComposerDraftStore } from "../composerDraftStore";
@@ -31,7 +31,7 @@ import {
3131
} from "../lib/addProjectToMachine";
3232
import { formatBytes } from "../lib/formatBytes";
3333
import { newProjectId } from "../lib/utils";
34-
import { useProject } from "../state/entities";
34+
import { readProject, useProject } from "../state/entities";
3535
import { useEnvironments } from "../state/environments";
3636
import { projectEnvironment } from "../state/projects";
3737
import { useEnvironmentQuery } from "../state/query";
@@ -58,20 +58,25 @@ interface AddProjectToMachineRequest {
5858
readonly targetEnvironmentId: EnvironmentId | null;
5959
}
6060

61-
const useRequest = create<{ request: AddProjectToMachineRequest | null }>(() => ({
61+
const useRequest = create<{ request: AddProjectToMachineRequest | null; session: number }>(() => ({
6262
request: null,
63+
session: 0,
6364
}));
6465

6566
/** Opens the dialog that clones a project onto another connected machine. */
6667
export function openAddProjectToMachine(request: AddProjectToMachineRequest) {
67-
useRequest.setState({ request });
68+
// The dialog closes itself when its project goes away, so it must not open
69+
// for one that is already gone and then appear when it loads.
70+
if (readProject(request.projectRef) === null) return;
71+
useRequest.setState((state) => ({ request, session: state.session + 1 }));
6872
}
6973

7074
const close = () => useRequest.setState({ request: null });
7175

7276
export function AddProjectToMachineDialogHost() {
7377
const request = useRequest((state) => state.request);
74-
return request ? <AddProjectToMachineDialog request={request} /> : null;
78+
const session = useRequest((state) => state.session);
79+
return request ? <AddProjectToMachineDialog key={session} request={request} /> : null;
7580
}
7681

7782
function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRequest }) {
@@ -128,10 +133,6 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe
128133
project === null ||
129134
target === null ||
130135
(canListFiles && ignoredFiles.data === null && ignoredFiles.error === null);
131-
useEffect(() => {
132-
if (project === null) close();
133-
}, [project]);
134-
135136
const toggleFile = (path: string, checked: boolean) => {
136137
const next = new Set(selectedFiles);
137138
if (checked) next.add(path);
@@ -196,10 +197,15 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe
196197

197198
return (
198199
<Dialog
199-
open
200+
open={project !== null}
200201
onOpenChange={(open) => {
201202
if (!open) close();
202203
}}
204+
// A user close unmounts at once through onOpenChange; this ends a request
205+
// whose project vanished while the dialog was open.
206+
onOpenChangeComplete={(open) => {
207+
if (!open) close();
208+
}}
203209
>
204210
<DialogPopup className="sm:max-w-xl">
205211
<form

‎apps/web/src/components/BranchPicker.tsx‎

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import type { VcsRef } from "@t3tools/contracts";
22
import { LegendList, type LegendListRef } from "@legendapp/list/react";
3-
import {
4-
useEffect,
5-
useId,
6-
useLayoutEffect,
7-
useRef,
8-
useState,
9-
type ComponentProps,
10-
type ReactNode,
11-
} from "react";
3+
import { useId, useRef, useState, type ComponentProps, type ReactNode } from "react";
124

135
import { MiddleTruncate } from "./ui/middle-truncate";
6+
import { observeResize } from "../lib/observeResize";
147
import { cn } from "../lib/utils";
158
import { shouldLoadNextBranchPageAfterScroll } from "../state/paginatedBranches";
169
import { RefreshIcon } from "./ui/refresh-icon";
@@ -32,7 +25,6 @@ export function BranchPicker({
3225
filteredItems,
3326
value,
3427
query,
35-
resultsQuery,
3628
onQueryChange,
3729
open,
3830
onOpenChange,
@@ -51,7 +43,6 @@ export function BranchPicker({
5143
filteredItems: string[];
5244
value: string | null;
5345
query: string;
54-
resultsQuery: string;
5546
onQueryChange: (value: string) => void;
5647
open: boolean;
5748
onOpenChange: (open: boolean) => void;
@@ -121,32 +112,22 @@ export function BranchPicker({
121112
setShowBottomBranchScrollFade(maxScrollOffset - scrollElement.scrollTop > 1);
122113
};
123114

124-
useLayoutEffect(() => {
125-
if (!open) {
126-
return;
127-
}
128-
129-
let nestedFrame = 0;
130-
const frame = requestAnimationFrame(() => {
131-
updateBranchListScrollFades();
132-
nestedFrame = requestAnimationFrame(updateBranchListScrollFades);
133-
});
115+
// The popup mounts the list when it opens. Its content settles over a few
116+
// frames as rows measure, so the fades follow the scroller and its content.
117+
const attachBranchList = (list: LegendListRef | null) => {
118+
branchListRef.current = list;
119+
const scrollElement = list?.getScrollableNode?.();
120+
if (!(scrollElement instanceof HTMLElement)) return;
121+
const content = scrollElement.firstElementChild;
122+
const stopObserving = observeResize(
123+
content ? [scrollElement, content] : scrollElement,
124+
updateBranchListScrollFades,
125+
);
134126
return () => {
135-
cancelAnimationFrame(frame);
136-
cancelAnimationFrame(nestedFrame);
127+
stopObserving();
128+
branchListRef.current = null;
137129
};
138-
}, [open, updateBranchListScrollFades]);
139-
140-
const previousResultsQuery = useRef<string | null>(null);
141-
useEffect(() => {
142-
if (!open) {
143-
previousResultsQuery.current = null;
144-
return;
145-
}
146-
if (previousResultsQuery.current === resultsQuery) return;
147-
previousResultsQuery.current = resultsQuery;
148-
void branchListRef.current?.scrollToOffset?.({ offset: 0, animated: false });
149-
}, [resultsQuery, open]);
130+
};
150131

151132
return (
152133
<Combobox
@@ -173,7 +154,10 @@ export function BranchPicker({
173154
<ComboboxSearchInput
174155
placeholder="Search refs..."
175156
value={query}
176-
onChange={(event) => onQueryChange(event.target.value)}
157+
onChange={(event) => {
158+
onQueryChange(event.target.value);
159+
void branchListRef.current?.scrollToOffset?.({ offset: 0, animated: false });
160+
}}
177161
onKeyDown={(event) => {
178162
if (event.key !== "Enter" || event.nativeEvent.isComposing || event.keyCode === 229)
179163
return;
@@ -193,7 +177,7 @@ export function BranchPicker({
193177
<div className="relative flex min-h-0 w-full max-h-56 flex-1 flex-col overflow-hidden">
194178
<ComboboxListVirtualized className="flex size-full min-h-0 min-w-0 flex-col">
195179
<LegendList<string>
196-
ref={branchListRef}
180+
ref={attachBranchList}
197181
data={filteredItems}
198182
keyExtractor={(item) => item}
199183
{...(getItemType ? { getItemType } : {})}

0 commit comments

Comments
 (0)