Repository navigation
fix(browse): tell an empty library apart from filters that match nothing - #626
Conversation
An iOS library with no media showed "No items found / Try adjusting your filters", the same message as a filter that matches nothing, so users could not tell an empty library from an over-filtered one. When a browse comes back empty, the app now decides why. Without active filters (or a name prefix), an empty first page already means the library is empty. With filters, it asks the catalog for one unfiltered item of the library (limit 1, skip_total) as the active profile, so only empty results pay for the extra request and a profile whose rating limits hide every title also sees the empty-library state. An empty library shows "This library is empty"; otherwise the grid shows "No items match your current filters" with a Clear filters button that resets the facets and keeps the sort. If the check fails, the filter message stays. BrowseEmptyReasonTests covers the decision: no probe without filters, filters over a library with or without visible items, a failed probe, the name prefix, and the probe query's parameters.
The Apple TV library grid showed "No titles match / Try a different letter or filter." for every empty result, including a library with no media, so users could not tell an empty library from an over-filtered one. The tvOS grid now uses the same decision as iOS (BrowseEmptyReason with the one-item library probe). An empty library shows "This library is empty". When filters or the letter rail match nothing, the grid shows "No titles match your filters" with a Clear filters button that resets the facets and the letter rail and keeps the sort. Clear filters is an ordinary native button in the grid column's focus section, so Down from Sort/Filter and Left from the letter rail reach it with no extra move handling. The reload removes the button, so pressing it hands focus to the Sort pill through the control row's existing focus request.
On the no-match grid, Down from Sort/Filter left focus on Sort: the focus engine searches below the focused pill, and the centered Clear filters button sits outside that path, so only Left from the letter rail reached it. The empty-state area is now a full-width focus section. Down from either pill enters it and lands on its only focusable child, Clear filters. No move handling changes: the row's Down handler still only claims the grid when it has items.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| try await !SiloAPI.shared.catalogPage(probe).response.items.isEmpty | ||
| } | ||
| guard myGeneration == generation else { return } | ||
| emptyReason = reason |
There was a problem hiding this comment.
Race condition in iosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridViewModel.swift: the guard preceding emptyReason = reason checks only the reload generation after an asynchronous catalog probe, allowing authentication-owner or active server/profile scope changes during either request without a reload to publish an empty-state reason based on another profile's catalog visibility; the same issue occurs in iosApp/iosApp/Screens/Browse/BrowseViewModel.swift:109-109 and iosApp/iosApp/Screens/Browse/BrowseViewModel.swift:112-112. Capture the owner and active scope before the page read, then verify both alongside myGeneration after the classification await and before publishing the result.
Kody rule violation: Fence asynchronous results by scope and invalidation generation
Prompt for LLM
File iosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridViewModel.swift:
Line 282:
Race condition in `iosApp/iosApp/tvOS/Screens/Libraries/TVLibraryGridViewModel.swift`: the guard preceding `emptyReason = reason` checks only the reload generation after an asynchronous catalog probe, allowing authentication-owner or active server/profile scope changes during either request without a reload to publish an empty-state reason based on another profile's catalog visibility; the same issue occurs in `iosApp/iosApp/Screens/Browse/BrowseViewModel.swift:109-109` and `iosApp/iosApp/Screens/Browse/BrowseViewModel.swift:112-112`. Capture the owner and active scope before the page read, then verify both alongside `myGeneration` after the classification await and before publishing the result.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not changing. The reason is fenced exactly like the page it describes: items from the same fetch is published under the same myGeneration check, which is unchanged from main. A scope change cannot reach this view model either. A server change re-keys the routed subtree (.id(authContentIdentity) in ContentView), and a profile switch, sign-out or session expiry moves authState off .authenticated, which removes MainTabView/TVMainTabView and the grid with its view model. A late probe result can only land on a discarded model, never on another profile's screen.
There was a problem hiding this comment.
Agreed—given the lifecycle you described, this suggestion does not warrant a change.
The generation guard rejects stale reload results, while subtree replacement or removal prevents results from an old server/profile scope from reaching the current screen. Even if the asynchronous task retains the old view model long enough to assign emptyReason, that assignment affects only the discarded model.
My original finding assumed the same view model could remain attached to the visible grid across a scope change without a generation increment. Your explanation addresses that assumption. The added classification await alone is not evidence of a cross-profile race, so I withdraw the recommendation for this PR.
Problem
Closes #582
Validation tasks: changes #337 C1; changes #338 C1
A library with no media showed "No items found / Try adjusting your filters" on iOS and "No titles match" on Apple TV, the same message as a filter that matches nothing. Users could not tell an empty library from an over-filtered one. Empty libraries now say so, and a filter that matches nothing offers Clear filters.
Approach
limit=1,skip_total) as the active profile, so only empty results pay for the extra request, and a profile whose rating limit hides every title also sees the empty-library state.Validation
scripts/ci/check-no-api-v1.sh: pass.main(6242652): the full iOS unit suite ran 2,691 tests. The only failures areArtworkURLTests.testDeliveryCapabilityOnIOSUsesV2RouteAndResetsandImageSizeCapabilityTests.testResetClearsCapability, which fail the same way onmain. tvOSbuild-for-testingand the macOS build succeed.Simulator screenshots (iOS 26.5, tvOS 26.5):
Risks
One extra catalog request when a filtered browse comes back empty.
Checklist
AI Disclosure
mainat medium effort, checking behaviour, platform guards (iOS, tvOS, macOS), tests and commit hygiene. It checked that a stale probe result can't flash the wrong message and that the tvOS focus change followsdocs/tvos-focus.md. No findings.Note
Add tests distinguishing empty library from non-matching filters in browse
Adds BrowseEmptyReasonTests.swift covering empty-state classification in browse. Tests verify that only narrowing filters trigger a library probe, that probe results distinguish an empty library from filters that match nothing, and that probe failures keep the filtered-empty result. Also checks the probe requests one unfiltered item without a total count.
Macroscope summarized 30bf812.