Repository navigation
Description
Problem
OnDisappearing never fires on the five pushed pages when you switch tabs away from them, so the
cleanup it performs simply does not happen. Found while fixing #127, which was the other half of
the same root cause.
Detail pages and View All are pushed onto a tab's navigation stack (AppShell.xaml.cs:23-27), and
MAUI Shell gives a page in a backgrounded stack no appearing/disappearing when the tab changes.
Measured on device, two tab round-trips away from a media details page:
| Hook | Fired |
|---|---|
OnAppearing |
1 (initial navigation only) |
OnDisappearing |
0 |
Loaded / Unloaded |
1 / 0 |
OnNavigatedTo / OnNavigatedFrom |
3 / 2 |
#127 fixed the appearing half by moving the display-settings re-projection to OnNavigatedTo. The
disappearing half is untouched.
What does not run
MediaDetailsPage.OnDisappearing (and the equivalent on StaffDetailsPage,
CharacterDetailsPage, StudioDetailsPage, MediaBrowsePage):
protected override void OnDisappearing()
{
base.OnDisappearing();
_loader.OnDisappearing();
// Abandon any in-flight load / section fetch so we don't keep hitting the API after navigating
// away. ...
ViewModel.CancelInFlight();
}ViewModel.CancelInFlight() — the comment states the intent plainly, and on a tab switch it is
not honoured. Tab away from a details page mid-load and the media fetch, and any Load More on the
Characters / Staff / Recommendations sections, run to completion against AniList. That spends
rate-limit budget on a page the user has left. It also means PageLoadScope is never cancelled, so
the guards written against it are inert on this path.
_loader.OnDisappearing() — leaves DeferredContentLoader._hasAppeared true and
_pendingVersion un-bumped. The loader believes the page is still on screen after the user has left,
so IsCurrent(version) keeps returning true and a scheduled load that yields will proceed rather
than no-op. The "supersede any scheduled/in-flight load so it no-ops after the yield" comment on that
line describes behaviour that does not occur for tab switches.
Fix shape
OnNavigatedFrom is the counterpart to the OnNavigatedTo that #127 now uses, and it fired reliably
in the same measurement (2 for 2). Moving the two cleanup calls there is the obvious change. It wants
care rather than a blind move:
OnNavigatedFromalso fires on a forward navigation (details → staff details), where cancelling
in-flight work is correct and already happens today viaOnDisappearing. Confirm the two do not
double-cancel or cancel something the destination page needs.- The sort popup currently relies on
OnAppearingfiring when it closes (see the reuse-guard comment
inDetailsPageModelBase.LoadCoreAsync). Check whether a popup open/close also fires
OnNavigatedFrom/OnNavigatedTo; if it does, the popup path may start cancelling loads it did not
before. - Decide whether
OnDisappearingshould keep its calls as well. It still fires on back-navigation and
popup dismissal, so removing them outright would change those paths too.
Verify on device, not in tests
No unit test can catch this, for the same reason it could not catch #127: the page model cancels
correctly when told to, and the defect is that nothing tells it. See #131.
A repro worth capturing: open a details page on a slow connection, tab away while the spinner is up,
and watch LoggingHandler's HTTP POST/HTTP 200 lines continue after the switch.
Open question — do tab-root pages get OnDisappearing?
Not measured. It matters beyond the pushed pages: SettingsPage.OnDisappearing is what calls
FlushPendingSaveAsync, the mechanism that sends a settings change still sitting in its 1500 ms
debounce when the user tabs away (#118, #128). If tab-root pages have the same gap, that flush never
runs and a change made and tabbed away from within the debounce window relies solely on the timer.
Worth measuring before assuming the tab-root half is sound.
Related
- Display setting changes don't re-render pages the user navigates back to #127 — the appearing half of the same root cause; fixed via
OnNavigatedTo. - UI tests: nothing can catch page-lifecycle bugs on pushed detail pages #131 — why no current test layer can catch either.
- Settings saves have no durable retry, and a failed save is silently reverted #128 — depends on
SettingsPage.OnDisappearingfiring; see the open question above.
Activity
zhollis21 commentedon Aug 25, 2026
Open question answered: tab-root pages do get
OnDisappearing. The gap is specific to pushed pages.Measured on device — changed a setting on Settings, tabbed away 438 ms later (well inside the 1500 ms debounce):
The save fired on the tab switch, not on the debounce timer, which would have landed around 20:00:46.65. So
SettingsPage.OnDisappearingruns andFlushPendingSaveAsyncworks as designed. #118 and #128 are unaffected by this issue.That narrows the scope here to the five pushed pages only, and leaves the
ViewModel.CancelInFlight()and_loader.OnDisappearing()calls as the live problem.Token load races, display-setting re-rendering, and settings-save dur…
zhollis21 commentedon Aug 25, 2026
Verified against
fe4dbad(main, after #133 merged). Updated after measuring on device — the openquestions below are now answered.
Confirmed as filed. All five pushed pages call
_loader.OnDisappearing()+ViewModel.CancelInFlight()from
OnDisappearingand nothing else:MediaDetailsPage.xaml.cs:117-124,StaffDetailsPage.xaml.cs:81-88,CharacterDetailsPage.xaml.cs:81,StudioDetailsPage.xaml.cs:81,MediaBrowsePage.xaml.cs:105-109.All five already override
OnNavigatedTo, and it does one thing —ViewModel.RefreshDisplaySettings()(#127). None overrides
OnNavigatedFrom.Full hook table, measured on device (Debug +
-p:CiBuild=true, temporary logging in all fourhooks on all five pushed pages plus
SettingsPageas a control):OnAppearingOnDisappearingOnNavigatedToOnNavigatedFromThe navigation hooks are a strict superset: they fire everywhere the appearing hooks do, plus the
two tab-switch rows where those do not. So moving the cleanup changes no other path.
The two open questions in the body are answered. The sort popup fires both pairs — open fires
OnDisappearingandOnNavigatedFrom, close firesOnAppearingandOnNavigatedTo— somoving to the navigation hooks leaves the popup path behaving exactly as it does today. Forward
navigation likewise fires both, and the double-cancel it raises is already absorbed by
PageLoadScope.EnsureActive()(PageLoadScope.cs) plus the fresh token fromScope.Begin()(
DetailsPageModelBase.cs:277).DeferredContentLoaderis not symmetric across the two pairs, which constrains the fix.OnAppearing()sets_hasAppeared = true;OnDisappearing()clears it. BothIsCurrent(version)and
TrySchedulegate on it. SinceOnAppearingdoes not fire on a tab return, moving_loader.OnDisappearing()toOnNavigatedFromalone would leave_hasAppearedfalse with nohook to set it back — after one tab round-trip
TrySchedulewould return early every time and thepage would sit on its spinner permanently. The cleanup has to be paired with a re-arm from
OnNavigatedTo.Repro tooling. #125 landed runtime fault injection;
driver.ps1 fault GetMedia delay next -delay 8000holds a load open long enough to tab away mid-flight, which is what makes this reproducible on demand.
Runtime fault injection, pushed-page lifecycle, and staff name langua…
zhollis21 commentedon Aug 27, 2026
Shipped in #135 (925d79f). Verified on main: a pushed page's tab switch now routes through
_loader.OnDisappearing()(src/AniSprinkles/Pages/MediaDetailsPage.xaml.cs:117, with the lifecycle asymmetry documented at :98), andDeferredContentLoader.OnDisappearingclears_hasAppearedand bumps_pendingVersionso any scheduled or in-flight load no-ops after its yield (src/AniSprinkles/Utilities/DeferredContentLoader.cs:61-65).Note #131 remains open and is the reason this could not be caught automatically — nothing drives a real tab switch against a pushed detail page.
Token load races, display-setting re-rendering, and settings-save dur…
Runtime fault injection, pushed-page lifecycle, and staff name langua…