Skip to content

refactor: simplify api helpers, Algolia hooks, error handling and feed paging, and drop low-value tests - #353

Merged
therealsama merged 7 commits into
mainfrom
refactor/simplify-code
Nov 27, 2026
Merged

therealsama merged 7 commits into
mainfrom
refactor/simplify-code

Conversation

@therealsama

@therealsama therealsama commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Removes dead and duplicated code, and tests that can't catch a bug, with no user-visible change: 94 files, +800 / −3,853. Each commit covers one area, so it's easiest to review commit by commit.

Changes

  • API and dead code (ee53abd): fetchBestStories and fetchNewStories share one fetchRankedStories and one cache. FEED_TYPES is now the only list of feeds. Deleted the unused Tooltip and the barrel exports that nothing imported, which also ends the barrel's circular imports.
  • Algolia hooks (6fbd452): the domain and user hooks are now thin wrappers around a new useAlgoliaInfiniteStories. DomainStories, UserSubmissions and UserProfile remount via a React key when their route param changes, instead of resetting state during render.
  • Shared helpers (786e043): errorMessage and isAbortError in utils/errors.ts replace 19 hand-written checks. useItemWithComments handles every comment load through one success handler and one error handler, instead of four copies of each. SwipeStoryViewer reuses one skeleton, one state view and one hide/show handler pair.
  • Leftover duplicates (49224f3): InfiniteStoryListPage drops resetKey, which the route keys made dead. One CommentArticleSkeleton replaces two identical skeletons. One Algolia day search replaces two; excludeTitles becomes excludeHiring.
  • loadMore (a34deb5, 24aeb88): new tests pin the top feed's day paging, session resume and list end. Then loadMore uses four small helpers instead of five copies of the dedupe filter, three of the cache refresh and two of the day loop (−105 lines).
  • Low-value tests (7bc0506): removes 187 unit and 30 e2e tests that duplicate a remaining test, restate the code, test a library, or can't fail (e.g. only not.toThrow). Also removes useItemWithComments' combined loading field, which nothing reads.

Worth a close look

  • Route keys replace the reset-during-render code, so dropping a key in App.tsx would bring back stale pages. The profile, domain and submissions switch tests catch that.
  • A search still running when you switch domain or user is now cached under its own key instead of discarded. The mobile viewers, and leaving for any other page, already worked this way.
  • Test removal leaves coverage within 0.1% (lines 93.2% → 93.1%). The removed tests that ran the few lines no longer covered didn't check what those lines do.
  • loadMore keeps its feed branches and saved-session format, so sessions saved before this still restore. The new tests pass both before and after the refactor.

Validation

Command Result
npm run typecheck passed
npm run lint passed, 0 warnings
npm run test:run 1033 passed (removed 10 tests of the old resets and 187 low-value tests; added 1 remount test and 5 loadMore tests)
npm run build passed
npm run e2e (all 4 projects) 804 passed, 44 skipped by the specs' own per-project rules

- Drop the unused Tooltip wrapper and its provider.
- Merge the best/new/show/ask ranked-list fetchers into one
  fetchRankedStories with a single ids cache.
- Use signal.throwIfAborted(), isHiringThread() and the story
  normalizer instead of inline copies.
- Define the feed types once (FEED_TYPES) and reuse feedCache's
  isStale instead of a second 5-minute check.
- Trim unused barrel re-exports and fix the two circular imports
  through components/index.ts.
- Delete the unused CachedItem and CachedFeed types.
useDomainInfiniteStories and useUserInfiniteStories were two copies of the
same paging, dedup, cache and staleness logic. Both now wrap
useAlgoliaInfiniteStories and only supply the query, the domain host
filter and the domain cold-start cap.

DomainStories, UserSubmissions and UserProfile are now keyed by their
route param in App.tsx, like the swipe viewers already were, so a new
domain or user remounts the page. That replaces the render-time state
resets and layout-effect ref resets in the three hooks.

Tests that rerendered one hook instance with a new key are replaced by a
remount test, and a new e2e test pins the profile key.
…y search

- Remove InfiniteStoryListPage's resetKey and the reset branch in
  useStaggerCascadeSlots. The list pages are keyed by feed, domain and
  user, each equal to the resetKey they passed, so a new context
  remounts the list and the reset could no longer run.
- Replace CommentDetailSkeleton and FullScreenCommentSkeleton, which
  differed only in their bottom margin, with one CommentArticleSkeleton
  that takes CommentArticle's articleClassName.
- Merge fetchFrontPageForDay and fetchTaggedStoriesForDay into one
  Algolia day search. excludeTitles only ever got the hiring titles, so
  it becomes excludeHiring and uses isHiringThread.
Pins loadMore behavior the next commit refactors: the top feed's walk
back through earlier days and its 5-empty-day limit, resuming a saved
top session on the next earlier day, and best/newest stopping at the
end of their list.
The seen-story filter was written five times, the first-page cache
refresh and the keep-or-append list update three times, and the
day-by-day Algolia loop twice. loadMore now uses takeUnseen,
showStories, loadRankedPage and loadDays, and each feed branch is a
few lines. The corrupt-session check is computed once.

The feed branches, the phase and position model and the saved session
format are unchanged, so sessions saved before this still restore.
@therealsama therealsama changed the title refactor: simplify api helpers, Algolia hooks and error handling refactor: simplify api helpers, Algolia hooks, error handling and feed paging Nov 27, 2026
Remove 187 unit tests and 30 e2e tests that duplicate a remaining test,
restate the implementation, test library behavior, or cannot fail
(only `not.toThrow`, or only assert fixture data). Coverage moves by
0.1% at most; the lines no longer run had no assertions on them.

Also remove two things only those tests used: the unused
`__getUserStoriesCacheForTests` export, and the combined `loading`
field of `useItemWithComments`, which no component reads.
@therealsama therealsama changed the title refactor: simplify api helpers, Algolia hooks, error handling and feed paging refactor: simplify api helpers, Algolia hooks, error handling and feed paging, and drop low-value tests Nov 27, 2026
@therealsama
therealsama merged commit c4ccf71 into main Nov 27, 2026
4 checks passed
@therealsama
therealsama deleted the refactor/simplify-code branch November 27, 2026 21:43
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