Skip to content

Commit 080c263

Browse files
committed
Fix: catalog list renders blank after leaving the Hub and returning
Returning to the Hub showed a blank list (visible on the On Device tab) until you toggled tabs. Made the list virtualizer's scroll element reactive (state-backed in ModelsCatalog via ref callback, passed to VirtualRows) so it binds on mount.
1 parent d21d44e commit 080c263

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

‎studio/frontend/src/features/hub/catalog/models-catalog-lists.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function DiscoverList({
6767
onSelect,
6868
isLoading,
6969
query,
70-
scrollRef,
70+
scrollElement,
7171
sentinelRef,
7272
activeCheckpoint,
7373
searchError,
@@ -89,7 +89,7 @@ export function DiscoverList({
8989
onSelect: (id: string) => void;
9090
isLoading: boolean;
9191
query: string;
92-
scrollRef: RefObject<HTMLDivElement | null>;
92+
scrollElement: HTMLDivElement | null;
9393
sentinelRef: RefObject<HTMLDivElement | null>;
9494
activeCheckpoint: string | null;
9595
searchError: string | null;
@@ -144,7 +144,7 @@ export function DiscoverList({
144144
<>
145145
<VirtualRows
146146
items={discoverRows}
147-
scrollRef={scrollRef}
147+
scrollElement={scrollElement}
148148
getKey={(row) => row.id}
149149
renderRow={(row) => (
150150
<DiscoverModelRow
@@ -191,7 +191,7 @@ export function DownloadedList({
191191
downloadedReady,
192192
inventoryError,
193193
query,
194-
scrollRef,
194+
scrollElement,
195195
activeCheckpoint,
196196
activeGgufVariant,
197197
isDataset,
@@ -206,7 +206,7 @@ export function DownloadedList({
206206
downloadedReady: boolean;
207207
inventoryError: boolean;
208208
query: string;
209-
scrollRef: RefObject<HTMLDivElement | null>;
209+
scrollElement: HTMLDivElement | null;
210210
activeCheckpoint: string | null;
211211
activeGgufVariant: string | null;
212212
isDataset: boolean;
@@ -260,7 +260,7 @@ export function DownloadedList({
260260
return (
261261
<VirtualRows
262262
items={inventoryItems}
263-
scrollRef={scrollRef}
263+
scrollElement={scrollElement}
264264
getKey={(item) => `${item.variant}-${item.row.id}`}
265265
renderRow={(item) => (
266266
<InventoryRow

‎studio/frontend/src/features/hub/catalog/models-catalog-rows.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { HugeiconsIcon } from "@hugeicons/react";
3131
import { useVirtualizer } from "@tanstack/react-virtual";
3232
import {
3333
type ReactNode,
34-
type RefObject,
3534
createContext,
3635
memo,
3736
useCallback,
@@ -720,19 +719,19 @@ const ROW_HEIGHT_PX = 57;
720719

721720
export function VirtualRows<T>({
722721
items,
723-
scrollRef,
722+
scrollElement,
724723
getKey,
725724
renderRow,
726725
}: {
727726
items: readonly T[];
728-
scrollRef: RefObject<HTMLDivElement | null>;
727+
scrollElement: HTMLDivElement | null;
729728
getKey: (item: T, index: number) => string;
730729
renderRow: (item: T) => ReactNode;
731730
}) {
732731
// eslint-disable-next-line react-hooks/incompatible-library
733732
const virtualizer = useVirtualizer({
734733
count: items.length,
735-
getScrollElement: () => scrollRef.current,
734+
getScrollElement: () => scrollElement,
736735
estimateSize: () => ROW_HEIGHT_PX,
737736
overscan: 24,
738737
getItemKey: (index) => getKey(items[index], index),

‎studio/frontend/src/features/hub/catalog/models-catalog.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ export const ModelsCatalog = memo(function ModelsCatalog({
115115
const previousLoadingIntentRef = useRef(loadingIntentCount);
116116
const discoverScrollRef = useRef<HTMLDivElement>(null);
117117
const downloadedScrollRef = useRef<HTMLDivElement>(null);
118+
const [discoverScrollEl, setDiscoverScrollEl] = useState<HTMLDivElement | null>(
119+
null,
120+
);
121+
const [downloadedScrollEl, setDownloadedScrollEl] =
122+
useState<HTMLDivElement | null>(null);
118123
const activeTabRef = useRef(tab);
119124
// Per-tab scroll positions. The visibility-hidden pane should preserve its
120125
// scrollTop in DOM by spec, but some browsers (and our absolute-positioned
@@ -129,10 +134,12 @@ export const ModelsCatalog = memo(function ModelsCatalog({
129134

130135
const setDiscoverScrollNode = useCallback((node: HTMLDivElement | null) => {
131136
discoverScrollRef.current = node;
137+
setDiscoverScrollEl(node);
132138
}, []);
133139

134140
const setDownloadedScrollNode = useCallback((node: HTMLDivElement | null) => {
135141
downloadedScrollRef.current = node;
142+
setDownloadedScrollEl(node);
136143
}, []);
137144

138145
// Synchronously restore the incoming pane's scrollTop and rebind the shared
@@ -285,7 +292,7 @@ export const ModelsCatalog = memo(function ModelsCatalog({
285292
onSelect={onSelect}
286293
isLoading={isLoading}
287294
query={query}
288-
scrollRef={discoverScrollRef}
295+
scrollElement={discoverScrollEl}
289296
sentinelRef={sentinelRef}
290297
activeCheckpoint={activeCheckpoint}
291298
searchError={searchError}
@@ -321,7 +328,7 @@ export const ModelsCatalog = memo(function ModelsCatalog({
321328
downloadedReady={downloadedReady}
322329
inventoryError={inventoryError}
323330
query={query}
324-
scrollRef={downloadedScrollRef}
331+
scrollElement={downloadedScrollEl}
325332
activeCheckpoint={activeCheckpoint}
326333
activeGgufVariant={activeGgufVariant}
327334
isDataset={isDataset}

0 commit comments

Comments
 (0)