From 25a6cbac4f82f8ffc6e5bbf9a4386e96ee36182b Mon Sep 17 00:00:00 2001
From: therealsama <263038098+therealsama@users.noreply.github.com>
Date: Sun, 22 Nov 2026 18:17:57 +0200
Subject: [PATCH 1/6] fix: keep tracking a story's prefetch when its card
scrolls back into view
A story card prefetches its comments while it is in view and aborts the
prefetch when it scrolls out. Scrolled back in before the aborted
prefetch settled, the card started a new one, and the aborted one's
cleanup then dropped the new one from the tracked prefetches. The
untracked prefetch could no longer be aborted, didn't count toward the
limit of three at a time, and the card's next return fetched the
comments again while it was still running.
A prefetch's cleanup now removes the entry only if it is still its own.
---
src/hooks/usePrefetchItem.test.ts | 22 ++++++++++++++++++++++
src/hooks/usePrefetchItem.ts | 6 +++++-
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/hooks/usePrefetchItem.test.ts b/src/hooks/usePrefetchItem.test.ts
index 7ec5515..6a18282 100644
--- a/src/hooks/usePrefetchItem.test.ts
+++ b/src/hooks/usePrefetchItem.test.ts
@@ -136,6 +136,28 @@ describe('usePrefetchItem', () => {
expect(spy.mock.calls[1][0]).toBe(99999);
spy.mockRestore();
});
+
+ it('keeps tracking a restarted prefetch after the aborted one settles', async () => {
+ const settle: (() => void)[] = [];
+ const spy = vi.spyOn(hn, 'prefetchItemComments').mockImplementation(
+ () => new Promise(resolve => { settle.push(() => resolve(null)); }));
+ const { result } = renderHook(() => usePrefetchItem());
+
+ act(() => { result.current.startPrefetch(12345, 0); });
+ await act(async () => { vi.advanceTimersByTime(250); });
+ act(() => { result.current.stopPrefetch(); });
+ act(() => { result.current.startPrefetch(12345, 0); });
+ await act(async () => { vi.advanceTimersByTime(250); });
+ expect(spy).toHaveBeenCalledTimes(2);
+
+ // The first, aborted fetch settles while the second is still in flight.
+ await act(async () => { settle[0](); });
+ act(() => { result.current.startPrefetch(12345, 0); });
+ await act(async () => { vi.advanceTimersByTime(250); });
+
+ expect(spy).toHaveBeenCalledTimes(2);
+ spy.mockRestore();
+ });
});
describe('priority fetch integration', () => {
diff --git a/src/hooks/usePrefetchItem.ts b/src/hooks/usePrefetchItem.ts
index 2fd2171..9d54adf 100644
--- a/src/hooks/usePrefetchItem.ts
+++ b/src/hooks/usePrefetchItem.ts
@@ -84,7 +84,11 @@ async function processQueue() {
// Don't await — let prefetches run in parallel, refilling the queue
// as each completes.
void doPrefetch(bestId, controller).finally(() => {
- activePrefetches.delete(bestId);
+ // A stop-then-restart can register a newer prefetch for this id
+ // before this aborted one settles; leave that one tracked.
+ if (activePrefetches.get(bestId) === controller) {
+ activePrefetches.delete(bestId);
+ }
processQueueNow();
});
}
From a52759d87557f986d2f2ab48f3d9d8a898232be5 Mon Sep 17 00:00:00 2001
From: therealsama <263038098+therealsama@users.noreply.github.com>
Date: Sun, 22 Nov 2026 18:18:48 +0200
Subject: [PATCH 2/6] fix: keep a feed's old list from passing as fresh after
opening a story
Opening a story from the list view saves the feed's session, and wrote
the feed's list back to the cache stamped with the current time. A list
fetched hours earlier then passed as just fetched for five minutes.
Only the swipe view reads that freshness. In that time its background
section prefetching skipped the feed instead of refreshing it, and it
opened the feed on the old list's first story instead of waiting for the
refresh. The list view refreshes a cached list every time it opens, so
this showed only when one browser switched layouts within those five
minutes, such as a phone turned to landscape and back.
Saving the session now keeps the list's fetch time, and skips the write
when the list has no cache entry: it is over a day old, or storage failed.
---
src/hooks/useInfiniteStories.test.ts | 10 ++++++++++
src/hooks/useInfiniteStories.ts | 10 +++++++---
src/utils/feedCache.ts | 5 +++--
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/hooks/useInfiniteStories.test.ts b/src/hooks/useInfiniteStories.test.ts
index db4cca8..1dc4411 100644
--- a/src/hooks/useInfiniteStories.test.ts
+++ b/src/hooks/useInfiniteStories.test.ts
@@ -151,6 +151,16 @@ describe('useInfiniteStories', () => {
expect(ids).toHaveLength(50);
});
+ it('keeps a stale cache stale when saving the session', () => {
+ const hourAgo = Date.now() - 60 * 60 * 1000;
+ setCachedFeed('top', [1, 2, 3].map(id => createStoryItem({ id })), hourAgo);
+ const { result } = renderHook(() => useInfiniteStories('top'));
+
+ act(() => result.current.saveSessionState(0));
+
+ expect(getCachedFeed('top')).toMatchObject({ timestamp: hourAgo, isStale: true });
+ });
+
describe('revalidation', () => {
function seedStaleFeed(type: FeedType) {
// A cached order the live ranking (1, 2, 3, …) has moved on from.
diff --git a/src/hooks/useInfiniteStories.ts b/src/hooks/useInfiniteStories.ts
index 4a8c243..1b9f9de 100644
--- a/src/hooks/useInfiniteStories.ts
+++ b/src/hooks/useInfiniteStories.ts
@@ -371,9 +371,13 @@ export function useInfiniteStories(type: FeedType = 'top') {
phase: phaseRef.current,
});
- // Also update the stories cache with current full list (for session reconstruction)
- if (stories.length > 0) {
- setCachedFeed(type, stories);
+ // Also update the stories cache with current full list (for session
+ // reconstruction). Keep the cached timestamp: the list is no newer than
+ // its last fetch, and re-stamping it would let a stale list pass as fresh.
+ // No cache entry means the list is over a day old, or storage failed.
+ const fetchedAt = getCachedFeed(type)?.timestamp;
+ if (stories.length > 0 && fetchedAt !== undefined) {
+ setCachedFeed(type, stories, fetchedAt);
}
}, [type, stories, hasMore]);
diff --git a/src/utils/feedCache.ts b/src/utils/feedCache.ts
index e4ee2fa..4f29cff 100644
--- a/src/utils/feedCache.ts
+++ b/src/utils/feedCache.ts
@@ -32,10 +32,11 @@ export function getCachedFeed(type: FeedType): { stories: StoryItem[]; timestamp
}
}
-export function setCachedFeed(type: FeedType, stories: StoryItem[]): void {
+/** `timestamp` is when the list was fetched; it decides freshness. */
+export function setCachedFeed(type: FeedType, stories: StoryItem[], timestamp = Date.now()): void {
try {
const key = `${FEED_CACHE_KEY_PREFIX}${type}`;
- const data = { stories, timestamp: Date.now() };
+ const data = { stories, timestamp };
setLocalStorageItem(key, JSON.stringify(data));
} catch { /* best-effort */ }
}
From 00c16d239793627cdd1a00268ede0ea38e0a7316 Mon Sep 17 00:00:00 2001
From: therealsama <263038098+therealsama@users.noreply.github.com>
Date: Sun, 22 Nov 2026 18:18:48 +0200
Subject: [PATCH 3/6] chore: explain why the Top feed skips today's stories
past the top 20
The Top feed is HN's current front page, then each earlier UTC day's
front page from Algolia. Today's stories ranked 21 and below are never
shown. That is by design, so say so where the feed moves on to yesterday.
---
src/hooks/useInfiniteStories.ts | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/hooks/useInfiniteStories.ts b/src/hooks/useInfiniteStories.ts
index 1b9f9de..11ff916 100644
--- a/src/hooks/useInfiniteStories.ts
+++ b/src/hooks/useInfiniteStories.ts
@@ -170,7 +170,10 @@ export function useInfiniteStories(type: FeedType = 'top') {
hasStaleCacheRef.current = false;
}
- positionRef.current = 1; // Next load will be yesterday
+ // Next load will be yesterday. By design, today's stories ranked
+ // past the top 20 are never shown: the feed is HN's front page,
+ // then each earlier (UTC) day's front page from Algolia.
+ positionRef.current = 1;
} else {
let attempts = 0;
const maxAttempts = 5; // Try up to 5 days if current day has no stories
From 1ad6c9bed73e0cbebdeb8a49f859e53ea7fd9d37 Mon Sep 17 00:00:00 2001
From: therealsama <263038098+therealsama@users.noreply.github.com>
Date: Sun, 22 Nov 2026 18:20:13 +0200
Subject: [PATCH 4/6] fix: say a poll option isn't supported instead of showing
an empty story
A Hacker News poll option is an item of its own, with text and a score
but no title. Read as a story, a link to one opened a page with an empty
heading, the tab titled "HackerTok" and "No comments yet." The page also
read the item again and searched Algolia for comments a poll option
can't have, and held background prefetches until both answered.
A poll option now keeps its type. The item page and the swipe view say
poll options aren't supported, and title the tab after that notice. It
fetches only the item, as a comment item does. A copy cached as a story
before this change is corrected by the revalidation, whose type wins.
Polls themselves still show like Ask posts: title, text and comments,
without the options.
---
src/api/hn.test.ts | 6 ++++
src/api/hn.ts | 8 +++++-
src/components/FullScreenItem.test.tsx | 8 ++++++
src/components/FullScreenItem.tsx | 10 +++++++
src/components/PollOptionNotSupported.tsx | 22 +++++++++++++++
src/components/SwipeStoryViewer.test.tsx | 21 ++++++++++++++
src/components/SwipeStoryViewer.tsx | 4 ++-
src/components/index.ts | 1 +
src/hooks/useItemWithComments.test.tsx | 34 +++++++++++++++++++++++
src/hooks/useItemWithComments.ts | 25 +++++++++++------
src/pages/ItemDetail.test.tsx | 9 ++++++
src/pages/ItemDetail.tsx | 12 +++++++-
src/types.ts | 4 ++-
13 files changed, 151 insertions(+), 13 deletions(-)
create mode 100644 src/components/PollOptionNotSupported.tsx
diff --git a/src/api/hn.test.ts b/src/api/hn.test.ts
index 21d1be6..b24e20e 100644
--- a/src/api/hn.test.ts
+++ b/src/api/hn.test.ts
@@ -941,6 +941,12 @@ describe('hn API utilities', () => {
expect(result.type !== 'job' ? result.commentCount : 0).toBe(137);
});
+
+ it('keeps a poll option typed as one', async () => {
+ vi.spyOn(hnSdk, 'readItem').mockResolvedValue({ id: 126810, text: 'Yes, ban them', by: 'pg', score: 30, time: 1204403652, type: 'pollopt' });
+
+ expect((await fetchItemOnly(126810)).type).toBe('pollopt');
+ });
});
describe('error handling', () => {
diff --git a/src/api/hn.ts b/src/api/hn.ts
index b624a1e..14f9e64 100644
--- a/src/api/hn.ts
+++ b/src/api/hn.ts
@@ -85,9 +85,10 @@ function normalizeFirebaseItem(fbItem: FirebaseItem): Item {
// Firebase doesn't distinguish ask/show — they're all type='story'.
// Only the Algolia path (via _tags) can set 'ask'/'show' sub-types.
+ // A poll reads as a story, without its options.
return {
...base,
- type: 'story' as const,
+ type: fbItem.type === 'pollopt' ? 'pollopt' : 'story',
title: fbItem.title ?? '',
url: fbItem.url,
text: fbItem.text,
@@ -231,6 +232,11 @@ export async function fetchNewStories(offset = 0, limit = 30) {
};
}
+/** A poll option has no title or comments, so its page shows a notice instead. */
+export function isPollOption(item: Item): item is StoryItem & { type: 'pollopt' } {
+ return item.type === 'pollopt';
+}
+
function normalizeFirebaseToStoryItem(fb: FirebaseItem): StoryItem {
return {
id: fb.id,
diff --git a/src/components/FullScreenItem.test.tsx b/src/components/FullScreenItem.test.tsx
index e33afaf..cc8f9be 100644
--- a/src/components/FullScreenItem.test.tsx
+++ b/src/components/FullScreenItem.test.tsx
@@ -82,4 +82,12 @@ describe('FullScreenItem', () => {
});
});
});
+
+ it('says a poll option is not supported instead of showing it', async () => {
+ vi.spyOn(hnSdk, 'readItem').mockResolvedValue({ id: 126810, text: 'Yes, ban them', by: 'pg', score: 30, time: 1204403652, type: 'pollopt' });
+ render();
+
+ expect(await screen.findByRole('heading', { name: "Poll options aren't supported" })).toBeInTheDocument();
+ expect(screen.queryByRole('heading', { level: 1 })).not.toBeInTheDocument();
+ });
});
diff --git a/src/components/FullScreenItem.tsx b/src/components/FullScreenItem.tsx
index 74c513c..4556d91 100644
--- a/src/components/FullScreenItem.tsx
+++ b/src/components/FullScreenItem.tsx
@@ -1,11 +1,13 @@
import { useItemWithComments } from '../hooks/useItemWithComments';
import { useNetworkStatus } from '../hooks/useNetworkStatus';
import { useAutoRetry } from '../hooks/useAutoRetry';
+import { isPollOption } from '../api/hn';
import { CommentSkeletonTree } from '../components';
import { CommentsSection } from './CommentsSection';
import { FullScreenChrome } from './FullScreenChrome';
import { ItemArticle } from './ItemArticle';
import { PageStage } from './PageStage';
+import { PollOptionNotSupported } from './PollOptionNotSupported';
import { StateView } from './StateView';
import type { StoryItem } from '../types';
@@ -94,6 +96,14 @@ export function FullScreenItem({ itemId, initialItem, isPriority = true, deferCo
);
}
+ if (!itemLoading && item && isPollOption(item)) {
+ return (
+
+ );
+ }
+
return (
{/* `triggerWhen={isPriority}` holds the entrance animation
diff --git a/src/components/PollOptionNotSupported.tsx b/src/components/PollOptionNotSupported.tsx
new file mode 100644
index 0000000..73cef0a
--- /dev/null
+++ b/src/components/PollOptionNotSupported.tsx
@@ -0,0 +1,22 @@
+import { StateView } from './StateView';
+
+interface PollOptionNotSupportedProps {
+ action?: { label: string; to?: string; onClick?: () => void };
+ className?: string;
+}
+
+/** The notice's heading, and the tab title while it shows. */
+export const POLL_OPTION_TITLE = "Poll options aren't supported";
+
+/** Shown in place of a poll option (see `isPollOption`). */
+export function PollOptionNotSupported({ action, className }: PollOptionNotSupportedProps) {
+ return (
+
+ );
+}
diff --git a/src/components/SwipeStoryViewer.test.tsx b/src/components/SwipeStoryViewer.test.tsx
index 10fac93..486d5e0 100644
--- a/src/components/SwipeStoryViewer.test.tsx
+++ b/src/components/SwipeStoryViewer.test.tsx
@@ -88,6 +88,27 @@ describe('SwipeStoryViewerCore', () => {
expect(title.closest('div')).toHaveClass('swipe-state-center');
});
+
+ it("titles the tab after the notice on a poll option's panel", async () => {
+ vi.mocked(fetchItemOnly).mockResolvedValueOnce(
+ createStoryItem({ id: 126810, type: 'pollopt', title: '', url: undefined, text: 'Yes, ban them' }),
+ );
+
+ render(
+ ,
+ );
+
+ await waitFor(() => expect(activePanel()?.getAttribute('data-item-id')).toBe('126810'));
+ expect(document.title).toBe("Poll options aren't supported | HackerTok");
+ });
});
describe('SwipeStoryViewerCore — mount-snapshot filtering', () => {
diff --git a/src/components/SwipeStoryViewer.tsx b/src/components/SwipeStoryViewer.tsx
index b899fea..0f3fa93 100644
--- a/src/components/SwipeStoryViewer.tsx
+++ b/src/components/SwipeStoryViewer.tsx
@@ -7,13 +7,14 @@ import { usePrefetchSections } from '../hooks/usePrefetchSections';
import { useDocumentTitle } from '../hooks/useDocumentTitle';
import { useNetworkStatus } from '../hooks/useNetworkStatus';
import { useAutoRetry } from '../hooks/useAutoRetry';
-import { fetchItemOnly, NotFoundError } from '../api/hn';
+import { fetchItemOnly, isPollOption, NotFoundError } from '../api/hn';
import { getFilteredViewedIds, getSessionViewedIds } from '../utils/viewedItems';
import { readSwipePosition, saveSwipePosition, clearSwipePosition } from '../utils/swipePosition';
import { isCacheFresh } from '../utils/feedCache';
import { useViewDwell } from '../hooks/useViewDwell';
import { FEED_TYPE_TITLES } from '../config/feedTypes';
import { FullScreenItem, FullScreenItemSkeletonPanel } from './FullScreenItem';
+import { POLL_OPTION_TITLE } from './PollOptionNotSupported';
import { StateView } from './StateView';
import type { StoryItem, FeedType, LocationState } from '../types';
@@ -222,6 +223,7 @@ export function SwipeStoryViewerCore({
? (isInjectedNotFound ? (isNonStoryError ? 'Item not available' : 'Item not found') : 'Failed to load item')
: (error && mergedStories.length === 0) ? 'Failed to load item'
: isOnline && isAtEndError && giveUp ? 'Failed to load item'
+ : currentStory && isPollOption(currentStory) ? POLL_OPTION_TITLE
: (currentStory?.title || titleFallback);
useDocumentTitle(documentTitle);
diff --git a/src/components/index.ts b/src/components/index.ts
index cc44e13..952e160 100644
--- a/src/components/index.ts
+++ b/src/components/index.ts
@@ -17,5 +17,6 @@ export { ItemArticle } from './ItemArticle';
export { FullScreenComment, FullScreenCommentSkeleton, FullScreenCommentSkeletonPanel } from './FullScreenComment';
export { CommentsSection } from './CommentsSection';
export { StateView } from './StateView';
+export { PollOptionNotSupported, POLL_OPTION_TITLE } from './PollOptionNotSupported';
export { NetworkStatusBar } from './NetworkStatusBar';
export { ShareButton } from './ShareButton';
diff --git a/src/hooks/useItemWithComments.test.tsx b/src/hooks/useItemWithComments.test.tsx
index d153623..1c37b80 100644
--- a/src/hooks/useItemWithComments.test.tsx
+++ b/src/hooks/useItemWithComments.test.tsx
@@ -548,6 +548,18 @@ describe('useItemWithComments', () => {
expect(getCachedItem(12345)?.item).toEqual(testItem);
});
+ it('takes the poll option type from the revalidation over a copy cached as a story', async () => {
+ vi.spyOn(hnSdk, 'readItem').mockResolvedValue({ id: 12345, text: 'Yes', by: 'pg', score: 30, time: mockFirebaseStory.time, type: 'pollopt' });
+ seedStaleCache();
+
+ const { result } = renderHook(() => useItemWithComments(12345));
+
+ await waitFor(() => {
+ expect(result.current.item?.type).toBe('pollopt');
+ });
+ expect(getCachedItem(12345)?.item.type).toBe('pollopt');
+ });
+
it('fetches when cache has no comments', async () => {
const CACHE_KEY = `${ITEM_CACHE_KEY_PREFIX}12345`;
const partialData = {
@@ -1031,6 +1043,28 @@ describe('useItemWithComments', () => {
});
});
+ describe('a poll option', () => {
+ it('fetches no comments, and releases priority once it loads', async () => {
+ const readItem = vi.spyOn(hnSdk, 'readItem').mockResolvedValue({
+ id: 126810, text: 'Yes, ban them', by: 'pg', score: 30, time: 1204403652, type: 'pollopt',
+ });
+ let commentSearches = 0;
+ server.use(
+ http.get(`${ALGOLIA_API}/search`, () => {
+ commentSearches++;
+ return HttpResponse.json({ hits: [], nbPages: 0 });
+ }),
+ );
+
+ const { result } = renderHook(() => useItemWithComments(126810));
+
+ await waitFor(() => expect(result.current.item?.type).toBe('pollopt'));
+ expect(isPriorityFetchActive()).toBe(false);
+ expect(readItem).toHaveBeenCalledTimes(1);
+ expect(commentSearches).toBe(0);
+ });
+ });
+
describe('refresh loading states', () => {
it('sets itemLoading and commentsLoading to true during refresh', async () => {
const { result } = renderHook(() =>
diff --git a/src/hooks/useItemWithComments.ts b/src/hooks/useItemWithComments.ts
index f45380d..fd6ee39 100644
--- a/src/hooks/useItemWithComments.ts
+++ b/src/hooks/useItemWithComments.ts
@@ -1,5 +1,5 @@
import { useState, useEffect, useRef, useEffectEvent, useCallback } from 'react';
-import { fetchItemOnly, fetchCommentsForItem, fetchItemWithComments, NotFoundError } from '../api/hn';
+import { fetchItemOnly, fetchCommentsForItem, fetchItemWithComments, isPollOption, NotFoundError } from '../api/hn';
import { getCachedItem, setCachedItem } from '../utils/itemCache';
import { registerPriorityFetch, unregisterPriorityFetch } from '../utils/fetchPriority';
import { useNetworkStatus } from './useNetworkStatus';
@@ -40,8 +40,11 @@ function withText(item: Item | null | undefined, source: Item | null | undefined
// The comments fetch reads the item too, so it has newer points, comment count
// and title than a cached or restored copy. The rest stays: Firebase calls
-// Ask/Show posts `story`, and a deleted story comes back without a title.
+// Ask/Show posts `story`, and a deleted story comes back without a title. A
+// fetched poll option's type wins: copies cached before it had one call it a
+// story.
function withFetchedFields(item: Item | null | undefined, fetched: Item): Item | null {
+ if (item && isPollOption(fetched) && fetched.id === item.id) return fetched;
if (!item || item.type === 'comment' || item.type === 'job' || fetched.type !== 'story' ||
fetched.id !== item.id || !fetched.title) {
return withText(item, fetched);
@@ -56,6 +59,12 @@ function withFetchedFields(item: Item | null | undefined, fetched: Item): Item |
};
}
+// A comment's replies come from useCommentDetail (Algolia /items), and a poll
+// option has no comments.
+function fetchesComments(item: Item): boolean {
+ return item.type !== 'comment' && !isPollOption(item);
+}
+
export function useItemWithComments(itemId: number | string, { initialItem = null, skipOrderingCompletion = false, isPriority = true, deferComments = false }: UseItemWithCommentsOptions = {}): UseItemWithCommentsResult {
const [initialCache] = useState(() => getCachedItem(itemId));
@@ -241,13 +250,12 @@ export function useItemWithComments(itemId: number | string, { initialItem = nul
} else if (needsFullFetch) {
const itemData = hasItem ?? await loadItem();
- // Comment items use a different fetch path (useCommentDetail via Algolia /items).
- if (itemData && itemData.type !== 'comment' && !controller.signal.aborted) {
+ if (itemData && fetchesComments(itemData) && !controller.signal.aborted) {
await loadComments(itemData, false);
}
}
- // A comment item fetches nothing more. After an abort, whoever
- // aborted releases it.
+ // A comment item or poll option fetches nothing more. After an abort,
+ // whoever aborted releases it.
if (!controller.signal.aborted) releasePriority();
}
@@ -288,7 +296,7 @@ export function useItemWithComments(itemId: number | string, { initialItem = nul
const { commentsLoading, comments, commentsError, item, deferComments } = getReconnectSnapshot();
// Only act when comments are stuck loading (hanging fetch, no error surfaced)
- if (!commentsLoading || comments || commentsError || !item || item.type === 'comment' || deferComments) return;
+ if (!commentsLoading || comments || commentsError || !item || !fetchesComments(item) || deferComments) return;
// Abort the hanging fetch so its promise settles (AbortError, swallowed by the effect)
controllerRef.current?.abort();
@@ -348,8 +356,7 @@ export function useItemWithComments(itemId: number | string, { initialItem = nul
}
setItemLoading(false);
- // Comment items use a different fetch path (useCommentDetail via Algolia /items)
- if (itemData.type !== 'comment') {
+ if (fetchesComments(itemData)) {
try {
const commentsData = await fetchCommentsForItem(itemId);
setComments(commentsData);
diff --git a/src/pages/ItemDetail.test.tsx b/src/pages/ItemDetail.test.tsx
index 8cbf075..b27ff26 100644
--- a/src/pages/ItemDetail.test.tsx
+++ b/src/pages/ItemDetail.test.tsx
@@ -96,6 +96,15 @@ describe('ItemDetail', () => {
});
});
+ it('says a poll option is not supported instead of showing it', async () => {
+ vi.spyOn(hnSdk, 'readItem').mockResolvedValue({ id: 126810, text: 'Yes, ban them', by: 'pg', score: 30, time: 1204403652, type: 'pollopt' });
+ renderItemDetail(126810);
+
+ expect(await screen.findByRole('heading', { name: "Poll options aren't supported" })).toBeInTheDocument();
+ expect(screen.queryByRole('heading', { level: 1 })).not.toBeInTheDocument();
+ expect(document.title).toBe("Poll options aren't supported | HackerTok");
+ });
+
describe('comments that keep failing', () => {
afterEach(() => {
vi.useRealTimers();
diff --git a/src/pages/ItemDetail.tsx b/src/pages/ItemDetail.tsx
index b950356..6050bfd 100644
--- a/src/pages/ItemDetail.tsx
+++ b/src/pages/ItemDetail.tsx
@@ -1,7 +1,8 @@
import { useParams } from 'react-router';
import { useEffect } from 'react';
import { useItemWithComments } from '../hooks/useItemWithComments';
-import { ItemDetailSkeleton, CommentDetail, StateView, CommentsSection, ItemArticle, PageStage } from '../components';
+import { isPollOption } from '../api/hn';
+import { ItemDetailSkeleton, CommentDetail, StateView, CommentsSection, ItemArticle, PageStage, PollOptionNotSupported, POLL_OPTION_TITLE } from '../components';
import { useDocumentTitle } from '../hooks/useDocumentTitle';
import { useNetworkStatus } from '../hooks/useNetworkStatus';
import { useAutoRetry } from '../hooks/useAutoRetry';
@@ -19,6 +20,7 @@ export function ItemDetail() {
const documentTitle = (!id || isNotFound || (!itemLoading && !item))
? 'Item not found'
: error ? 'Failed to load item'
+ : item && isPollOption(item) ? POLL_OPTION_TITLE
: (item && 'title' in item ? item.title : undefined);
useDocumentTitle(documentTitle);
@@ -73,6 +75,14 @@ export function ItemDetail() {
return ;
}
+ if (!itemLoading && item && isPollOption(item)) {
+ return (
+
+ );
+ }
+
return (
{/* `loading={itemLoading || commentsLoading}` holds the skeleton
diff --git a/src/types.ts b/src/types.ts
index be3a77a..6e208fb 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -14,7 +14,9 @@ interface ItemBase {
}
export interface StoryItem extends ItemBase {
- type: 'story' | 'ask' | 'show';
+ // A poll is a story. A poll option ('pollopt') rides along as one only so
+ // its page can say it isn't supported.
+ type: 'story' | 'ask' | 'show' | 'pollopt';
title: string;
url?: string;
text?: string;
From a46293bbfcf81b2f0932270c5098c19b6ae80ccd Mon Sep 17 00:00:00 2001
From: therealsama <263038098+therealsama@users.noreply.github.com>
Date: Sun, 22 Nov 2026 18:20:23 +0200
Subject: [PATCH 5/6] fix: give 404.html a Content-Security-Policy
GitHub Pages serves 404.html for any path it has no file for, and its
inline script redirects the path into the app's hash route. Vite copies
public/ as is, so the build's CSP plugin never saw 404.html, and the
page shipped with no CSP while every other page has one.
404.html is now a build entry beside index.html, so the plugin hashes
its inline script into a CSP meta tag, and an e2e test checks it.
---
public/404.html => 404.html | 0
e2e/csp.spec.ts | 11 +++++++++++
src/utils/sanitize.ts | 2 +-
vite.config.js | 6 ++++++
4 files changed, 18 insertions(+), 1 deletion(-)
rename public/404.html => 404.html (100%)
diff --git a/public/404.html b/404.html
similarity index 100%
rename from public/404.html
rename to 404.html
diff --git a/e2e/csp.spec.ts b/e2e/csp.spec.ts
index 18d5a4a..7734acf 100644
--- a/e2e/csp.spec.ts
+++ b/e2e/csp.spec.ts
@@ -66,4 +66,15 @@ test.describe('Content-Security-Policy', () => {
});
expect(await readViolations(page)).toEqual([]);
});
+
+ test('covers the 404.html redirect shell', async ({ page, request }) => {
+ // Pages serves 404.html for every unknown path, so it is a second entry
+ // document and needs the same policy.
+ const html = await (await request.get('/404.html')).text();
+ expect(html).toMatch(/
Date: Sun, 22 Nov 2026 19:41:45 +0200
Subject: [PATCH 6/6] fix: center a swipe panel's states on the phone
On the phone, a state shown in place of a swipe panel's content sat right
under the header instead of in the middle of the screen. Its wrapper asked
for `min-height: 100%`, but the active panel only has a min-height, so the
percentage resolved to nothing. The state also jumped up when a swipe
landed on it, because the peeking panel it came from has a definite height.
The new `.full-screen-state` takes the panel's box under the header and
above the offline bar. This covers the poll-option notice, the item's
not-found and error states, the comment's error and deleted states, and
the end-of-feed error.
The empty illustration's rising dots also sat 2px left of the box's
middle, on every layout. They now rise from its center, under "No
comments yet" and the poll-option notice alike.
---
e2e/item-detail.spec.ts | 27 ++++++++++++++++++++++++++-
src/components/FullScreenComment.tsx | 4 ++--
src/components/FullScreenItem.tsx | 6 +++---
src/components/StateView.tsx | 6 +++---
src/components/SwipeStoryViewer.tsx | 2 +-
src/index.css | 11 +++++++++++
6 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/e2e/item-detail.spec.ts b/e2e/item-detail.spec.ts
index ccb1a09..3fcc3e1 100644
--- a/e2e/item-detail.spec.ts
+++ b/e2e/item-detail.spec.ts
@@ -1,5 +1,6 @@
import { test, expect } from '@playwright/test';
-import { setupApiMocks } from './fixtures/api-mocks';
+import { createFirebaseWsHandler, FIREBASE_WS_PATTERN, setupApiMocks } from './fixtures/api-mocks';
+import { expectLocatorCenteredBetweenChrome, setOfflineAndWaitForBar } from './fixtures/layout-helpers';
test.describe('Item Detail', () => {
test.beforeEach(async ({ page }) => {
@@ -265,3 +266,27 @@ test.describe('Item Detail - Desktop', () => {
await expect(page.getByText('SQLite Does Not Do Full FSYNC by Default').first()).toBeVisible();
});
});
+
+test.describe('Item Detail - Poll option on a phone', () => {
+ test.use({ viewport: { width: 375, height: 667 }, hasTouch: true });
+
+ test.beforeEach(async ({ page }) => {
+ await setupApiMocks(page);
+ // Registered last, so it wins over setupApiMocks' handler.
+ await page.routeWebSocket(FIREBASE_WS_PATTERN, createFirebaseWsHandler({
+ itemOverrides: {
+ 126810: { id: 126810, text: 'Yes, ban them', by: 'pg', score: 30, time: 1204403652, poll: 126809, type: 'pollopt' },
+ },
+ }));
+ });
+
+ test('centers the notice between the header and the offline bar', async ({ page, context }) => {
+ await page.goto('/#/item/126810');
+ const heading = page.getByRole('heading', { name: "Poll options aren't supported" });
+ await expect(heading).toBeVisible({ timeout: 10_000 });
+
+ await setOfflineAndWaitForBar(page, context);
+
+ await expectLocatorCenteredBetweenChrome(heading.locator('xpath=..'));
+ });
+});
diff --git a/src/components/FullScreenComment.tsx b/src/components/FullScreenComment.tsx
index b85f9dd..414b292 100644
--- a/src/components/FullScreenComment.tsx
+++ b/src/components/FullScreenComment.tsx
@@ -62,7 +62,7 @@ export function FullScreenComment({ commentId, onAuthorLoaded }: FullScreenComme
if (error && !isRetrying) {
return (
-
+
void retry().catch(() => { /* error state set internally */ }) }} />
);
@@ -78,7 +78,7 @@ export function FullScreenComment({ commentId, onAuthorLoaded }: FullScreenComme
const isDeletedLeaf = !!comment && !comment.author && !comment.text && replies.length === 0 && !moreRepliesLoading;
if (!loading && (!comment || isDeletedLeaf)) {
return (
-
+
);
diff --git a/src/components/FullScreenItem.tsx b/src/components/FullScreenItem.tsx
index 4556d91..82d45f1 100644
--- a/src/components/FullScreenItem.tsx
+++ b/src/components/FullScreenItem.tsx
@@ -73,7 +73,7 @@ export function FullScreenItem({ itemId, initialItem, isPriority = true, deferCo
if (error && !isRetrying) {
return (
-
+
+
);
@@ -98,7 +98,7 @@ export function FullScreenItem({ itemId, initialItem, isPriority = true, deferCo
if (!itemLoading && item && isPollOption(item)) {
return (
-
+
);
diff --git a/src/components/StateView.tsx b/src/components/StateView.tsx
index e0fa58f..15aef5c 100644
--- a/src/components/StateView.tsx
+++ b/src/components/StateView.tsx
@@ -112,9 +112,9 @@ function EmptyScene({ compact }: { compact?: boolean }) {
return (
{/* Rising thought dots — start at box opening (y≈55) and float above */}
-
-
-
+
+
+
{/* Floating particles */}
diff --git a/src/components/SwipeStoryViewer.tsx b/src/components/SwipeStoryViewer.tsx
index 0f3fa93..7b9e81c 100644
--- a/src/components/SwipeStoryViewer.tsx
+++ b/src/components/SwipeStoryViewer.tsx
@@ -722,7 +722,7 @@ export function SwipeStoryViewerCore({
`.active` sets display:block, so the centering lives on an inner box. */}
{showErrorPanel && (