fix: adjust historyOffset when removing items to prevent skipping unseen rows

Addresses review feedback: removeHistoryItems() now decrements
historyOffset by the number of removed items so the next
loadMoreHistory() call does not skip unseen history rows.

https://github.com/Comfy-Org/ComfyUI_frontend/pull/9005#discussion_r2044741070
This commit is contained in:
bymyself
2026-04-10 00:04:22 -07:00
parent 2148f15caa
commit 972b14fdd4
2 changed files with 24 additions and 0 deletions

View File

@@ -438,6 +438,26 @@ describe('assetsStore - Refactored (Option A)', () => {
expect(ids).not.toContain('prompt_3')
})
it('should adjust pagination offset after deletion', async () => {
const mockHistory = Array.from({ length: 200 }, (_, i) =>
createMockJobItem(i)
)
vi.mocked(api.getHistory).mockResolvedValueOnce(mockHistory)
await store.updateHistory()
// Delete 3 items — offset should shift from 200 to 197
store.removeHistoryItems(['prompt_1', 'prompt_3', 'prompt_5'])
expect(store.historyAssets).toHaveLength(197)
const nextBatch = Array.from({ length: 200 }, (_, i) =>
createMockJobItem(200 + i)
)
vi.mocked(api.getHistory).mockResolvedValueOnce(nextBatch)
await store.loadMoreHistory()
expect(api.getHistory).toHaveBeenLastCalledWith(200, { offset: 197 })
})
it('should allow re-inserting a removed item on next updateHistory', async () => {
const mockHistory = Array.from({ length: 3 }, (_, i) =>
createMockJobItem(i)

View File

@@ -157,10 +157,14 @@ export const useAssetsStore = defineStore('assets', () => {
function removeHistoryItems(ids: string[]) {
const idSet = new Set(ids)
const removedCount = allHistoryItems.value.filter((item) =>
idSet.has(item.id)
).length
allHistoryItems.value = allHistoryItems.value.filter(
(item) => !idSet.has(item.id)
)
ids.forEach((id) => loadedIds.delete(id))
historyOffset.value = Math.max(0, historyOffset.value - removedCount)
historyAssets.value = allHistoryItems.value
}