Skip to content

Commit a80a939

Browse files
Fix: virtual grid scrolling bug when container is rendered with emtpy items (switching tabs) (#4251)
1 parent 8e2d7ca commit a80a939

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/components/common/VirtualGrid.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,21 @@ whenever(
9292
const updateItemSize = () => {
9393
if (container.value) {
9494
const firstItem = container.value.querySelector('[data-virtual-grid-item]')
95-
itemHeight.value = firstItem?.clientHeight || defaultItemHeight
96-
itemWidth.value = firstItem?.clientWidth || defaultItemWidth
95+
96+
// Don't update item size if the first item is not rendered yet
97+
if (!firstItem?.clientHeight || !firstItem?.clientWidth) return
98+
99+
if (itemHeight.value !== firstItem.clientHeight) {
100+
itemHeight.value = firstItem.clientHeight
101+
}
102+
if (itemWidth.value !== firstItem.clientWidth) {
103+
itemWidth.value = firstItem.clientWidth
104+
}
97105
}
98106
}
99107
const onResize = debounce(updateItemSize, resizeDebounce)
100108
watch([width, height], onResize, { flush: 'post' })
109+
whenever(() => items, updateItemSize)
101110
onBeforeUnmount(() => {
102111
onResize.cancel() // Clear pending debounced calls
103112
})

src/components/dialog/content/manager/ManagerDialogContent.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ const {
219219
const filterMissingPacks = (packs: components['schemas']['Node'][]) =>
220220
packs.filter((pack) => !comfyManagerStore.isPackInstalled(pack.id))
221221
222-
whenever(selectedTab, () => {
223-
pageNumber.value = 0
224-
})
225-
226222
const isUpdateAvailableTab = computed(
227223
() => selectedTab.value?.id === ManagerTab.UpdateAvailable
228224
)
@@ -468,9 +464,10 @@ let gridContainer: HTMLElement | null = null
468464
onMounted(() => {
469465
gridContainer = document.getElementById('results-grid')
470466
})
471-
watch(searchQuery, () => {
467+
watch([searchQuery, selectedTab], () => {
472468
gridContainer ??= document.getElementById('results-grid')
473469
if (gridContainer) {
470+
pageNumber.value = 0
474471
gridContainer.scrollTop = 0
475472
}
476473
})

0 commit comments

Comments
 (0)