Skip to content

fix: 17 audit fixes across feeds, swipe, offline app, comments and autolinking - #358

Merged
therealsama merged 16 commits into
mainfrom
fix/audit-feed-swipe-sw-comments
Nov 29, 2026
Merged

therealsama merged 16 commits into
mainfrom
fix/audit-feed-swipe-sw-comments

Conversation

@therealsama

@therealsama therealsama commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes 17 bugs found in an audit. Each fix has a regression test that fails without it.

What changed

Feed and swipe viewer

  • Going back to a cached feed refreshes it, instead of repeating the front page when you scroll.
  • A linked story that isn't in the feed shows once, not twice.
  • Touching during a snap-back no longer jumps to the top.

Offline app (service worker)

  • A 5xx from GitHub Pages serves the cached app instead of an error page.
  • The cached app is replaced only after the new version's files are cached, so a failed download can't leave a blank screen offline.
  • A service worker update whose files fail to download keeps the working app. Also affects main.
  • An offline launch no longer gets a just-deployed page from the browser's 10-minute cache when that version's files are missing. Navigations now revalidate, which costs one conditional request per launch. Also affects main.
  • Cache trimming never removes a file the cached app needs. On main, this breaks the offline app after enough releases.

Comments

  • The first paragraph is spaced like the others.
  • Keyboard focus stays on the replies toggle after expanding or collapsing.
  • Screen-reader and reduced-motion users see a loading skeleton, not "No comments yet."
  • A swipe panel that unmounts mid-fetch no longer blocks prefetching.

Text and data

  • The email autolinker no longer freezes on long tokens (a 60k-character hash took about 9 s; now under 1 ms).
  • Git remotes like git@github.com:user/repo.git aren't linked as emails.
  • Comment counts are never negative (some dead stories report -1).
  • Domain feeds keep paging past empty search pages (the x.com feed stopped at 425 of 457 stories).
  • #/from/. shows "No domain specified" on phones too.

Testing

  • npm run typecheck: passed
  • npm run lint: passed
  • npm run test:run: passed, 1047 tests (was 1035)
  • npm run build: passed
  • npm run e2e -- --project=chromium --project="Mobile Chrome": 433 passed, 9 skipped (442 tests, was 424)
  • Each new test fails when its fix is removed.
  • e2e/pwa-update.spec.ts serves dist/ from its own server and blocks external hosts, because Playwright's route mocks intermittently stall service worker updates.

Known limitations and follow-ups

  • Desktop scroll: if you leave a feed before its refresh lands, then return through a reload or an external link, it starts at the top. In-app Back keeps the position. Follow-up: restore the scroll and still refresh.
  • OP badge: it puts aria-label on a plain span, which axe flags for review. Follow-up.
  • First install: if the files fail to download on the very first install, the next online load fixes it, as before.

A list restored from the cache was saved to the session on the way out
even when it was never refreshed. Coming back restored it as current, so
it skipped the refresh and its next page repeated the front page. Clear
the session state instead, so returning refreshes it like a fresh visit.
The injected story was compared to the first story by reference. Once
the feed loaded its own copy of the anchored story, the check missed and
the linked story was spliced in twice, with duplicate React keys.
Compare by id.
A new touch during any running animation restored the panel and its
saved scroll, but only an interrupted commit needs that. A snap-back
leaves the panel in place, and its scroll was never saved, so the page
jumped to the top. Track whether the running animation is a commit.
…its bundles

A 5xx from Pages won the navigation race and replaced a working app with
an error page; it now counts as a network failure. The offline shell
was also replaced as soon as new HTML arrived, before its hashed bundles
were cached, so a failed bundle download left a shell that opened to a
blank screen offline. Cache the bundles first, then swap the shell.
Also correct two comments about Pages and the timeout path.
HN leaves the first paragraph as a bare text node (first<p>second), so
the p + p rule never spaced the first break. Give every p a top margin
instead. The e2e mock comment now uses HN's real markup.
Expanding or collapsing replies unmounted the pressed button and dropped
focus to <body>. When the button had focus, move it to the button that
replaces it.
Comments that hadn't loaded yet rendered as an empty tree, which says
"No comments yet." Screen readers and reduced-motion users, who get no
skeleton overlay, saw it on every story.
…otes

The email branch retried from every character of a long token with no
@, which is quadratic: a 60k-character hash froze the page for seconds.
Start a local part only where one can start. Also stop linking an
address followed by :path, such as git@github.com:user/repo.git.
Some dead stories (item 28) report descendants: -1, shown as -1
comments.
A query search can return empty pages before its estimated nbPages
(x.com: pages 9 and 10 of 11). The last page then had no hit to restart
from, so the feed ended early (425 of 457 x.com stories). Carry the
oldest hit so far in the cursor and restart from it after an empty
last page.
The mobile wrapper checked the raw route param, so a domain that
canonicalizes to nothing mounted an empty swipe viewer instead of the
"No domain specified" state desktop shows.
A panel that turns deferred keeps its fetch running, which holds the
priority slot until it settles. The deferred effect had no cleanup, so a
panel unmounted with that fetch stalled blocked prefetching until the
request settled, possibly never.
The runtime cache is FIFO-trimmed to 64 entries, but cache hits never
rewrite an entry, so chunks that rarely change (the rolldown runtime,
inserted at install right after the index bundle) stay the oldest. Once
enough deploys fill the cache, the next trim evicts a bundle the cached
shell still needs and the next offline launch is a blank screen. This
predates this branch; it is reachable after roughly 6-12 months of
regular releases.

trimCache now skips the cached offline shell's bundles, and when a new
shell is adopted, the new shell's bundles too, so the old shell stays a
working fallback until it is replaced. The cache layout is unchanged,
so VERSION stays as is.
A release that changes sw.js installs the new worker into the same
hackertok-shell cache the running one boots from. Install used to
addAll() the new index.html first and precache its bundles best-effort
afterwards, so a dropped bundle download left a shell whose bundles
weren't cached: the next offline launch was a blank screen. This is
already on main, and sw.js hasn't changed since v1.0.0, so this release
is the first time installed clients run the update install.

Install now fetches the precache into memory, caches the shell's
bundles through cacheShellAssets (the navigation-refresh path), and
only then writes the new shell. If the bundles fail, an update keeps
the cached shell; a first install has none to keep, so it caches this
one and leaves the bundles to runtime caching, as before. Install also
drops its own copy of the asset regex.

cacheShellAssets now checks this version's runtime cache only. During
a VERSION bump's install the old caches still hold the bundles, so a
global caches.match() skipped them, and activate then deleted them.

The new spec serves dist/ from an in-test server, because
context.route() can't intercept the browser's sw.js update fetch. It
blocks external hosts by DNS rather than mocking the HN APIs, because
Playwright's route interception intermittently keeps the old worker
from handing over.
…mails

The scp-remote guard let the domain backtrack, so git@gitlab.example.com:u/r.git
linked mailto:git@gitlab.example. The local-part guard also stopped linking
--name@gmail.com and _foo@bar.com, which main linked as name@ / foo@.
… shell

With GitHub Pages' max-age=600, the navigation fetch could return a
just-deployed index.html from the HTTP cache while offline. If that build's
bundles never downloaded, the app booted blank instead of falling back to
the cached shell.
@therealsama therealsama changed the title fix: twelve audit fixes across feeds, swipe, offline shell, comments and autolinking fix: 17 audit fixes across feeds, swipe, offline app, comments and autolinking Nov 29, 2026
@therealsama
therealsama merged commit 8779383 into main Nov 29, 2026
4 checks passed
@therealsama
therealsama deleted the fix/audit-feed-swipe-sw-comments branch November 29, 2026 21:05
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