Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/components/assets/AssetCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
:src="asset.thumbnail_url"
alt=""
draggable="false"
loading="lazy"
decoding="async"
class="size-full object-cover"
/>
<div v-else :class="['grid size-full place-items-center', previewStyle.tile]">
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/components/common/FileTypeIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
'grid place-items-center',
]"
>
<img v-if="thumbnailUrl" :src="thumbnailUrl" :alt="alt" class="size-full object-cover" />
<img
v-if="thumbnailUrl"
:src="thumbnailUrl"
:alt="alt"
loading="lazy"
decoding="async"
class="size-full object-cover"
/>
<span v-else :class="[style.icon, iconClass]" aria-hidden="true" />
</div>
</template>
Expand Down
24 changes: 21 additions & 3 deletions frontend/src/components/projects/useProjectBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export function useProjectBrowser(
const tag = ref<string | null>(null)
const sort = ref<AssetSort>({ field: 'creation', order: 'desc' })
const limit = ref(PAGE_SIZE)
const loadingMore = ref(false)
const reachedEnd = ref(false)
const selection = ref<string[]>([])
const preview = ref<{ asset: Asset; url: string } | null>(null)
const view = ref<'grid' | 'list'>(storedView())
Expand Down Expand Up @@ -141,13 +143,21 @@ export function useProjectBrowser(
}
return counts
})
const hasMore = computed(() => assets.value.length < total.value)
const hasMore = computed(() => !reachedEnd.value && assets.value.length < total.value)
const hasProcessing = computed(() => assets.value.some((asset) => asset.status === 'Processing'))

watch(searchInput, (value) => {
clearTimeout(debounceTimer)
debounceTimer = setTimeout(() => (search.value = value.trim()), 250)
})
watch(
() => assetsCall.loading,
(loading) => {
if (loading) return
loadingMore.value = false
reachedEnd.value = assets.value.length < limit.value
},
)
Comment on lines +153 to +160

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Failed Loads Disable Scrolling

When a load-more request fails, staleOnError keeps the previously loaded rows while limit has already increased. When loading finishes, this watcher compares that stale row count with the new limit and marks the list as complete. This makes hasMore false and removes the only infinite-scroll sentinel even though total still indicates that more assets exist, so scrolling cannot retry the failed request.

Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/components/projects/useProjectBrowser.ts
Line: 153-160

Comment:
**Failed Loads Disable Scrolling**

When a load-more request fails, `staleOnError` keeps the previously loaded rows while `limit` has already increased. When loading finishes, this watcher compares that stale row count with the new limit and marks the list as complete. This makes `hasMore` false and removes the only infinite-scroll sentinel even though `total` still indicates that more assets exist, so scrolling cannot retry the failed request.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

watch([currentProject, currentFolder, category, tag, search, sort], resetList, { deep: true })
watch(view, (value) => localStorage.setItem('vms_asset_view', value))
watch(hasProcessing, configurePolling, { immediate: true })
Expand Down Expand Up @@ -303,9 +313,17 @@ export function useProjectBrowser(

function resetList() {
limit.value = PAGE_SIZE
loadingMore.value = false
reachedEnd.value = false
selection.value = []
}

function loadMore() {
if (assetsCall.loading || !hasMore.value) return
loadingMore.value = true
limit.value += PAGE_SIZE
}

return {
project,
folders,
Expand All @@ -322,6 +340,7 @@ export function useProjectBrowser(
folderCounts,
selectedAssets,
hasMore,
loadingMore,
searchInput,
category,
tag,
Expand All @@ -333,14 +352,13 @@ export function useProjectBrowser(
hasNextPreview,
showPreviousPreview: () => stepPreview(-1),
showNextPreview: () => stepPreview(1),
limit,
openAsset,
moveAssets,
moveFolder,
deleteFolder,
reloadAssets,
reloadAll,
loadMore: () => (limit.value += PAGE_SIZE),
loadMore,
}
}

Expand Down
40 changes: 40 additions & 0 deletions frontend/src/composables/useInfiniteScroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { onScopeDispose, watch, type Ref } from 'vue'

export function useInfiniteScroll(
target: Ref<HTMLElement | null>,
busy: Ref<boolean>,
canLoad: () => boolean,
onLoadMore: () => void,
) {
let observer: IntersectionObserver | undefined
let intersecting = false

function maybeLoad() {
if (intersecting && !busy.value && canLoad()) onLoadMore()
}

watch(
target,
(el) => {
observer?.disconnect()
observer = undefined
intersecting = false
if (!el) return
observer = new IntersectionObserver(
(entries) => {
intersecting = entries[entries.length - 1]?.isIntersecting ?? false
maybeLoad()
},
{ rootMargin: '600px 0px' },
)
observer.observe(el)
},
{ immediate: true },
)

watch(busy, (now, before) => {
if (before && !now) maybeLoad()
})

onScopeDispose(() => observer?.disconnect())
}
17 changes: 9 additions & 8 deletions frontend/src/pages/ProjectDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,9 @@
@drop-assets="(names, target) => moveAssets(names, target)"
@drop-folder="(name, target) => moveFolder(name, target)"
/>
<div v-if="hasMore" class="flex justify-center pt-6">
<Button
label="Load more"
variant="ghost"
:loading="assetsCall.loading"
@click="loadMore"
/>
<div v-if="hasMore" ref="sentinel" class="pt-3">
<SkeletonCards v-if="loadingMore && view === 'grid'" :count="4" media />
<SkeletonLines v-else-if="loadingMore" :lines="3" />
</div>
</template>
<EmptyState
Expand Down Expand Up @@ -271,7 +267,7 @@
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { computed, ref } from 'vue'
import {
Button,
Dropdown,
Expand Down Expand Up @@ -303,6 +299,7 @@ import { serverMessage } from '@/lib/format'
import ShareProjectPanel from '@/components/projects/ShareProjectPanel.vue'
import { useProjectBrowser } from '@/components/projects/useProjectBrowser'
import { useProjectPageActions } from '@/components/projects/useProjectPageActions'
import { useInfiniteScroll } from '@/composables/useInfiniteScroll'
import { useUploadTarget } from '@/composables/usePasteUpload'
import SkeletonLines from '@/components/common/SkeletonLines.vue'
import SkeletonCards from '@/components/common/SkeletonCards.vue'
Expand Down Expand Up @@ -336,6 +333,7 @@ const {
folderCounts,
selectedAssets,
hasMore,
loadingMore,
searchInput,
category,
tag,
Expand All @@ -355,6 +353,9 @@ const {
reloadAll,
loadMore,
} = browser

const sentinel = ref<HTMLElement | null>(null)
useInfiniteScroll(sentinel, loadingMore, () => hasMore.value, loadMore)
const {
createFolderOpen,
renameFolderOpen,
Expand Down
Loading