Address PR feedback on router and thread hydration

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex authored and Julius Marminge committed 2026-02-18 23:54:48 -08:00
1 parent e9d40e4481
commit fe69e96942
12 files changed
+104 -20

No files matched your search

+3 -1
View File
@@ -23,6 +23,7 @@ import {
import { ChevronDownIcon } from "lucide-react";
interface BranchToolbarProps {
threadId: string;
envMode: "local" | "worktree";
onEnvModeChange: (mode: "local" | "worktree") => void;
envLocked: boolean;
@@ -30,6 +31,7 @@ interface BranchToolbarProps {
}
export default function BranchToolbar({
threadId,
envMode,
onEnvModeChange,
envLocked,
@@ -42,7 +44,7 @@ export default function BranchToolbar({
const [isBranchMenuOpen, setIsBranchMenuOpen] = useState(false);
const [branchQuery, setBranchQuery] = useState("");
const activeThread = state.threads.find((thread) => thread.id === state.activeThreadId);
const activeThread = state.threads.find((thread) => thread.id === threadId);
const activeProject = state.projects.find((project) => project.id === activeThread?.projectId);
const activeThreadId = activeThread?.id;
const activeThreadBranch = activeThread?.branch ?? null;
+18 -4
View File
@@ -63,6 +63,7 @@ import {
} from "../session-logic";
import { isScrollContainerNearBottom } from "../chat-scroll";
import { useStore } from "../store";
import { truncateTitle } from "../truncateTitle";
import {
DEFAULT_THREAD_TERMINAL_ID,
MAX_THREAD_TERMINAL_COUNT,
@@ -1129,6 +1130,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
revokePreviewUrls(existing);
return [];
});
setPrompt("");
promptRef.current = "";
setIsSending(false);
setComposerCursor(0);
setComposerHighlightedItemId(null);
dragDepthRef.current = 0;
@@ -1650,7 +1654,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
(composerImagesSnapshot.length > 0
? `Image: ${composerImagesSnapshot[0]?.name ?? "attachment"}`
: "New thread");
const title = titleSeed.length > 50 ? `${titleSeed.slice(0, 50)}...` : titleSeed;
const title = truncateTitle(titleSeed);
dispatch({
type: "SET_THREAD_TITLE",
threadId: activeThread.id,
@@ -1944,6 +1948,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
className={`flex items-center justify-between border-b border-border px-5 ${isElectron ? "drag-region h-[52px]" : "py-3"}`}
>
<ChatHeader
activeThreadId={activeThread.id}
activeThreadTitle={activeThread.title}
activeProjectName={activeProject?.name}
activeProjectScripts={activeProject?.scripts}
@@ -2210,6 +2215,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
{isGitRepo && (
<BranchToolbar
threadId={activeThread.id}
envMode={envMode}
onEnvModeChange={onEnvModeChange}
envLocked={envLocked}
@@ -2286,6 +2292,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
}
interface ChatHeaderProps {
activeThreadId: string;
activeThreadTitle: string;
activeProjectName: string | undefined;
activeProjectScripts: ProjectScript[] | undefined;
@@ -2301,6 +2308,7 @@ interface ChatHeaderProps {
}
const ChatHeader = memo(function ChatHeader({
activeThreadId,
activeThreadTitle,
activeProjectName,
activeProjectScripts,
@@ -2333,8 +2341,12 @@ const ChatHeader = memo(function ChatHeader({
onUpdateScript={onUpdateProjectScript}
/>
)}
{activeProjectName && <OpenInPicker keybindings={keybindings} />}
{activeProjectName && <GitActionsControl api={api} gitCwd={gitCwd} />}
{activeProjectName && (
<OpenInPicker keybindings={keybindings} activeThreadId={activeThreadId} />
)}
{activeProjectName && (
<GitActionsControl api={api} gitCwd={gitCwd} activeThreadId={activeThreadId} />
)}
<Toggle
pressed={diffOpen}
onPressedChange={onToggleDiff}
@@ -2827,8 +2839,10 @@ const ReasoningEffortPicker = memo(function ReasoningEffortPicker(props: {
const OpenInPicker = memo(function OpenInPicker({
keybindings,
activeThreadId,
}: {
keybindings: ResolvedKeybindingsConfig;
activeThreadId: string | null;
}) {
const [lastEditor, setLastEditor] = useState<EditorId>(() => {
const stored = localStorage.getItem(LAST_EDITOR_KEY);
@@ -2855,7 +2869,7 @@ const OpenInPicker = memo(function OpenInPicker({
const api = useNativeApi();
const { state } = useStore();
const activeThread = state.threads.find((t) => t.id === state.activeThreadId);
const activeThread = state.threads.find((t) => t.id === activeThreadId);
const activeProject = state.projects.find((p) => p.id === activeThread?.projectId);
const openInEditor = useCallback(
@@ -38,12 +38,12 @@ import {
gitStatusQueryOptions,
invalidateGitQueries,
} from "~/lib/gitReactQuery";
import { useStore } from "~/store";
import { preferredTerminalEditor, resolvePathLinkTarget } from "~/terminal-links";
interface GitActionsControlProps {
api: NativeApi | undefined;
gitCwd: string | null;
activeThreadId: string | null;
}
function getMenuActionDisabledReason(
@@ -136,9 +136,11 @@ function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
return <InfoIcon className={iconClassName} />;
}
export default function GitActionsControl({ api, gitCwd }: GitActionsControlProps) {
const { state } = useStore();
const activeThreadId = state.activeThreadId;
export default function GitActionsControl({
api,
gitCwd,
activeThreadId,
}: GitActionsControlProps) {
const threadToastData = useMemo(
() => (activeThreadId ? { threadId: activeThreadId } : undefined),
[activeThreadId],
+4 -2
View File
@@ -397,7 +397,9 @@ export default function Sidebar() {
useEffect(() => {
const onWindowKeyDown = (event: KeyboardEvent) => {
const activeThread = state.threads.find((t) => t.id === state.activeThreadId);
const activeThread = routeThreadId
? state.threads.find((thread) => thread.id === routeThreadId)
: undefined;
if (isChatNewLocalShortcut(event, keybindings)) {
const projectId = activeThread?.projectId ?? state.projects[0]?.id;
if (!projectId) return;
@@ -420,7 +422,7 @@ export default function Sidebar() {
return () => {
window.removeEventListener("keydown", onWindowKeyDown);
};
}, [handleNewThread, keybindings, state.activeThreadId, state.projects, state.threads]);
}, [handleNewThread, keybindings, routeThreadId, state.projects, state.threads]);
return (
<aside className="sidebar flex h-full w-[260px] shrink-0 flex-col border-r border-border bg-card">
+9 -2
View File
@@ -1,8 +1,15 @@
import { createRouter } from "@tanstack/react-router";
import { createHashHistory, createRouter } from "@tanstack/react-router";
import { isElectron } from "./env";
import { routeTree } from "./routeTree.gen";
export const router = createRouter({ routeTree });
const useHashHistory =
isElectron && typeof window !== "undefined" && window.location.protocol === "file:";
export const router = createRouter({
routeTree,
...(useHashHistory ? { history: createHashHistory() } : {}),
});
declare module "@tanstack/react-router" {
interface Register {
+5
View File
@@ -67,6 +67,7 @@ function AutoProjectBootstrap() {
threadId: existingThread.id,
});
}
dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true });
return;
}
@@ -82,12 +83,14 @@ function AutoProjectBootstrap() {
cwd: payload.cwd,
model: DEFAULT_MODEL,
expanded: true,
scripts: [],
},
});
dispatch({
type: "ADD_THREAD",
thread: createThread(projectId),
});
dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true });
});
}, [state.projects, state.threads, state.activeThreadId, dispatch]);
@@ -118,8 +121,10 @@ function DesktopProjectBootstrap() {
cwd: project.cwd,
model: DEFAULT_MODEL,
expanded: true,
scripts: project.scripts,
})),
});
dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true });
bootstrappedRef.current = true;
} catch {
if (disposed) return;
+6 -2
View File
@@ -16,6 +16,10 @@ function ChatThreadRouteView() {
return;
}
if (!state.threadsHydrated) {
return;
}
if (!threadExists) {
void navigate({ to: "/", replace: true });
return;
@@ -26,9 +30,9 @@ function ChatThreadRouteView() {
}
dispatch({ type: "SET_ACTIVE_THREAD", threadId });
}, [dispatch, navigate, state.activeThreadId, threadExists, threadId]);
}, [dispatch, navigate, state.activeThreadId, state.threadsHydrated, threadExists, threadId]);
if (!threadId || !threadExists) {
if (!threadId || !state.threadsHydrated || !threadExists) {
return null;
}
+2 -5
View File
@@ -4,6 +4,7 @@ import { type FormEvent, useMemo, useState } from "react";
import { Button } from "../components/ui/button";
import { Textarea } from "../components/ui/textarea";
import { createThread } from "../threadFactory";
import { truncateTitle } from "../truncateTitle";
import { useStore } from "../store";
function ChatIndexRouteView() {
@@ -24,11 +25,7 @@ function ChatIndexRouteView() {
event.preventDefault();
if (!defaultProject) return;
const titleSeed = draft.trim();
const threadTitle =
titleSeed.length > 0
? (titleSeed.length > 50 ? `${titleSeed.slice(0, 50)}...` : titleSeed)
: undefined;
const threadTitle = truncateTitle(draft);
const thread = createThread(
defaultProject.id,
threadTitle
+14
View File
@@ -80,6 +80,7 @@ function makeState(thread: Thread): AppState {
],
threads: [thread],
activeThreadId: thread.id,
threadsHydrated: true,
runtimeMode: "full-access",
diffOpen: false,
diffThreadId: null,
@@ -617,6 +618,7 @@ describe("store reducer thread continuity", () => {
}),
],
activeThreadId: "thread-b",
threadsHydrated: true,
runtimeMode: "full-access",
diffOpen: true,
diffThreadId: "thread-b",
@@ -674,6 +676,7 @@ describe("store reducer thread continuity", () => {
],
threads: [makeThread({ id: "thread-a", projectId: "project-old-a" })],
activeThreadId: "thread-a",
threadsHydrated: true,
runtimeMode: "full-access",
diffOpen: false,
diffThreadId: null,
@@ -725,6 +728,16 @@ describe("store reducer thread continuity", () => {
]);
});
it("marks threads hydration state", () => {
const state = makeState(makeThread());
const next = reducer(state, {
type: "SET_THREADS_HYDRATED",
hydrated: false,
});
expect(next.threadsHydrated).toBe(false);
});
it("deletes a project and all of its threads", () => {
const state: AppState = {
projects: [
@@ -756,6 +769,7 @@ describe("store reducer thread continuity", () => {
}),
],
activeThreadId: "thread-a",
threadsHydrated: true,
runtimeMode: "full-access",
diffOpen: true,
diffThreadId: "thread-a",
+13
View File
@@ -38,6 +38,7 @@ type Action =
| { type: "ADD_PROJECT"; project: Project }
| { type: "SET_PROJECT_SCRIPTS"; projectId: string; scripts: ProjectScript[] }
| { type: "SYNC_PROJECTS"; projects: Project[] }
| { type: "SET_THREADS_HYDRATED"; hydrated: boolean }
| { type: "TOGGLE_PROJECT"; projectId: string }
| { type: "DELETE_PROJECT"; projectId: string }
| { type: "ADD_THREAD"; thread: Thread }
@@ -113,6 +114,7 @@ export interface AppState {
projects: Project[];
threads: Thread[];
activeThreadId: string | null;
threadsHydrated: boolean;
runtimeMode: RuntimeMode;
diffOpen: boolean;
diffThreadId: string | null;
@@ -136,6 +138,7 @@ const initialState: AppState = {
projects: [],
threads: [],
activeThreadId: null,
threadsHydrated: false,
runtimeMode: DEFAULT_RUNTIME_MODE,
diffOpen: false,
diffThreadId: null,
@@ -167,6 +170,7 @@ function readPersistedState(): AppState {
...hydrated,
threads,
activeThreadId,
threadsHydrated: threads.length > 0,
diffOpen: false,
diffThreadId: null,
diffTurnId: null,
@@ -593,6 +597,15 @@ export function reducer(state: AppState, action: Action): AppState {
),
};
case "SET_THREADS_HYDRATED":
if (state.threadsHydrated === action.hydrated) {
return state;
}
return {
...state,
threadsHydrated: action.hydrated,
};
case "SYNC_PROJECTS": {
const previousByCwd = new Map(
state.projects.map((project) => [project.cwd, project] as const),
+17
View File
@@ -0,0 +1,17 @@
import { describe, expect, it } from "vitest";
import { truncateTitle } from "./truncateTitle";
describe("truncateTitle", () => {
it("trims surrounding whitespace", () => {
expect(truncateTitle(" hello world ")).toBe("hello world");
});
it("returns trimmed text when within max length", () => {
expect(truncateTitle("alpha", 10)).toBe("alpha");
});
it("appends ellipsis when text exceeds max length", () => {
expect(truncateTitle("abcdefghij", 5)).toBe("abcde...");
});
});
+7
View File
@@ -0,0 +1,7 @@
export function truncateTitle(text: string, maxLength = 50): string {
const trimmed = text.trim();
if (trimmed.length <= maxLength) {
return trimmed;
}
return `${trimmed.slice(0, maxLength)}...`;
}