From 61a32bcdd5763af2005634eb15f7a02dd9df599e Mon Sep 17 00:00:00 2001 From: therealsama <263038098+therealsama@users.noreply.github.com> Date: Sat, 28 Nov 2026 02:10:01 +0200 Subject: [PATCH] fix: hide not-found glyphs from screen readers, stop orphaning prefetches The not-found illustration floats a "{", a "}" and a "/" around its drawing. The drawing is an aria-hidden SVG, but the three glyphs are plain text, so a screen reader read "{ } /" before "Item not found" on the 404 page, a missing item, and an unknown user or domain. The illustration's wrapper is now aria-hidden, so every scene stays decorative, including ones added later. axe has no rule for stray decorative text, so the e2e scans never caught it. Switching tabs, or going Back from a profile or domain page, mounts a new swipe viewer, which queues the stories ahead of it again. When one was still downloading, the queue started it a second time and replaced its tracked AbortController, so cancelAllPrefetches() could no longer abort the first. Thread downloads are shared, so this cost no extra requests, but the download kept running after the cancel, outside the three-prefetch limit. The queue now skips a story whose prefetch is already in flight. useSiblingComments showed a lone panel for a comment with no parent, "a top-level comment or deleted". On Hacker News every comment has a parent: a top-level one's is its story, which is how swiping steps through the other top-level comments, and a deleted one keeps its parent too. Only a story, job, poll or poll option has none, so that branch is a fallback real comments never reach. Its comment and tests, and the parent-link test in CommentArticle, now say so, and the tests' no-parent item is a story. No behavior changes there. --- src/components/CommentArticle.test.tsx | 3 ++- src/components/StateView.test.tsx | 5 +++++ src/components/StateView.tsx | 2 +- src/components/SwipeCommentViewer.test.tsx | 8 ++++---- src/hooks/usePrefetchItem.test.ts | 17 +++++++++++++++++ src/hooks/usePrefetchItem.ts | 2 ++ src/hooks/useSiblingComments.test.ts | 6 +++--- src/hooks/useSiblingComments.ts | 3 ++- 8 files changed, 36 insertions(+), 10 deletions(-) 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);