Skip to content

Commit 5a38e6b

Browse files
t3dotggclaude
andauthored
fix(web): model picker no longer jumps when switching providers (#25358)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 2763bbe commit 5a38e6b

1 file changed

Lines changed: 43 additions & 9 deletions

File tree

‎apps/web/src/components/chat/ModelPickerContent.tsx‎

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ function adjacentModelPickerProvider(input: {
163163

164164
const EMPTY_MODEL_JUMP_LABELS = new Map<string, string>();
165165
const MODEL_LIST_ESTIMATED_ITEM_SIZE = 52;
166+
// Rendered heights in `--spacing` units. Chrome is the search box and list padding, plus a 1px border.
167+
const ONE_LINE_ROW_UNITS = 8;
168+
const TWO_LINE_ROW_UNITS = { classic: 11.25, redesign: 12 };
169+
const ROW_SEPARATOR_UNITS = 0.5;
170+
const LIST_CHROME_UNITS = 15.5;
166171

167172
function ModelListSeparator() {
168173
return <div className="h-0.5" />;
@@ -259,10 +264,6 @@ function ModelPickerList({
259264
}) {
260265
const [showTopScrollFade, setShowTopScrollFade] = useState(false);
261266
const [showBottomScrollFade, setShowBottomScrollFade] = useState(false);
262-
const [contentSize, setContentSize] = useState(
263-
() => itemKeys.length * MODEL_LIST_ESTIMATED_ITEM_SIZE,
264-
);
265-
useLayoutEffect(() => listRef.current?.getState().listen("totalSize", setContentSize), [listRef]);
266267
const updateScrollFades = () => {
267268
const scrollElement = listRef.current?.getScrollableNode();
268269
if (!(scrollElement instanceof HTMLElement)) {
@@ -297,10 +298,10 @@ function ModelPickerList({
297298

298299
return (
299300
<div
300-
className="relative min-h-0 overflow-hidden pr-px"
301-
style={{
302-
height: itemKeys.length === 0 ? 0 : `calc(${contentSize}px + var(--spacing) * 5)`,
303-
}}
301+
className={cn(
302+
"relative min-h-0 overflow-hidden pr-px",
303+
itemKeys.length > 0 ? "flex-1" : "h-0",
304+
)}
304305
>
305306
<ComboboxListVirtualized>
306307
<LegendList<string>
@@ -578,6 +579,33 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
578579
// Inside one provider's tab the provider line repeats the selected rail icon on every row.
579580
const redesign = useClientSettings((s) => s.redesignEnabled);
580581
const rowsMixProviders = !redesign || isSearching || selectedInstanceId === "favorites";
582+
// Fit the tallest tab so switching tabs never resizes the popup and moves the rail under the cursor.
583+
const tallestTabUnits = (() => {
584+
const unitsByTab = new Map<ProviderInstanceId | "favorites", number>();
585+
const addRow = (tab: ProviderInstanceId | "favorites", twoLine: boolean) => {
586+
const rowUnits = twoLine
587+
? TWO_LINE_ROW_UNITS[redesign ? "redesign" : "classic"]
588+
: ONE_LINE_ROW_UNITS;
589+
const previous = unitsByTab.get(tab);
590+
unitsByTab.set(
591+
tab,
592+
previous === undefined ? rowUnits : previous + ROW_SEPARATOR_UNITS + rowUnits,
593+
);
594+
};
595+
const tabsWithLegacyRow = new Set<ProviderInstanceId>();
596+
for (const model of flatModels) {
597+
if (!matchesLockedProvider(model)) continue;
598+
const isFavorite = favoritesSet.has(providerModelKey(model.instanceId, model.slug));
599+
if (isFavorite) addRow("favorites", true);
600+
if (model.isLegacy && !isFavorite) {
601+
tabsWithLegacyRow.add(model.instanceId);
602+
} else {
603+
addRow(model.instanceId, !redesign || Boolean(model.subProvider));
604+
}
605+
}
606+
for (const instanceId of tabsWithLegacyRow) addRow(instanceId, true);
607+
return Math.max(0, ...unitsByTab.values());
608+
})();
581609
const lockedDisabledInstanceIds = (() => {
582610
if (!isLocked) {
583611
return undefined;
@@ -799,7 +827,13 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
799827
<div
800828
ref={pickerContentRef}
801829
className="relative flex max-h-86.5 w-screen max-w-90 flex-row overflow-hidden"
802-
style={isSearching ? { height: searchHeight } : undefined}
830+
style={
831+
isSearching
832+
? { height: searchHeight }
833+
: {
834+
minHeight: `min(calc(var(--spacing) * ${tallestTabUnits + LIST_CHROME_UNITS} + 1px), calc(var(--spacing) * 86.5))`,
835+
}
836+
}
803837
data-model-picker-content="true"
804838
>
805839
{showSidebar && (

0 commit comments

Comments
 (0)