Skip to content

fix: keep swipe position on Back, reach end-of-feed retry, and six smaller fixes - #284

Merged
therealsama merged 9 commits into
mainfrom
fix/verified-audit-bugs
Oct 4, 2026
Merged

therealsama merged 9 commits into
mainfrom
fix/verified-audit-bugs

Conversation

@therealsama

@therealsama therealsama commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes nine bugs found in an audit of the app. Each commit is one fix with its tests, with two exceptions: the first two swipe-viewer fixes share a commit because they touch the same code, and the blocked-storage fix is split into the React provider and the inline theme script.

Mobile swipe viewer

  • Back lost your place past the first page. Tapping the author (or any in-app link) unmounted the viewer without saving its position, and the remount on Back only had the feed's first cached page. A story beyond it reopened at index 0 with its neighbors gone. The viewer now saves its swipe snapshot when it unmounts (the same snapshot pagehide writes), so Back restores the way a reload does, including the scroll offset within the story.
  • Switching feeds lost your place. The snapshot had a single slot, so opening Best (or a domain, or a user's submissions) replaced the Top feed's position, and Back to Top fell back to the cached first page. Positions are now kept per viewer, newest first, capped at 8. Opening a feed from its tab drops that feed's old position, so the tab still starts at the top.
  • The end-of-feed Try Again button was unreachable. The loading/error panel after the last story wasn't counted as a swipe target, and panels stay display:none until activated, so a failed page left you on the last story with no way to retry. It's now a swipe target, and if it goes away while showing, the viewer falls back to the last story. The error is centered on an inner box because .active sets display:block, which overrode the panel's flex.
  • Duplicate cold-start requests. Two effects calling loadMore in the same commit both saw loading === false. A ref guard brings a mobile cold start from 5 topstories reads to 2 against the e2e mock; desktop stays at 1.

Feeds and data

  • Domain pages said "No submissions" when the first Algolia page was all other-host hits. On the desktop list nothing asks for page 2 while the list is empty. loadMore now keeps paging within one call until a story lands, still capped at 3 empty pages.
  • whoishiring threads showed up in Ask (and could in Best). They're type: 'story', so the job filter missed them. Show is left unfiltered on purpose, since a Show HN title that mentions hiring is a real project.
  • HN /newest links left the app. Added to the in-app link rewrite map.
  • Tabs erased each other's viewed stories. Each write stored the tab's whole in-memory copy, so a stale copy overwrote what another tab had recorded. A storage event now drops the stale copies.
  • Blocked site storage blanked the whole app. localStorage throws a SecurityError when site data is blocked, and ThemeProvider renders above the ErrorBoundary. It now falls back to the system theme and keeps a chosen mode for the visit. The inline theme script in index.html had the same unguarded read: it threw an uncaught error before applying the dark class, so dark-OS users got a brief light background (about 65 ms in Chromium). It now falls back to the OS scheme too; the CSP hash is regenerated at build time.

Testing

  • npm run typecheck, npm run lint, npm run test:run (1057 tests), npm run build
  • npm run e2e: 828 passed, 40 skipped (chromium, firefox, Mobile Safari, Mobile Chrome)
  • New e2e tests:
    • Back after visiting the author returns to index 21 with its neighbors (mobile-swipe.spec.ts).
    • Back after switching to Best does the same (mobile-swipe.spec.ts).
    • Swiping onto the end-of-feed error panel and retrying from it (domain-filter.spec.ts).
    • With storage blocked, the app loads in the OS dark theme with no uncaught error (theme-toggle.spec.ts).
  • Each new e2e test fails against the code before its fix and passes on repeat runs on every project. The two added last (Best and blocked storage) failed 16/16 runs without their fixes; together with the author test they passed 48/48 with them.
  • The new SwipeStoryViewer unit tests fail without the change they cover (checked by reverting the viewer change, the fall-back-to-last-story effect, and the per-viewer snapshot change).

Known limitations

  • On mobile, the URL rewrite from / to /item/:id still remounts the viewer, which is the second topstories read above. Avoiding it means not remounting on that rewrite, a bigger routing change.
  • Positions are kept one per feed, so if the same feed appears twice in your history (opening Top from its tab again, say), Back to the older entry falls back to the cached first page.
  • The Best filter has no visible effect today; it only matters in a month when a hiring thread ranks among the best.
  • The item-cache pruning cost noted in the audit is unchanged; it's minor.

In-app navigation (tapping the author) unmounted the mobile viewer without saving its place, and the remount on Back only had the feed's first cached page, so a story past it reopened at index 0 with its neighbors gone. Save the swipe snapshot when the viewer unmounts, as pagehide already does.

The loading/error panel after the last story wasn't counted as a swipe target, so the gesture could never land on it and the Try Again button stayed hidden. Count it, fall back to the last panel when it goes away, and center the error on an inner box since .active sets display:block.
Two effects calling loadMore in the same commit both saw loading === false, so a mobile cold start read the ranked list several times. Guard with a ref that flips synchronously.
When the first Algolia page held only hits from other hosts, the desktop list showed "No submissions" because nothing asked for page 2 (there's no sentinel while the list is empty). loadMore now keeps paging within one call until a story lands, still capped at MAX_EMPTY_PAGES_COLD_START.
They're type='story', so the job filter misses them. New, the Ask day pages
and the front-page day pages already excluded them. Show stays unfiltered,
Firebase and Algolia alike, because a Show HN title that mentions hiring is a
real project.
localStorage throws a SecurityError when site data is blocked, and ThemeProvider renders above the ErrorBoundary, so the whole app went blank. Fall back to the system theme and keep a chosen mode for the visit.
/newest is an in-app route but wasn't in FEED_LABELS, so links to it left for news.ycombinator.com.
Each write stores the tab's whole in-memory copy, so a stale copy erased what another tab had recorded. Drop the copies on a storage event so the next read or write starts from storage.
@therealsama
therealsama requested a review from kplachkov as a code owner October 4, 2026 20:10
The inline script in index.html read localStorage unguarded. With storage
blocked it threw before applying the dark class, so a dark-OS user got a
light background until React's ThemeProvider caught up, plus an uncaught
error. It now falls back to the OS scheme, like ThemeProvider does.
The saved position had a single slot, so opening Best (or a domain or
user's submissions) replaced the Top feed's position and Back to Top
lost your place. Positions are now kept per viewer, newest first, capped
at 8. Opening a feed from its tab drops that feed's old position so the
tab still starts at the top.
@therealsama
therealsama enabled auto-merge October 4, 2026 21:23
@therealsama
therealsama merged commit 907db50 into main Oct 4, 2026
4 checks passed
@therealsama
therealsama deleted the fix/verified-audit-bugs branch October 4, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants