fix: preserve keyset totals when count is skipped

This commit is contained in:
Jonathan Finley 2026-03-13 23:39:53 -04:00
parent 23dfde8d34
commit 9a6591fa59
2 changed files with 42 additions and 1 deletions

View file

@ -350,7 +350,10 @@ export default {
this.pageCursors = { 0: null }
},
updateVisibleBrowseRange(totalEntities = this.serverTotalEntities) {
this.serverTotalEntities = Number(totalEntities) || 0
const hasExplicitTotal = totalEntities !== null && totalEntities !== undefined
if (hasExplicitTotal) {
this.serverTotalEntities = Number(totalEntities) || 0
}
const visibleTotalEntities = this.deepScrollBlocked
? Math.min(this.serverTotalEntities, this.maxOffsetPages * this.booksPerFetch)

View file

@ -166,6 +166,44 @@ describe('LazyBookshelf', () => {
})
})
it('preserves visible totals when keyset follow-up responses omit total', () => {
const requestUrls = []
const getStub = cy.stub().callsFake((url) => {
requestUrls.push(url)
if (requestUrls.length === 1) {
return Promise.resolve({
results: [{ id: 'item-1', mediaType: 'book', media: { metadata: { title: 'Alpha' } } }],
total: 4,
nextCursor: 'cursor-1',
paginationMode: 'keyset',
isCountDeferred: true
})
}
return Promise.resolve({
results: [{ id: 'item-2', mediaType: 'book', media: { metadata: { title: 'Beta' } } }],
total: null,
nextCursor: null,
paginationMode: 'keyset',
isCountDeferred: true
})
})
mountBookshelf(getStub, { initialPagesToLoad: 1 }).then(({ wrapper }) => {
cy.wrap(null)
.then(() => wrapper.vm.loadPage(1))
.then(() => {
expect(wrapper.vm.serverTotalEntities).to.equal(4)
expect(wrapper.vm.totalEntities).to.equal(4)
expect(wrapper.vm.totalShelves).to.equal(4)
expect(wrapper.vm.entities).to.have.length(4)
})
})
cy.get('[id^="shelf-"]').should('have.length', 4)
})
it('keeps offset fallback mode explicit and caps deep endless scroll', () => {
const requestUrls = []
const getStub = cy.stub().callsFake((url) => {