The best way to control Claude Code, Codex and more from any computer or phone
fix(web): toggling a model's visibility no longer jumps the model list (#31637)
Julius Marminge committed
Nov 20, 2026 at 17:36 UTC
6357d17a4963e546aa71a6094ae2b3d3bb04edb1
2 files changed
+71
-8
apps/web/src/components/settings/ProviderModelsSection.browser.test.tsx
+51
-2
@@ -1,7 +1,12 @@
1
-import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
2
-import type { ComponentProps } from "react";
1
+import {
2
+ ProviderDriverKind,
3
+ ProviderInstanceId,
4
+ type ServerProviderModel,
5
+} from "@t3tools/contracts";
6
+import { type ComponentProps, useState } from "react";
7
import { expect, it, vi } from "vite-plus/test";
8
import { userEvent } from "vite-plus/test/browser";
9
+import "~/index.css";
10
11
import { act, render } from "../../../test/render";
12
import { ProviderModelsSection } from "./ProviderModelsSection";
@@ -98,3 +103,47 @@ it("keeps changes typed while an earlier save succeeds", async () => {
103
await act(() => saves[1]!(true));
104
await expect.element(displayName).not.toBeInTheDocument();
105
});
106
+
107
+const models: ServerProviderModel[] = ["a", "b", "c", "d", "e"].map((id) => ({
108
+ slug: `model-${id}`,
109
+ name: `Model ${id.toUpperCase()}`,
110
+ isCustom: false,
111
+ capabilities: null,
112
+}));
113
+
114
+function StatefulModelsSection() {
115
+ const [hiddenModels, setHiddenModels] = useState<ReadonlyArray<string>>(
116
+ models.map((model) => model.slug),
117
+ );
118
+ return section({ models, hiddenModels, onHiddenModelsChange: setHiddenModels });
119
+}
120
+
121
+const rowSlugs = (container: HTMLElement) =>
122
+ Array.from(container.querySelectorAll<HTMLElement>("[data-model-slug]"), (row) =>
123
+ row.getAttribute("data-model-slug"),
124
+ );
125
+
126
+it("keeps a model in place when it is shown again after disabling all", async () => {
127
+ await using screen = await render(<StatefulModelsSection />);
128
+ const order = models.map((model) => model.slug);
129
+ expect(rowSlugs(screen.container)).toEqual(order);
130
+
131
+ const toggle = screen.getByRole("switch", { name: "Show Model C in the model picker" });
132
+ await toggle.click();
133
+ await expect.element(toggle).toBeChecked();
134
+
135
+ expect(rowSlugs(screen.container)).toEqual(order);
136
+});
137
+
138
+it("regroups the list when all models are disabled and enabled again", async () => {
139
+ await using screen = await render(<StatefulModelsSection />);
140
+ const toggle = screen.getByRole("switch", { name: "Show Model C in the model picker" });
141
+ await toggle.click();
142
+ await expect.element(toggle).toBeChecked();
143
+
144
+ await screen.getByRole("button", { name: "Disable all" }).click();
145
+ await screen.getByRole("button", { name: "Enable all" }).click();
146
+ await expect.element(toggle).toBeChecked();
147
+
148
+ expect(rowSlugs(screen.container)).toEqual(models.map((model) => model.slug));
149
+});
apps/web/src/components/settings/ProviderModelsSection.tsx
+20
-6
@@ -150,6 +150,10 @@ export function ProviderModelsSection({
150
const editAttemptRef = useRef(0);
151
const listRef = useRef<HTMLDivElement>(null);
152
const scrollToSlugRef = useRef<string | null>(null);
153
+ // A row toggled on its own keeps its placement until a bulk toggle or remount regroups the list.
154
+ const [heldPlacements, setHeldPlacements] = useState<ReadonlyMap<string, boolean>>(
155
+ () => new Map(),
156
+ );
157
const hiddenModelSet = new Set(hiddenModels);
158
const favoriteModelSet = new Set(favoriteModels);
159
const reportedSlugs = new Set(models.map((model) => model.slug));
@@ -158,9 +162,15 @@ export function ProviderModelsSection({
162
const unreportedFavoriteModels = favoriteModels.flatMap((slug): ServerProviderModel[] =>
163
reportedSlugs.has(slug) ? [] : [{ slug, name: slug, isCustom: false, capabilities: null }],
164
);
161
- const displayModels = groupModelsForDisplay([...models, ...unreportedFavoriteModels], {
165
+ const listedModels = [...models, ...unreportedFavoriteModels];
166
+ const placedHiddenSet = new Set(
167
+ listedModels
168
+ .filter((model) => heldPlacements.get(model.slug) ?? hiddenModelSet.has(model.slug))
169
+ .map((model) => model.slug),
170
+ );
171
+ const displayModels = groupModelsForDisplay(listedModels, {
172
favoriteModels: favoriteModelSet,
163
- hiddenModels: hiddenModelSet,
173
+ hiddenModels: placedHiddenSet,
174
modelOrder,
175
});
176
const favoriteCount = displayModels.filter((model) => favoriteModelSet.has(model.slug)).length;
@@ -266,6 +276,9 @@ export function ProviderModelsSection({
276
277
const setHidden = (slug: string, hidden: boolean) => {
278
if (!canWritePreferences || hidden === hiddenModelSet.has(slug)) return;
279
+ setHeldPlacements((current) =>
280
+ current.has(slug) ? current : new Map(current).set(slug, hiddenModelSet.has(slug)),
281
+ );
282
onHiddenModelsChange(
283
hidden ? [...hiddenModels, slug] : hiddenModels.filter((model) => model !== slug),
284
[slug],
@@ -280,7 +293,7 @@ export function ProviderModelsSection({
293
const groupOf = (model: (typeof displayModels)[number]) =>
294
favoriteModelSet.has(model.slug)
295
? "favorite"
283
- : !model.isCustom && hiddenModelSet.has(model.slug)
296
+ : !model.isCustom && placedHiddenSet.has(model.slug)
297
? "hidden"
298
: "visible";
299
const handleMove = (slug: string, direction: -1 | 1) => {
@@ -355,12 +368,13 @@ export function ProviderModelsSection({
368
type="button"
369
size="xs"
370
variant="ghost-muted"
358
- onClick={() =>
371
+ onClick={() => {
372
+ setHeldPlacements(new Map());
373
onHiddenModelsChange(
374
nextHiddenModelsForBulkToggle(models, hiddenModels),
375
builtInModels.map((model) => model.slug),
362
- )
363
- }
376
+ );
377
+ }}
378
>
379
{allBuiltInModelsHidden ? gt("Enable all") : gt("Disable all")}
380
</Button>