Repository navigation
fix: keep Ask/Show bodies on restore, stop repeated and wrong-feed stories, and four smaller fixes - #285
Merged
Conversation
The saved swipe position stores stories without `text`, and that copy wins when the viewer comes back (Back from an author's profile, or a reload), so an Ask HN or Show HN panel lost its body. useItemWithComments never fetched the item when given one. It now fills `text` from the cached item, or from the item the comments fetch already reads, and caches the result.
Opening a story saves the feed's session. Going Back to that feed from another tab keeps the list mounted, so StoryList calls reset(), which restored the session's stories but reset the paging cursor to zero. The next page then loaded the same stories again. reset() now starts from the feed cache, matching its "start fresh" contract and a header-tab click.
…y opens Every feed route renders MobileStoryListWrapper, so React reused the same SwipeStoryViewer across them. A tab switch made before the viewer moved the URL to /item/:id (the first load still running, or a failed one) kept the previous feed's stories, and its in-flight page then landed in the new feed. Key the viewer by feed type, as the domain viewer already is.
/#/item/abc mounted the swipe viewer, which can only fetch numeric ids. Its NaN id never matched the failed fetch, so the viewer fell back to the Top feed instead of an error. The mobile item route now shows the not-found state, with its document title, for any id that isn't all digits. Desktop already did.
The swipe viewers guarded their sessionStorage writes but not the reads, so with site storage blocked, returning to the tab (or a back-forward cache restore) threw an uncaught error. Both restores only run in the page that was hidden, and bfcache keeps the JS heap, so a ref is enough. The shared scroll helpers aren't a fit: they drop positions after 30 minutes, which would send you to the top of the story after a long break.
…oads A comment page clears `loading` before the parent story's title arrives, and the generic "story" fallback was shown whenever `loading` was false and the title was missing. So the link read "story" for a moment, then changed to the real title. useCommentDetail now reports itemTitleLoading, and until the title fetch settles the placeholder stays, already as a link to the story: that fetch has no timeout and can wait out a dropped connection.
The sanitizer kept `class` and `id`, which HN never emits. They let user-written HTML pick up the app's utility classes or shadow ids the app looks up. Only `href` is kept now.
therealsama
force-pushed
the
fix/verified-restore-and-feed-bugs
branch
from
October 5, 2026 11:16
95600cd to
8a08f5a
Compare
therealsama
enabled auto-merge
October 5, 2026 11:39
kplachkov
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes seven bugs found in a follow-up audit. The first four were reproduced in a production build against the live HN APIs before fixing (phone emulation for the mobile ones). The other three came from reading the code. Each commit is one fix with its tests.
Mobile swipe viewer
textto stay small, and the restored copy is what the panel renders.useItemWithCommentsnever fetched an item it was handed, so the body stayed empty, and the text-less copy was written over the cached one. It now fillstextfrom the cached item, or from the item the comments fetch already reads (no extra request), and caches the result. The retry that runs when the connection comes back does the same. Onlytextis taken, because Firebase normalizes ask/show stories totype: 'story'and would blank the title of a deleted story./item/:id(first load still running, or a failed one) kept Top's state, and its in-flight page then landed in Best: in the browser, Best opened on Top's 4th story, and it was still there after a reload because it went into Best's saved position. The viewer is now keyed by feed type, as the domain viewer already is. On a slow connection the window is the whole first load./#/item/abcshowed the Top feed instead of "Item not found". The swipe viewer can only fetch numeric ids, and itsNaNid never matched the failed fetch, so it fell back to the feed. The mobile item route now shows the not-found state, with its document title, for any id that isn't all digits. Desktop already did.Feeds and data
StoryListcallsreset(), which restored the session's stories but set the paging cursor back to zero. The next page then loaded the same stories again (Best's 3 became 6 in the e2e mock).reset()now starts from the feed cache, matching its "start fresh" contract and what a header-tab click does.Smaller fixes
sessionStoragewrites were guarded but the reads weren't, so returning to the tab or a back-forward cache restore threw an uncaughtSecurityError. They now keep the offset in memory: both restores run in the page that was hidden, and bfcache keeps the JS heap. The sharedscrollRestorehelpers would have dropped it after 30 minutes and sent you to the top of the story.loadingbefore the parent story's title arrives, and the generic "story" fallback showed in between.useCommentDetailnow reportsitemTitleLoading, so the fallback only appears when the title fetch fails. Until then the placeholder is already a link to the story, because that fetch (a Firebaseget()) has no timeout and can wait out a dropped connection.classandid. HN never emits them, and they let user-written HTML pick up the app's utility classes or shadow ids the app looks up. Onlyhrefis kept.Testing
npm run typecheck,npm run lintandnpm run test:runpass on every commit, not just the tip (1072 tests, 15 new).npm run e2e: 842 passed, 42 skipped (chromium, firefox, Mobile Safari, Mobile Chrome), with no retries used.mobile-swipe.spec.ts).mobile-swipe.spec.ts)./#/item/abcshows "Item not found" and sets the title (mobile-swipe.spec.ts).story-browsing.spec.ts).maintoo. It guards against the expiry the sharedscrollRestorehelpers would add.Not changed / known limitations
display: none, so keyboard and screen-reader users on a phone layout can't move through the feed. WCAG 2.5.1 asks for a single-pointer alternative to path gestures. Adding one is a design decision, so it's left for a separate change.__swipe_scrollYand__swipe_comment_scrollYsessionStorage keys are no longer read or written. Values already stored go away when the tab closes.