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
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,69 @@ describe('WebsiteViewDialog', () => {
});
});

it('retries a failed later page without gaps or duplicates and resumes paging', async () => {
const pageAt = (index: number): CrawlerPage => ({
url: `https://docs.example.com/${index}`,
title: null,
word_count: 10,
status: 'active',
content_hash: 'h',
last_crawled_at: '2026-09-14T11:11:00.000Z',
discovered_at: '2026-09-14T11:11:00.000Z',
chunks_count: 1,
indexed: true,
fail_count: 0,
last_error: null,
last_error_kind: null,
last_error_at: null,
});
const range = (from: number, to: number) =>
Array.from({ length: to - from }, (_, index) => pageAt(from + index));
pagesPayload.current = { offset: 0, hasMore: true, pages: range(0, 20) };
const fetchPages = useBackendAction('websites/actions:fetchPages').mutate;
vi.mocked(fetchPages).mockClear();
const { user, container } = render(
<WebsiteViewDialog isOpen onClose={vi.fn()} website={WEBSITE} />,
);
await screen.findByRole('link', { name: 'https://docs.example.com/19' });
pagesPayload.current = null;
await user.click(screen.getByRole('button', { name: 'Load more' }));
failPagesRead({ offset: 20, limit: 20 });
expect(screen.getByRole('alert')).toHaveTextContent("Couldn't load pages");
expect(
screen.getByRole('link', { name: 'https://docs.example.com/19' }),
).toBeInTheDocument();
expect(
screen.queryByRole('button', { name: 'Load more' }),
).not.toBeInTheDocument();
await checkAccessibility(container);
await user.click(screen.getByRole('button', { name: 'Try again' }));
failPagesRead({ offset: 20, limit: 20 });
expect(screen.getByRole('alert')).toHaveTextContent("Couldn't load pages");
expect(toastSpy).toHaveBeenCalledTimes(2);
pagesRead.current = ({ offset, limit }) => ({
offset,
hasMore: offset + limit < 60,
pages: range(offset, Math.min(offset + limit, 60)),
});
await user.click(screen.getByRole('button', { name: 'Try again' }));
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
await user.click(screen.getByRole('button', { name: 'Load more' }));
expect(
vi.mocked(fetchPages).mock.calls.map(([args]) => args.offset),
).toEqual([0, 20, 20, 20, 40]);
for (let index = 0; index < 60; index += 1) {
expect(
screen.getAllByRole('link', {
name: `https://docs.example.com/${index}`,
}),
).toHaveLength(1);
}
expect(
screen.queryByRole('button', { name: 'Load more' }),
).not.toBeInTheDocument();
});

// A "Load more" answer that arrived after a refresh answer was appended
// again: the refresh had read the same rows, and they showed twice.
it('drops a page read that a refresh has overtaken', async () => {
Expand Down Expand Up @@ -1736,8 +1799,8 @@ describe('WebsiteViewDialog', () => {
within(dialog).queryByText('No pages crawled yet'),
).not.toBeInTheDocument();
expect(
within(dialog).queryByRole('button', { name: 'Try again' }),
).not.toBeInTheDocument();
within(dialog).getByRole('button', { name: 'Try again' }),
).toBeInTheDocument();
expect(toastSpy).toHaveBeenCalledWith({
title: "Couldn't load pages",
variant: 'destructive',
Expand All @@ -1746,7 +1809,7 @@ describe('WebsiteViewDialog', () => {
vi.mocked(fetchPages).mockClear();
listPages(30);
await user.click(
within(dialog).getByRole('button', { name: 'Load more' }),
within(dialog).getByRole('button', { name: 'Try again' }),
);

expect(fetchPages).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { Alert } from '@tale/ui/alert';
import { Badge } from '@tale/ui/badge';
import { BorderedSection } from '@tale/ui/bordered-section';
import { Button } from '@tale/ui/button';
Expand Down Expand Up @@ -352,6 +353,7 @@ export function WebsiteViewDialog({
const [pages, setPages] = useState<CrawlerPage[]>([]);
const [hasMore, setHasMore] = useState(false);
const [offset, setOffset] = useState(0);
const [pagesError, setPagesError] = useState(false);
const [isFirstLoad, setIsFirstLoad] = useState(true);
// Failed reads since the list last read, kept until one reads: with no
// page on screen the list says it could not read them, not that the site
Expand Down Expand Up @@ -396,13 +398,16 @@ export function WebsiteViewDialog({
} else {
return;
}
setOffset(Math.max(0, shownPages.current - PAGE_SIZE));
setPagesError(false);
setHasMore(data.hasMore);
setIsFirstLoad(false);
setReadFailures(0);
},
onError: (_error, args) => {
// A read for a state the reader has left says nothing of this list.
if ((args.state ?? 'all') !== pageStateRef.current) return;
if ((args?.state ?? 'all') !== pageStateRef.current) return;
setPagesError(shownPages.current > 0);
setIsFirstLoad(false);
setReadFailures((count) => count + 1);
// Rows already shown stay, and "Load more" asks for the same window
Expand All @@ -423,6 +428,7 @@ export function WebsiteViewDialog({
if (isOpen) {
searchRequestId.current += 1;
shownPages.current = 0;
setPagesError(false);
setPages([]);
setOffset(0);
setHasMore(false);
Expand Down Expand Up @@ -487,6 +493,7 @@ export function WebsiteViewDialog({
// for again, not skipped — its successor's answer did not continue the
// list, and was dropped.
const loadMore = useCallback(() => {
if (isPending) return;
const nextOffset = shownPages.current;
setOffset(nextOffset);
fetchPages({
Expand All @@ -495,7 +502,7 @@ export function WebsiteViewDialog({
limit: PAGE_SIZE,
...pageStateArg(pageState),
});
}, [pageState, website._id, fetchPages]);
}, [isPending, pageState, website._id, fetchPages]);

// A retry replaces the control that ran it (with the pages once they are
// back), so focus moves onto the section first instead of falling back to
Expand All @@ -521,6 +528,7 @@ export function WebsiteViewDialog({
pageStateRef.current = next;
setPageState(next);
shownPages.current = 0;
setPagesError(false);
setPages([]);
setOffset(0);
setHasMore(false);
Expand Down Expand Up @@ -904,14 +912,22 @@ export function WebsiteViewDialog({
</Stack>
</Skeletonize>

{hasMore && (
{pagesError && (
<Alert
variant="destructive"
title={t('toast.fetchPagesError')}
/>
)}
{(hasMore || pagesError) && (
<Row gap={0} justify="center" className="pt-2">
<Button
variant="secondary"
onClick={loadMore}
isLoading={isPending}
>
{t('pagesDialog.loadMore')}
{pagesError
? tCommon('actions.tryAgain')
: t('pagesDialog.loadMore')}
</Button>
</Row>
)}
Expand Down
6 changes: 6 additions & 0 deletions services/platform/tests/manual/reference/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ edits retain results; clearing the input and late responses after edits are
covered by `app/features/websites/components/website-view-dialog.test.tsx`.
Real-browser speech and visual transitions remain manual.

Website details retains loaded rows after a failed Load more request and exposes
a live error with Try again. Repeated failures retry the same offset; recovery
appends each page once and resumes successful paging, covered by
`app/features/websites/components/website-view-dialog.test.tsx`.
Real-browser speech and visual transitions remain manual.

Inbox source discovery distinguishes a failed read from successful empty
discovery. Both automation and API-source failures retain the Inbox shell and
conversation outlet with an accessible retry; retries retain the error while
Expand Down