Skip to content

fix: treat a feed refresh with no stories as failed - #289

Merged
therealsama merged 1 commit into
mainfrom
fix/empty-feed-refresh-loop
Oct 6, 2026
Merged

therealsama merged 1 commit into
mainfrom
fix/empty-feed-refresh-loop

Conversation

@therealsama

@therealsama therealsama commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

When a feed refresh came back with no stories, the feed stayed marked as cached, and the swipe viewer and desktop list paged through every older day. This happens on main. It came up while reviewing #288, which didn't cause it. This branch is rebased onto main with #288 merged.

The bug

Opening a feed from its cache refreshes it in the background. Until the refresh lands, the feed counts as cached (isFromCache), and SwipeStoryViewer and StoryList call loadMore whenever that's set and nothing is loading or failed. The page fetchers (fetchTopStories, fetchBestStories, fetchNewStories, fetchRankedStories) drop each story whose Firebase read fails, so when every read fails the request still succeeds, with an empty page. The feed stayed marked as cached, each loadMore fetched the next page, and on Top, where every page after the first is an older day, the viewer went through the whole year. In a Playwright run at phone size, with a mock that returns three stories a day, that was 364 day requests and 1,097 panels in under three seconds, in both Chromium and WebKit.

The trigger is rare: every story read has to fail or come back empty while the list of ids still loads, as in a Firebase outage or a permissions error. I haven't seen it happen against the live API.

The fix

useInfiniteStories now throws when a refresh's page is empty, for Top, Best/New and Ask/Show. That goes through the existing error path. The cached stories stay on screen, the error stops the eager loadMore calls (both check !error), and useAutoRetry retries after 2, 4 and 8 s. A retry is still a refresh, so it asks for the front page again, not an older day. An empty page after the first one still just adds nothing, as before. #288's check that a refresh's page isn't empty before it keeps the reader's stories can't fail any more, so it's removed.

The visible change: if the retries also come back empty, the reader sees the cached stories and the usual error with a retry button, where before they got a year of older days.

One case the retries can't fix: Best, New, Ask and Show keep their list of ids in memory for 5 minutes, even when it's empty. If Firebase returns an empty or missing list, the retries reuse it and fail again, and a manual retry works only after those 5 minutes. Top reads its list on every attempt, and failing story reads are retried on every feed. I haven't seen Firebase return an empty list, so the fetchers are left as they are.

Testing

  • npm run typecheck, npm run lint and npm run test:run pass (1095 tests, 4 new).
  • npm run e2e: 896 passed, 44 skipped (chromium, firefox, Mobile Safari, Mobile Chrome), with retries off.
  • New unit tests: an empty refresh fails and keeps the cached stories (Top, Best, Ask), and the retry after it loads the front page. All 4 fail on main.
  • New e2e tests use a cached Top feed whose story reads all fail. They check that the swipe viewer (mobile-swipe.spec.ts, all four browsers) and the desktop list (story-browsing.spec.ts, chromium and firefox) make no day requests in 3 s and keep the cached stories. They passed 30/30 (5 runs each). With main's hook all 6 failed, both before and after fix: keep the story on screen in the swipe viewer, load past Algolia's 1,000-result cap, and two smaller fixes #288 merged: the viewer made 147 to 364 day requests and the desktop list 20 to 55.

Opening a feed from its cache refreshes it, and the swipe viewer and
the desktop list call loadMore for as long as the feed counts as
cached. The page fetchers drop every story whose read fails, so when
all the reads fail the page request still succeeds, with no stories.
That refresh left the feed marked as cached, so loadMore kept fetching
the next page. On Top, where each page after the first is an older
day, the new e2e tests saw the swipe viewer make 364 day requests in
three seconds, the whole year, and the desktop list up to 54.

A refresh that brings no stories back now fails like any other failed
request: the cached stories stay, the error stops the eager loadMore
calls, and the automatic retry asks for the front page again.
@therealsama
therealsama force-pushed the fix/empty-feed-refresh-loop branch from dced13b to 79af10d Compare October 6, 2026 08:55
@therealsama
therealsama enabled auto-merge October 6, 2026 09:24
@therealsama
therealsama merged commit f0e38e1 into main Oct 6, 2026
4 checks passed
@therealsama
therealsama deleted the fix/empty-feed-refresh-loop branch October 6, 2026 09:31
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