Repository navigation
fix: show the phone's opened comment sooner, and skip hidden comments in its swipe - #324
Merged
Merged
Conversation
When a comment's siblings failed to load, the viewer still started the swipe, on the one-comment list the failed load left. The automatic retry then brought in the siblings, but with the swipe already started the viewer showed the first of them and moved the URL there, away from the comment that was opened. The swipe now starts only once the siblings load without an error.
The swipe comment viewer showed a skeleton until it had read the comment and its parent from Firebase for the sibling list, and only then started loading the comment itself. The comment now shows as the only panel while the siblings load, and loads alongside them. Once they're in, the swipe starts on that same panel: it stays mounted, isn't fetched again, and keeps the reader's place in it. useSwipeScroll gets `resetToIndex` for this, which switches to the new list without moving the page. While the siblings retry after a failed load, the comment stays on screen instead of a skeleton. On "Ask HN: Who wants to be hired? (November 2026)" a comment now shows after 0.8-1.0s instead of 1.2s, or 2.3s instead of 2.7-2.8s on slow 4G. The swipe is ready when it was before.
The swipe comment viewer took its comments from the parent's `kids` in Firebase, which include deleted and flagged comments that the thread, like HN, leaves out when nothing is under them. Across the top 15 stories, 29 of 357 top-level comments were such comments, and so are 29 of the 438 on "Ask HN: Who wants to be hired?". Swiping onto a deleted one showed "Comment deleted" with no parent or story link. Swiping onto a flagged one showed "[flagged]" with its author. Once the list is in, the viewer reads every sibling from Firebase, and the swipe passes over the flagged and deleted ones with no replies, the rule the comment page's reply check uses. It never passes over the comment it was opened on, or one whose read fails. Those panels stay in the list, so the reads don't hold up the swipe, and a swipe under way keeps its target. The panels loaded ahead on each side are now the swipe's next stops rather than the nearest panels. On "Who wants to be hired?" the swipe starts when it did before, and passes over hidden comments from about 1.5s after the page opens, or 7.4s on slow 4G. A swipe before then can still land on one. The reads add about 620KB.
The phone's comment viewer swaps everything for "Failed to load comments" when its siblings failed to load and `isRetrying` is off. That flag is still off in the render where a load fails, and only comes on in a layout effect after it. So each failure rendered the error branch once, before paint, which unmounted the panels: the comment shown while its siblings load was mounted again, fetched again, and lost the reader's place. Scrolled 600px down it, a reader dropped to 27px in Mobile Chrome and 207px in Mobile Safari at the first failed retry. The viewer now shows the error once the retries have given up, as `SwipeStoryViewer` does. That is the only time the error showed on screen before, so offline, after giving up and on a manual retry it shows as it did.
therealsama
enabled auto-merge
November 5, 2026 18:21
kplachkov
approved these changes
Nov 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.
Follow-up to #323, which dropped the first version of the hidden-comment fix because it held up the opened comment on large threads. In this version nothing waits for the hidden-comment check. It also fixes a retry bug in the same viewer.
Changes
useSwipeScrollgetsresetToIndexfor this, which switches to the new list without moving the page. While the siblings retry, the comment stays on screen instead of a skeleton.kids, which include deleted and flagged comments with nothing under them. HN and the thread leave those out (see fix: show flagged replies on a comment's page, and two smaller fixes #321). Across the top 15 stories, 29 of 357 top-level comments were such comments. Swiping onto a deleted one showed "Comment deleted" with no links, and swiping onto a flagged one showed[flagged]with its author. Once the list is in, the viewer reads every sibling from Firebase. The swipe then passes over the flagged and deleted ones with no replies, the rule the comment page's reply check uses. It never passes over the comment it was opened on, or one whose read fails. Those panels stay in the list, so the reads don't hold up the swipe, and a swipe already under way keeps its target. The panels loaded ahead on each side are now the swipe's next stops rather than the nearest panels.Measurements
"Ask HN: Who wants to be hired? (November 2026)" has 438 top-level comments. These numbers come from opening the 41st with a Pixel 7 profile, from the time the page opens, two runs each:
The sibling reads make up the last Firebase frames here, so hidden comments are skipped from about that point. On the same thread, one swipe forward from 50364051 on main landed on 50362176, "Comment deleted". With this PR it lands on 50362186, the next live comment.
Known limitations
dead,deletedandkidswould cut that, at three reads per sibling.