diff --git a/src/components/CommentArticle.test.tsx b/src/components/CommentArticle.test.tsx index 1800420..c06adfa 100644 --- a/src/components/CommentArticle.test.tsx +++ b/src/components/CommentArticle.test.tsx @@ -49,7 +49,8 @@ describe('CommentArticle', () => { }); it('omits the parent link when parentId is null', () => { - // Top-level comments have no parent — drop the pill, don't render a dangling link. + // A top-level comment's parent is its story, so only an item that isn't a + // comment has none: drop the pill rather than render a dangling link. renderArticle({ comment: { ...mockComment, parentId: null } }); expect(screen.queryByRole('link', { name: 'parent' })).not.toBeInTheDocument(); diff --git a/src/components/StateView.test.tsx b/src/components/StateView.test.tsx index 0e1ca9c..65d02ff 100644 --- a/src/components/StateView.test.tsx +++ b/src/components/StateView.test.tsx @@ -60,6 +60,11 @@ describe('StateView', () => { expect(heading).toBeInTheDocument(); }); + it('hides the illustration, including its decorative glyphs, from screen readers', () => { + render(); + expect(screen.getByText('{').closest('[aria-hidden="true"]')).not.toBeNull(); + }); + it('does NOT render an

in compact mode (single-row layout)', () => { render(); expect( diff --git a/src/components/StateView.tsx b/src/components/StateView.tsx index 15aef5c..c402287 100644 --- a/src/components/StateView.tsx +++ b/src/components/StateView.tsx @@ -233,7 +233,7 @@ export function StateView({ variant, title, description, action, compact, classN return (
-
+ {resolvedTitle && ( diff --git a/src/components/SwipeCommentViewer.test.tsx b/src/components/SwipeCommentViewer.test.tsx index 6e3fd83..a41616c 100644 --- a/src/components/SwipeCommentViewer.test.tsx +++ b/src/components/SwipeCommentViewer.test.tsx @@ -108,10 +108,10 @@ describe('SwipeCommentViewer', () => { }, { timeout: 30000 }); }, 35000); - it('renders single panel when comment has no parent', async () => { + it('renders a single panel for an item with no parent', async () => { vi.spyOn(hnSdk, 'readItem').mockImplementation(async (id) => { if (Number(id) === 7777) { - return { id: 7777, by: 'solo', text: 'Top-level comment with no parent.', time: Math.floor(Date.now() / 1000) - 300, type: 'comment' }; + return { id: 7777, by: 'solo', text: 'An item with no parent.', time: Math.floor(Date.now() / 1000) - 300, type: 'story' }; } return null; }); @@ -121,9 +121,9 @@ describe('SwipeCommentViewer', () => { http.get(`${ALGOLIA_API}/items/:id`, () => { return HttpResponse.json({ id: 7777, - type: 'comment', + type: 'story', author: 'solo', - text: 'Top-level comment with no parent.', + text: 'An item with no parent.', created_at_i: Math.floor(Date.now() / 1000) - 300, parent_id: null, story_id: null, diff --git a/src/hooks/usePrefetchItem.test.ts b/src/hooks/usePrefetchItem.test.ts index 41da5b7..afbaa31 100644 --- a/src/hooks/usePrefetchItem.test.ts +++ b/src/hooks/usePrefetchItem.test.ts @@ -147,6 +147,23 @@ describe('usePrefetchItems', () => { renderHook(() => usePrefetchItems(0, undefined as unknown as Item[], 3)); }).not.toThrow(); }); + + it('does not restart an in-flight prefetch when the viewer remounts', async () => { + const spy = vi.spyOn(hn, 'prefetchItemComments').mockReturnValue(new Promise(() => { /* in flight */ })); + const items = [{ id: 1 }, { id: 2 }, { id: 3 }] as Item[]; + + const first = renderHook(() => usePrefetchItems(0, items, 2)); + await act(async () => { vi.advanceTimersByTime(250); }); + // A tab switch or Back mounts a new viewer with the same stories ahead. + first.unmount(); + renderHook(() => usePrefetchItems(0, items, 2)); + await act(async () => { vi.advanceTimersByTime(250); }); + + expect(spy.mock.calls.map(([id]) => id)).toEqual([2, 3]); + cancelAllPrefetches(); + expect(spy.mock.calls.every(([, signal]) => signal?.aborted)).toBe(true); + spy.mockRestore(); + }); }); describe('cancelAllPrefetches', () => { diff --git a/src/hooks/usePrefetchItem.ts b/src/hooks/usePrefetchItem.ts index 0f5cd74..09f9afb 100644 --- a/src/hooks/usePrefetchItem.ts +++ b/src/hooks/usePrefetchItem.ts @@ -72,6 +72,8 @@ async function processQueue() { if (bestId === null) break; prefetchQueue.delete(bestId); + // A remounted swipe viewer re-queues stories that may still be downloading. + if (activePrefetches.has(bestId)) continue; const cached = getCachedItem(bestId); if (cached?.isFresh) { diff --git a/src/hooks/useSiblingComments.test.ts b/src/hooks/useSiblingComments.test.ts index cff13d9..80e99e4 100644 --- a/src/hooks/useSiblingComments.test.ts +++ b/src/hooks/useSiblingComments.test.ts @@ -113,10 +113,10 @@ describe('useSiblingComments', () => { }); }); - it('returns single comment when parent_id is null', async () => { + it('returns just this item when it has no parent', async () => { vi.spyOn(hnSdk, 'readItem').mockImplementation(async (id) => { if (Number(id) === 7777) { - return { id: 7777, by: 'someone', text: 'A top-level comment.', time: Math.floor(Date.now() / 1000) - 300, type: 'comment' }; + return { id: 7777, by: 'someone', text: 'An item with no parent.', time: Math.floor(Date.now() / 1000) - 300, type: 'story' }; } return null; }); @@ -188,7 +188,7 @@ describe('useSiblingComments', () => { vi.spyOn(hnSdk, 'readItem').mockImplementation(async (id) => { if (Number(id) === 7777) { - return { id: 7777, by: 'someone', text: 'A top-level comment.', time: Math.floor(Date.now() / 1000) - 300, type: 'comment' }; + return { id: 7777, by: 'someone', text: 'An item with no parent.', time: Math.floor(Date.now() / 1000) - 300, type: 'story' }; } return null; }); diff --git a/src/hooks/useSiblingComments.ts b/src/hooks/useSiblingComments.ts index 158558e..d15fe14 100644 --- a/src/hooks/useSiblingComments.ts +++ b/src/hooks/useSiblingComments.ts @@ -39,7 +39,8 @@ export function useSiblingComments(commentId: number | string): UseSiblingCommen const item = await fetchFirebaseItem(numericId, signal); if (signal.aborted) return; - // No parent → top-level comment or deleted; show just this one. + // Every comment has a parent, even a deleted one, so this is an item that + // isn't a comment (a story, job, poll or poll option); show just this one. if (item.parent == null) { setSiblingIds([numericId]); setCurrentIndex(0);