Skip to content

Adult-content setting commits 1.5s late and notifies nobody, leaving 18+ results on screen #118

Closed

Description

@zhollis21

Background

AppSettings.DisplayAdultContent is what every browse surface filters on, but it is not written when the user flips the toggle. SettingsPageModel debounces 1500 ms (DebouncedSaveAsync), saves to AniList, and the value only reaches AppSettings when the server response is applied. So there is a window of a second and a half plus a network round trip where the user believes adult content is off and the app still thinks it is on.

Nothing notifies anyone when that commit finally lands. Every affected page checks the setting only when it appears, which misses two cases:

  1. The page is already visible when the commit lands — no OnAppearing fires.
  2. The page reappeared during the window, read the old value, and cache-hit — so its next check is a whole tab cycle away.

Symptoms

  • Turn adult content off, return to a browse surface quickly. The 18+ results already on screen stay there, and stay there past the point where the setting has committed.
  • Before the paging filter was pinned in Replace hamburger flyout with a bottom tab bar (#43) #116, it was worse: page 1 held 18+ items under the old policy while Load More fetched SFW pages under the new one, mixing both into a single list. Pinning removed the mixing but not the staleness — pages are now consistently old policy until something invalidates them.

Affected

Surface Where it reads the setting
SearchPageModel OnAppearingAsync compares against _searchedWithAdultContent; paging pinned to _seededDisplayAdult (#116)
DiscoverPageModel LoadAsync compares against _loadedWithAdultContent; rows page live through DiscoverSectionFetch
MediaBrowsePageModel Same shape as Discover — IsBusy guard plus a live-reading DiscoverSectionFetch
MyAnimePageModel (Library) Added during implementation. Filters via MediaListSectionsMerger.OrderAndFilterGroups while building sections, but LoadAsync short-circuits on a five-minute freshness window that never compared the setting

DiscoverSectionFetch.PageAsync resolves AppSettings.DisplayAdultContent per page, so Discover rows and View All can still mix policies in the way Search no longer can.

Proposal

Commit the value the moment the toggle flips, rather than notifying about a late commit.
SettingsPageModel.OnDisplayAdultContentChanged writes AppSettings.DisplayAdultContent (and
persists it) synchronously, before starting the debounce. The AniList save still runs on the existing
1500 ms debounce; only the local commit moves.

That removes the window rather than reacting to it. A browse surface can only appear after the user
leaves Settings, and by then the value is already correct — so the invalidation checks those surfaces
already have (DiscoverPageModel.LoadCoreAsync's adultChanged, SearchPageModel.OnAppearingAsync,
MediaBrowsePageModel.LoadAsync) start working with no new machinery.

Pin the paging filter the way SearchPageModel now does via _seededDisplayAdult:
DiscoverSectionFetch.PageAsync takes the display-adult value as a parameter instead of reading the
static per page, and each caller passes the value its current result set was seeded under. This is a
live path, not only hardening — once a commit lands while Discover is on screen, the next horizontal
Load More fetches under the new filter and appends onto the old one. The IsBusy || _refreshEvaluating
guards added in #116 do not cover it, because no reload is involved.

Rejected: a static change notification

This section originally proposed an event (or version counter) on AppSettings with
SearchPageModel, DiscoverPageModel and MediaBrowsePageModel subscribing. Dropped during planning:

  • With an immediate commit there is no remaining staleness for it to fix.
  • MediaBrowsePageModel is registered transient (MauiProgram.cs:155), not singleton as the
    original note assumed — subscribing it to a static event would leak one page model per View All
    navigation. The lifetime hazard that note flagged is a reason not to build the event rather than a
    reason to build it carefully.

It stays available if a future commit path can ever fire while a browse surface is visible. Today the
only two commit points are SettingsPageModel and MyAnimePageModel, both of which require their
own tab.

Notes

Found by review on #116 (four separate comments across the three surfaces). Not a regression from that PR — the live-read pattern predates it for Discover and View All, and Search inherited it during the extraction.

The testability note originally here is out of date: #62/#123 landed and PageModel tests exist. What
remains untestable is specifically the commit — SyncFromViewer ends in Save() →
Preferences.Default.Set, which throws off-device. #121 removes that, so it should land alongside or
before this.

Acceptance

  • AppSettings.DisplayAdultContent reflects the toggle immediately, with no debounce or network
    round-trip in between.
  • Turning adult content off and navigating straight to a browse surface shows results under the new
    policy, rather than leaving 18+ results visible until a tab cycle.
  • DiscoverSectionFetch-based paging cannot mix two policies within one result set.
  • Library re-filters on return rather than holding 18+ entries for its five-minute refresh window.
  • A refresh elsewhere in the app cannot sync the pre-change value back over a local change that has
    not reached AniList yet.

Activity

  1. added
    bug
    p2-high
    on Aug 22, 2026
  2. zhollis21 commented on Aug 23, 2026

    @zhollis21
    OwnerAuthor

    Verification notes (checked against origin/main @ 57d4506):

    • Confirmed as written. The chain is OnDisplayAdultContentChanged (SettingsPageModel.cs:443) →
      TriggerAutoSave (:458) → DebouncedSaveAsync (:468, await Task.Delay(1500, token)) →
      SaveSettingsAsync → PopulateFromUser(updatedUser) (:508) → AppSettings.SyncFromViewer(user)
      (:350). Nothing writes AppSettings.DisplayAdultContent before that.
    • Correction to the proposal: AppSettings.Storage.cs has no ApplyFrom(user) method. The
      commit point named in the body is SyncFromViewer(AniListUser) at AppSettings.Storage.cs:44,
      which sets the four properties and then calls Save().
    • AppSettings today is four plain auto-properties (AppSettings.cs:11-14) — no
      INotifyPropertyChanged, no event, no version counter. Nothing to subscribe to yet.
    • Live-read sites confirmed: DiscoverSectionFetch.cs:33 (per page, shared by Discover rows and
      View All), DiscoverPageModel.cs:193, MediaBrowsePageModel.cs:158, SearchPageModel.cs:107.
      SearchPageModel pins page 1's value at :260 (_seededDisplayAdult); DiscoverSectionFetch
      has no equivalent.
    • The testability note in the body is now partly out of date. Extract AniSprinkles.Core so PageModels can be tested (#62, #117) #123 landed, and PageModel tests
      exist (SearchPageModelTests, DiscoverPageModelTests, SettingsPageModelTests, …). What is
      still untestable is specifically the commit: SyncFromViewer ends in Save() →
      Preferences.Default.Set, which throws NotImplementedInReferenceAssemblyException off-device.
      That is exactly Give AppSettings an injectable preferences store so its callers are testable #121, so Give AppSettings an injectable preferences store so its callers are testable #121 landing first makes this issue's acceptance criteria testable
      rather than assertion-by-eye.
  3. zhollis21 commented on Aug 23, 2026

    @zhollis21
    OwnerAuthor

    Updated during planning. The proposal changed from a static change notification to committing AppSettings.DisplayAdultContent synchronously when the toggle flips, plus passing the pinned value into DiscoverSectionFetch.PageAsync.

    Two reasons the event was dropped: an immediate commit leaves no staleness window for it to close (a browse surface can only appear after the user leaves Settings), and MediaBrowsePageModel is registered transient at MauiProgram.cs:155 rather than singleton as the original note assumed — a static event would leak one page model per View All navigation.

    Also corrected: the commit point is SyncFromViewer(AniListUser), not ApplyFrom(user), and the note about this being untestable is superseded by #123. The acceptance criteria were reworded to match.

  4. zhollis21 commented on Aug 24, 2026

    @zhollis21
    OwnerAuthor

    Scope grew twice during implementation, both from tracing rather than guessing.

    Fourth surface: Library. The Affected table listed Search, Discover and View All. MyAnimePageModel also filters on the setting (MediaListSectionsMerger.OrderAndFilterGroups), and its LoadAsync short-circuit weighed only auth and a five-minute freshness window — it never compared the setting. That made it the worst of the four, not the mildest: the other three clear on the next appearance, whereas Library held 18+ entries for up to five minutes no matter how many times you tabbed back. Fixed by giving it a _loadedWithAdultContent comparison like the others.

    A viewer sync could revert the local commit. MyAnimePageModel.LoadAsync calls AppSettings.SyncFromViewer(viewer). Inside the 1500 ms debounce the server still reports the old value, so a Library load in that window turned the toggle back on app-wide. Reproduced with a throwaway test before fixing — AppSettings.DisplayAdultContent came back True after the load. The Library fix above made this more reachable, since Library now reloads precisely when the setting has just changed.

    Fixed with two complementary changes:

    • SettingsPage.OnDisappearing calls a new SettingsPageModel.FlushPendingSaveAsync, sending a pending change on navigate-away. Worth having regardless — a change made and then backgrounded was previously lost with the debounce.
    • AppSettings raises a pending flag in SetDisplayAdultContent that makes SyncFromViewer skip that one field until ConfirmDisplayAdultContentSaved (any viewer response reaching SettingsPageModel.PopulateFromUser) or Clear on sign-out.

    The flush alone was considered and is not sufficient: Shell does not guarantee the outgoing page OnDisappearing runs before the incoming page OnAppearing, OnDisappearing cannot block on a network call without stalling the transition, and a failed save leaves the server genuinely stale. The flag encodes the invariant that actually holds — a local change outranks the server copy until the server confirms it.

    Separately filed #127 for the general case: title language, score format and section order have the same navigate-back staleness, but they change how already-fetched items render rather than which items exist, so they want a broadcast and re-projection rather than the compare-and-refetch used here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugp2-high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions