The best way to control Claude Code, Codex and more from any computer or phone
fix(web): settled shelf no longer crashes with several projects filtered (#27231)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
Jagrat committed
Nov 1, 2026 at 16:42 UTC
e2ad07abad1ddfe3a763d373e4bde21c140045eb
4 files changed
+65
-7
apps/mobile/src/state/olderSettledShelf.ts
+6
-4
@@ -3,6 +3,7 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/model
3
import {
4
isListedSettledThread,
5
settledShelfFrontier,
6
+ sortOlderSettledScopes,
7
unloadedOlderSettledCount,
8
wantedOlderSettledPages,
9
type OlderSettled,
@@ -10,7 +11,7 @@ import {
11
} from "@t3tools/client-runtime/state/threads";
12
import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
13
import { Atom } from "effect/reactivity";
13
-import { useEffect, useState } from "react";
14
+import { useEffect, useMemo, useState } from "react";
15
16
import { appAtomRegistry } from "./atom-registry";
17
import { olderSettledThreads, threadFamilies } from "./threads";
@@ -30,10 +31,11 @@ export function useOlderSettledShelf(input: {
31
/** Rows the shelf shows; pages are read until it lists that many. */
32
readonly visibleCount: number;
33
}) {
33
- const scopeKey = JSON.stringify(input.scopes);
34
+ const scopes = useMemo(() => sortOlderSettledScopes(input.scopes), [input.scopes]);
35
+ const scopeKey = JSON.stringify(scopes);
36
const [requested, setRequested] = useState({ scopeKey, pages: NO_PAGES });
37
const pages = requested.scopeKey === scopeKey && input.expanded ? requested.pages : NO_PAGES;
36
- const shelfScopes = input.scopes.map((scope) => ({
38
+ const shelfScopes = scopes.map((scope) => ({
39
scope,
40
pages: pages.get(scope.environmentId) ?? 0,
41
}));
@@ -70,7 +72,7 @@ export function useOlderSettledShelf(input: {
72
isListed: (thread: EnvironmentThreadShell) => isListedSettledThread(thread.source, frontier),
73
/** Older settled threads in scope that are not local; add it to the local Settled rows. */
74
unloadedCount: (threads: ReadonlyArray<EnvironmentThreadShell>) =>
73
- unloadedOlderSettledCount({ olderSettled: olderOf, scopes: input.scopes, threads }),
75
+ unloadedOlderSettledCount({ olderSettled: olderOf, scopes, threads }),
76
loading: loaded.some(({ scope }) => pagesOf(scope.environmentId)?.status === "pending"),
77
failed: loaded.some(({ scope }) => pagesOf(scope.environmentId)?.status === "failed"),
78
retry: () => {
apps/web/src/state/olderSettledShelf.browser.test.tsx
new
+39
@@ -0,0 +1,39 @@
1
+import type { OlderSettledScope } from "@t3tools/client-runtime/state/threads";
2
+import { EnvironmentId, ProjectId } from "@t3tools/contracts";
3
+import { describe, expect, it } from "vite-plus/test";
4
+import { userEvent } from "vite-plus/test/browser";
5
+
6
+import { render } from "../../test/render";
7
+import { useOlderSettledShelf } from "./olderSettledShelf";
8
+
9
+const environmentId = EnvironmentId.make("env-a");
10
+const first = ProjectId.make("project-a");
11
+const second = ProjectId.make("project-b");
12
+
13
+function Shelf(props: { readonly scopes: ReadonlyArray<OlderSettledScope> }) {
14
+ const shelf = useOlderSettledShelf({ scopes: props.scopes, expanded: true, visibleCount: 0 });
15
+ return (
16
+ <>
17
+ <output>{shelf.pages.get(environmentId) ?? 0}</output>
18
+ <button type="button" onClick={() => shelf.grow(new Map([[environmentId, 1]]))}>
19
+ Grow
20
+ </button>
21
+ </>
22
+ );
23
+}
24
+
25
+describe("useOlderSettledShelf", () => {
26
+ it("keeps requested pages when the scope's projects reorder", async () => {
27
+ await using screen = await render(
28
+ <Shelf scopes={[{ environmentId, projectIds: [first, second] }]} />,
29
+ // A bare hook host; nothing here links or navigates.
30
+ { router: false },
31
+ );
32
+ await userEvent.click(screen.getByRole("button", { name: "Grow" }));
33
+ await expect.element(screen.getByRole("status")).toHaveTextContent("1");
34
+
35
+ // Loading a page can reorder the sidebar's projects; the shelf must not drop its pages.
36
+ await screen.rerender(<Shelf scopes={[{ environmentId, projectIds: [second, first] }]} />);
37
+ await expect.element(screen.getByRole("status")).toHaveTextContent("1");
38
+ });
39
+});
apps/web/src/state/olderSettledShelf.ts
+5
-3
@@ -3,6 +3,7 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/model
3
import {
4
isListedSettledThread,
5
settledShelfFrontier,
6
+ sortOlderSettledScopes,
7
unloadedOlderSettledCount,
8
wantedOlderSettledPages,
9
type OlderSettledScope,
@@ -27,10 +28,11 @@ export function useOlderSettledShelf(input: {
28
/** Rows the shelf shows; pages are read until it lists that many. */
29
readonly visibleCount: number;
30
}) {
30
- const scopeKey = JSON.stringify(input.scopes);
31
+ const scopes = sortOlderSettledScopes(input.scopes);
32
+ const scopeKey = JSON.stringify(scopes);
33
const [requested, setRequested] = useState({ scopeKey, pages: NO_PAGES });
34
const pages = requested.scopeKey === scopeKey && input.expanded ? requested.pages : NO_PAGES;
33
- const shelfScopes = input.scopes.map((scope) => ({
35
+ const shelfScopes = scopes.map((scope) => ({
36
scope,
37
pages: pages.get(scope.environmentId) ?? 0,
38
}));
@@ -67,7 +69,7 @@ export function useOlderSettledShelf(input: {
69
isListed: (thread: EnvironmentThreadShell) => isListedSettledThread(thread.source, frontier),
70
/** Older settled threads in scope that are not local; add it to the local Settled rows. */
71
unloadedCount: (threads: ReadonlyArray<EnvironmentThreadShell>) =>
70
- unloadedOlderSettledCount({ olderSettled: olderOf, scopes: input.scopes, threads }),
72
+ unloadedOlderSettledCount({ olderSettled: olderOf, scopes, threads }),
73
loading: loaded.some(({ scope }) => pagesOf(scope.environmentId)?.status === "pending"),
74
failed: loaded.some(({ scope }) => pagesOf(scope.environmentId)?.status === "failed"),
75
retry: () => {
packages/client-runtime/src/state/olderSettledThreads.ts
+15
@@ -63,6 +63,21 @@ export interface OlderSettledShelfEnvironment {
63
readonly pages: OlderSettledPages;
64
}
65
66
+/**
67
+ * Scopes in one order, so a shelf keyed on them keeps its pages when the caller's project order
68
+ * changes. Loading a page can reorder the sidebar's projects, which would otherwise drop the page.
69
+ */
70
+export function sortOlderSettledScopes(
71
+ scopes: ReadonlyArray<OlderSettledScope>,
72
+): ReadonlyArray<OlderSettledScope> {
73
+ return scopes
74
+ .map((scope) => ({
75
+ environmentId: scope.environmentId,
76
+ projectIds: scope.projectIds === null ? null : [...scope.projectIds].sort(),
77
+ }))
78
+ .sort((left, right) => left.environmentId.localeCompare(right.environmentId));
79
+}
80
+
81
/**
82
* Changes whenever the older count can: any removal (by largest sequence, so a repeat counts), an
83
* older row that arrives or changes, or an old row arriving outside the set (unsettled). Threads