Commit 5d9d4e4
fix(mobile): start track comments fetch on screen mount to cut load delay (#14450)
## Problem
On the mobile track detail screen, the comments section takes a while to
appear after the rest of the page is up.
The root cause is a **serial waterfall** before the comments query can
even start. The comments query (`useTrackComments`) lives inside
`CommentSectionProvider` → `CommentPreview`, which only mounts after
three gates clear in order in
[`TrackScreen.tsx`](packages/mobile/src/screens/track-screen/TrackScreen.tsx):
1. `useTrackByParams` resolves the track
2. `useUser(track.owner_id)` resolves — the `if (!track || !user) return
<Skeleton/>` early-return blocks `CommentPreview` from mounting, **even
though comments don't need user data**
3. `ScreenSecondaryContent` waits for `isPrimaryContentReady` before
mounting its children
So comments only begin fetching well after track + owner data have
loaded and the primary content is painted — not in parallel.
There was no waterfall at the *endpoint* level (`GET
/tracks/{id}/comments`, no artificial delay), and a skeleton already
exists in `CommentPreviewContent` — the issue is purely *when* the fetch
starts.
## Fix
Add `usePrefetchTrackComments` (`packages/common`) and call it at the
top of `TrackScreen`, before the early-return and the secondary-content
gate. It fires the comment-list query **on mount, in parallel with the
track/user fetch**, as soon as a `trackId` is known — from route params
when navigating by id, so it can start *before the track even resolves*.
Because the comment-list query uses `gcTime: 0` (evicted the instant no
observer is mounted), a one-shot prefetch wouldn't survive. So
`usePrefetchTrackComments` keeps a **live observer** mounted at the
screen level, using the default `Top` sort + page size to match what
`CommentSectionProvider` requests — guaranteeing a cache hit when the
comment section finally mounts.
Net effect: by the time `CommentPreview` renders, the comments are
usually already in cache, so the skeleton rarely flashes and comments
appear with (or shortly after) the rest of the page instead of well
after it. Comment-disabled tracks are skipped once that flag is known.
### Implementation notes
- Extracted the raw infinite query in `useTrackComments.ts` into a
shared `useTrackCommentsQuery` base hook so both `useTrackComments`
(which adds the error toast + `useComments` hydration) and the new
`usePrefetchTrackComments` reuse one definition — no duplicated
`queryFn`. Behavior of `useTrackComments` is unchanged.
## Testing
- `turbo run typecheck --filter=@audius/common --filter=@audius/mobile`
— passes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent e9ad034 commit 5d9d4e4
4 files changed
Lines changed: 84 additions & 5 deletions
File tree
- .changeset
- packages
- common/src/api/tan-query
- comments
- lineups
- mobile/src/screens/track-screen
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 37 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
| |||
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
31 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
32 | 41 | | |
33 | 42 | | |
34 | 43 | | |
| |||
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
42 | | - | |
43 | 51 | | |
44 | 52 | | |
45 | | - | |
| 53 | + | |
46 | 54 | | |
47 | 55 | | |
48 | 56 | | |
| |||
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
81 | 114 | | |
82 | 115 | | |
83 | 116 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
| |||
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
37 | 58 | | |
38 | 59 | | |
39 | 60 | | |
| |||
0 commit comments