+
{loading && }
)}
From 590ed74b6258a1cec38d3a9799783f78fb469d1e Mon Sep 17 00:00:00 2001
From: therealsama <263038098+therealsama@users.noreply.github.com>
Date: Wed, 4 Nov 2026 09:28:55 +0100
Subject: [PATCH 2/3] fix: show a deleted comment's replies on a phone
The phone's full-screen comment showed "Comment deleted", with nothing
else, for any comment with no author and no text, even one with
replies. The desktop page shows the same comment under a [deleted]
byline, with its parent and story links and its replies. Tapping
"parent" on reply 50343707 on a phone led to such a dead end for
comment 50343637.
The phone now shows the dead end only when the comment has no replies
and none are still loading. Otherwise it renders the comment as the
desktop page does.
---
src/components/FullScreenComment.test.tsx | 16 ++++++++++++++++
src/components/FullScreenComment.tsx | 4 +++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/components/FullScreenComment.test.tsx b/src/components/FullScreenComment.test.tsx
index 51fa5f7..df83d7d 100644
--- a/src/components/FullScreenComment.test.tsx
+++ b/src/components/FullScreenComment.test.tsx
@@ -172,6 +172,22 @@ describe('FullScreenComment', () => {
expect(await screen.findByText('Comment deleted')).toBeInTheDocument();
expect(screen.queryByText('Failed to load comment')).not.toBeInTheDocument();
});
+
+ it('shows a deleted comment with replies as [deleted], with its replies', async () => {
+ mockMissingFromAlgolia(
+ 8888,
+ { id: 8888, type: 'comment', deleted: true, parent: 12345, kids: [8889], time: now - 600 },
+ [{ id: 8889, type: 'comment', author: 'dang', text: 'Still worth reading.', created_at_i: now - 300, parent_id: 8888, story_id: 12345, children: [] }],
+ );
+
+ render(
);
+
+ expect(await screen.findByText('[deleted]')).toBeInTheDocument();
+ expect(screen.getByText('dang')).toBeInTheDocument();
+ expect(screen.getByText('Still worth reading.')).toBeInTheDocument();
+ expect(await screen.findByRole('link', { name: 'Rust Is the Future of JavaScript Infrastructure' })).toHaveAttribute('href', '/item/12345');
+ expect(screen.queryByText('Comment deleted')).not.toBeInTheDocument();
+ });
});
it('shows "No replies yet" for comment with no children', async () => {
diff --git a/src/components/FullScreenComment.tsx b/src/components/FullScreenComment.tsx
index ef26331..b85f9dd 100644
--- a/src/components/FullScreenComment.tsx
+++ b/src/components/FullScreenComment.tsx
@@ -74,7 +74,9 @@ export function FullScreenComment({ commentId, onAuthorLoaded }: FullScreenComme
// CRITICAL `!loading` gate: during cold load `comment` is null but
// we want PageStage to show the skeleton, not flash deleted-state.
- if (!loading && (!comment || (!comment.author && !comment.text))) {
+ // A deleted comment with replies still shows them, under a [deleted] byline.
+ const isDeletedLeaf = !!comment && !comment.author && !comment.text && replies.length === 0 && !moreRepliesLoading;
+ if (!loading && (!comment || isDeletedLeaf)) {
return (
From c4d2a0f6f3d128f43b9b85cc24424c5a12c4f689 Mon Sep 17 00:00:00 2001
From: therealsama <263038098+therealsama@users.noreply.github.com>
Date: Wed, 4 Nov 2026 09:28:55 +0100
Subject: [PATCH 3/3] perf: read an item's cached thread once, when its view
mounts
useItemWithComments read the item cache in its body, which parses the
cached thread from localStorage on every render, though the result
only seeds the initial state. Over five swipes on a phone-speed CPU,
those reads parsed 3.3 million characters, about 18ms. It now reads
the cache once, in a state initializer.
---
src/hooks/useItemWithComments.test.tsx | 16 ++++++++++++++++
src/hooks/useItemWithComments.ts | 2 +-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/hooks/useItemWithComments.test.tsx b/src/hooks/useItemWithComments.test.tsx
index e1be881..d153623 100644
--- a/src/hooks/useItemWithComments.test.tsx
+++ b/src/hooks/useItemWithComments.test.tsx
@@ -82,6 +82,22 @@ describe('useItemWithComments', () => {
expect(result.current.comments).toEqual(testComments);
});
+ it('reads the cache when it mounts, not on every render', () => {
+ setCachedItem(12345, testItem, testComments, 3);
+ const cached = localStorage.getItem(`${ITEM_CACHE_KEY_PREFIX}12345`);
+ const parse = vi.spyOn(JSON, 'parse');
+ const cacheReads = () => parse.mock.calls.filter(([text]) => text === cached).length;
+
+ const { rerender } = renderHook(() => useItemWithComments(12345));
+ const readsOnMount = cacheReads();
+ rerender();
+ rerender();
+ rerender();
+
+ expect(readsOnMount).toBeGreaterThan(0);
+ expect(cacheReads()).toBe(readsOnMount);
+ });
+
it('accepts initialItem prop to skip item fetch', async () => {
const { result } = renderHook(() =>
useItemWithComments(12345, { initialItem: testItem })
diff --git a/src/hooks/useItemWithComments.ts b/src/hooks/useItemWithComments.ts
index b32d4b7..f45380d 100644
--- a/src/hooks/useItemWithComments.ts
+++ b/src/hooks/useItemWithComments.ts
@@ -57,7 +57,7 @@ function withFetchedFields(item: Item | null | undefined, fetched: Item): Item |
}
export function useItemWithComments(itemId: number | string, { initialItem = null, skipOrderingCompletion = false, isPriority = true, deferComments = false }: UseItemWithCommentsOptions = {}): UseItemWithCommentsResult {
- const initialCache = getCachedItem(itemId);
+ const [initialCache] = useState(() => getCachedItem(itemId));
// Lazy initialization from cache or initialItem for instant render
const [item, setItem] = useState(() => withText(initialItem, initialCache?.item) ?? initialCache?.item ?? null);