@devries-cameron20 / t3code-1 / commits / 8fc1dade71
Fork 0

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

fix(web): keep settled pagination focused while loading (#35522)

Yash Singh committed Nov 12, 2026 at 12:58 UTC 8fc1dade71e08dacf08bae997d550ff318a95a0e
2 files changed +108 -3
apps/web/src/components/Sidebar.browser.test.tsx
+105 -1
@@ -1,3 +1,7 @@
1 +import appCss from "../index.css?inline";
2 +import type { EnvironmentServerConfig } from "@t3tools/client-runtime/connection";
3 +import * as shelfHooks from "../state/olderSettledShelf";
4 +import { createWorkspaceFocusController, workspaceAreaProps } from "../lib/workspaceFocus";
5 import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
6 import {
7 DEFAULT_CLIENT_SETTINGS,
@@ -16,7 +20,7 @@ import { makeThreadFixture } from "../test-fixtures";
20 import { useHandleNewThread } from "../hooks/useHandleNewThread";
21 import { __setClientSettingsForTests, getClientSettings } from "../hooks/useSettings";
22 import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
19 -import { useProjects, useQuietThreadShells } from "../state/entities";
23 +import { useProjects, useServerConfigs, useQuietThreadShells } from "../state/entities";
24 import { readEnvironmentScope, useEnvironmentScope } from "../state/session";
25 import { useOrchestrationCommand } from "../state/use-orchestration-command";
26 import { useTerminalUiStateStore } from "../terminalUiStateStore";
@@ -26,6 +30,10 @@ import { THREAD_JUMP_HINT_SHOW_DELAY_MS } from "./Sidebar.logic";
30 import { SortableThreadRow } from "./sidebar/SidebarThreadRow";
31 import { SidebarProvider } from "./ui/sidebar";
32
33 +vi.mock(import("../state/olderSettledShelf"), async (original) => {
34 + const actual = await original();
35 + return { ...actual, useOlderSettledShelf: vi.fn(actual.useOlderSettledShelf) };
36 +});
37 vi.mock("../state/entities", { spy: true });
38 vi.mock("../hooks/useHandleNewThread", { spy: true });
39 vi.mock("../hooks/useThreadRouteTarget", { spy: true });
@@ -135,6 +143,7 @@ describe("sidebar render isolation", () => {
143 environmentId: activeProject.environmentId,
144 threadId: threads[0]!.id,
145 };
146 + threads.unshift(threadShell(activeProject.id, 100));
147 vi.mocked(useProjects).mockReturnValue([activeProject]);
148 vi.mocked(useQuietThreadShells).mockReturnValue(threads);
149 vi.mocked(useThreadRouteTarget).mockReturnValue({ kind: "server", threadRef: routeThreadRef });
@@ -247,3 +256,98 @@ describe("sidebar thread rename", () => {
256 },
257 );
258 });
259 +
260 +describe("sidebar settled pagination", () => {
261 + it("keeps the viewport in place when showing more settled threads", async () => {
262 + using stack = new DisposableStack();
263 + const style = document.createElement("style");
264 + style.textContent = appCss;
265 + document.head.append(style);
266 + stack.defer(() => style.remove());
267 + const focusController = createWorkspaceFocusController(document);
268 + stack.defer(() => focusController.dispose());
269 + let loading = false;
270 + const originalShelf = vi.mocked(shelfHooks.useOlderSettledShelf).getMockImplementation()!;
271 + using _shelf = vi.spyOn(shelfHooks, "useOlderSettledShelf").mockImplementation((input) => ({
272 + ...originalShelf(input),
273 + loading,
274 + retry: () => {
275 + loading = true;
276 + },
277 + }));
278 + const activeProject = project("active");
279 + const threads = Array.from({ length: 70 }, (_, index) =>
280 + makeThreadFixture({
281 + environmentId: activeProject.environmentId,
282 + projectId: activeProject.id,
283 + id: ThreadId.make(`settled-${index}`),
284 + title: `Settled thread ${index}`,
285 + settledOverride: "settled",
286 + settledAt: "2026-01-01T00:00:00.000Z",
287 + }),
288 + );
289 + threads.unshift(threadShell(activeProject.id, 100));
290 + vi.mocked(useProjects).mockReturnValue([activeProject]);
291 + vi.mocked(useQuietThreadShells).mockReturnValue(threads);
292 + vi.mocked(useThreadRouteTarget).mockReturnValue({
293 + kind: "server",
294 + threadRef: { environmentId: activeProject.environmentId, threadId: threads[0]!.id },
295 + });
296 + vi.mocked(useHandleNewThread).mockReturnValue({
297 + activeDraftThread: null,
298 + activeThread: null,
299 + defaultProjectRef: {
300 + environmentId: activeProject.environmentId,
301 + projectId: activeProject.id,
302 + },
303 + defaultProjectFallbackReady: true,
304 + handleNewThread: vi.fn().mockResolvedValue(null),
305 + routeDraftId: null,
306 + routeThreadRef: { environmentId: activeProject.environmentId, threadId: threads[0]!.id },
307 + });
308 + vi.mocked(useServerConfigs).mockReturnValue(
309 + new Map([
310 + [
311 + activeProject.environmentId,
312 + {
313 + scratchWorkspaceRoot: null,
314 + shellThreadFamilies: false,
315 + } as unknown as EnvironmentServerConfig,
316 + ],
317 + ]),
318 + );
319 + await using screen = await render(
320 + <SidebarProvider
321 + {...workspaceAreaProps("sidebar", 0, "Threads")}
322 + style={{ height: 400, minHeight: 400 }}
323 + >
324 + <Sidebar routeReveal={{ observedKey: null, pendingKey: null }} />
325 + </SidebarProvider>,
326 + );
327 + const shelf = screen.container.querySelector<HTMLElement>(
328 + '[data-sidebar-row="shelf:settled"]',
329 + )!;
330 + if (shelf.getAttribute("aria-expanded") === "false") await act(() => shelf.click());
331 + const more = screen.getByRole("button", { name: "Show 25 more", exact: true });
332 + await expect.element(more).toBeInTheDocument();
333 + const moreButton = more.element() as HTMLButtonElement;
334 + const viewport = moreButton.closest<HTMLElement>('[data-slot="scroll-area-viewport"]')!;
335 + viewport.style.height = "300px";
336 + viewport.style.maxHeight = "300px";
337 + moreButton.scrollIntoView({ block: "nearest" });
338 + const before = viewport.scrollTop;
339 + expect(before).toBeGreaterThan(0);
340 + moreButton.focus({ preventScroll: true });
341 + await act(() => moreButton.click());
342 + await expect
343 + .element(screen.getByRole("button", { name: "Loading", exact: true }))
344 + .toBeInTheDocument();
345 + await expect
346 + .element(screen.getByRole("button", { name: "Loading", exact: true }))
347 + .toHaveFocus();
348 + expect(viewport.scrollTop).toBe(before);
349 + const loadedRows = screen.container.querySelectorAll("[data-thread-item]").length;
350 + await act(() => moreButton.click());
351 + expect(screen.container.querySelectorAll("[data-thread-item]")).toHaveLength(loadedRows);
352 + });
353 +});
apps/web/src/components/Sidebar.tsx
+3 -2
@@ -3644,12 +3644,13 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
3644 type="button"
3645 data-sidebar-row="settled:more"
3646 data-sidebar-parent="shelf:settled"
3647 - disabled={olderSettledShelf.loading}
3647 + aria-disabled={olderSettledShelf.loading}
3648 onClick={() => {
3649 + if (olderSettledShelf.loading) return;
3650 olderSettledShelf.retry();
3651 showMoreSettled();
3652 }}
3652 - className="flex h-9 w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 text-left text-sm text-sidebar-muted-foreground hover:bg-sidebar-row-hover hover:text-sidebar-foreground disabled:cursor-default"
3653 + className="flex h-9 w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 text-left text-sm text-sidebar-muted-foreground hover:bg-sidebar-row-hover hover:text-sidebar-foreground aria-disabled:cursor-default"
3654 >
3655 {/* Plus means "add", so revealing more uses a chevron. */}
3656 <ChevronDownIcon aria-hidden className="size-4 shrink-0" />