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
16 changes: 16 additions & 0 deletions src/lib/hanime1/scraper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ describe('parseVideoList — homepage feed', () => {
expect(result.nextPage).toBe(2); // page 1 always advances to 2 on a multi-page feed
expect(result.lastPage).toBeGreaterThan(1);
});

it('treats an empty page as terminal even when pagination.next markers exist', () => {
// Live-verified shape: past-the-end pages render zero cards but still
// carry pagination.next markers. Trusting them made the infinite query
// walk empty pages forever.
const html = `
<ul class="pagination">
<li><a href="/search?page=1" aria-label="pagination.previous">‹</a></li>
<li><a href="/search?page=2" aria-label="pagination.next">›</a></li>
</ul>
<div id="search-result"></div>`;
const result = parseVideoList(html, 2);
expect(result.items).toEqual([]);
expect(result.nextPage).toBeNull();
expect(result.lastPage).toBeNull();
});
});

describe('parseVideoList — genre search page', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/hanime1/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ export function parseVideoList(html: string, currentPage = 1): ListResult<VideoL
const item = parseCard(m[1], m[2]);
if (item) items.push(item);
});
// The site's pagination lies on past-the-end pages: an empty result page
// still renders `pagination.next` markers (verified live: page 2 of a
// 1-result search — 0 cards, 3 next markers). Trusting it made the
// infinite query walk empty pages forever, refetching on every scroll
// bounce. An empty page is always terminal, whatever the markers claim.
if (items.length === 0) {
return { items, nextPage: null, lastPage: null };
}
const pagination = parsePagination(html, currentPage);
return { items, nextPage: pagination.nextPage, lastPage: pagination.lastPage };
}
Expand Down
Loading