Skip to content

fix(app): cancel the HomePage tab prewarm timers on dispose - #14406

Merged
Git-on-my-level merged 6 commits into
mainfrom
task/msd-ui-home-prewarm-timers
Sep 17, 2026
Merged

Git-on-my-level merged 6 commits into
mainfrom
task/msd-ui-home-prewarm-timers

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

What changed and why

HomePage still armed one Timer per non-selected IndexedStack tab (350ms + n×180ms) and never cancelled them. That is the same class as #14373: work scheduled on HomePage that outlives dispose and fails flutter_test _verifyInvariants. Hold the timers on the State and cancel them in dispose.

Product invariants affected

none

How it was verified

  • Before the cancel: TZ=UTC bash app/test.sh test/widgets/home_announcement_timer_test.dart --name 'HomePage tab prewarm timers are cancelled on dispose' failed with A Timer is still pending even after the widget tree was disposed and dumped the 350/530/710ms timers created in _prewarmRemainingTabs.
  • After the cancel: the same command printed All tests passed!
  • TZ=UTC bash app/test.sh
  • make preflight
  • dart format --line-length 120 on the two touched Dart files
  • Not exercised live in a device build; the defect is the pending-timer invariant, which the widget test is the user-facing path for.

Tests

app/test/widgets/home_announcement_timer_test.dart — new HomePage tab prewarm timers are cancelled on dispose. Disposes without elapsing 350ms so leftover prewarm timers fail _verifyInvariants. A further unregistered HomePage timer that is still pending at test end fails the same way. Duration.zero work that fires in the 1ms Upgrader flush would not; asserting list membership itself needs C1 CaptureLifetime, which this lane does not have.

Failure class (fixes)

Failure-Class: FC-timer-after-dispose


Coordinator notes

Stacked on #14373, and it carries that PR's firebase_core_platform_interface dev-dependency
fix merged in, so its own Dart Analyze & Tests can pass the analyzer ratchet.

Two corrections the builder made to the brief it was given, both right and both worth
recording: the four prewarm delays are 350/530/710/890 ms but _prewarmRemainingTabs skips
the selected slot, so the default home tab arms three, not four. And the new test catches a
fifth unregistered Timer only because any leftover pending timer fails the invariant at test
end; it does not assert list membership, and it would need CaptureLifetime (a different
lane's unmerged file) to do that or to catch a Duration.zero timer firing inside the 1 ms
Upgrader flush. The builder said so rather than faking a source scrape, which is the right
answer.

Found while in this file and deliberately not fixed here, to keep the diff to timer
lifecycle: _HomePageProductState.initState does not re-check mounted after
await Permission.notification.isGranted. That is a real instance of the async-lifecycle
class this program exists to close, and it gets its own PR rather than riding along in this
one. Roughly ten other post-frame callbacks in this file do re-check mounted; the
Future.delayed(Duration.zero) in build on reconnect is uncancelled but its callback checks
mounted. There is no Timer.periodic in the file.

Two tooling defects surfaced by this work, neither of which this PR changes:

  • scripts/failure-class prepare did not demand a new class, but it reported three unrelated
    advisory hits because FC-timer-after-dispose.json uses prefix hints such as
    app/lib/pages/home/ that fnmatch does not treat as globs — it needs
    app/lib/pages/home/**.
  • make preflight is hardcoded to origin/main, so on a stacked branch it fails
    instance_fix_mutates_registry because the stacked range still contains the parent's new
    failure-class definition. Against the stacked parent it is green: 14 checks in 15.19 s.

🤖 Generated with Claude Code

Review in cubic

Git-on-my-level and others added 6 commits September 17, 2026 23:23
A 2s Future.delayed survived unmount and failed flutter_test invariants; hold a Timer on the State and cancel it in dispose.

Co-authored-by: Cursor <[email protected]>
The HomePage timer widget test added in this PR imports
firebase_core_platform_interface/test.dart for setupFirebaseCoreMocks.
That package is a transitive dependency of the already-declared
firebase_core and does not re-export the test helper, so the analyzer
ratchet counted a new depend_on_referenced_packages occurrence
(5 found, baseline 4) and Dart Analyze & Tests failed.

Declaring it changes no resolved version and adds no package to the
tree: pubspec.lock moves the same 5.4.2 from "transitive" to
"direct dev". This follows the existing convention in dev_dependencies,
where async and stream_channel are declared for the same reason.

Failure-Class: none

Co-Authored-By: Claude Opus 5 <[email protected]>
The 350ms-staggered IndexedStack prewarm Timers survived unmount the same way the announcement delay did. Hold them on the State and cancel in dispose.

Failure-Class: FC-timer-after-dispose
Co-authored-by: Cursor <[email protected]>
Two conflicts, both resolved mechanically and verified rather than
assumed:

app/lib/pages/home/page.dart — both hunks are purely additive on this
side (the _prewarmTimers list and its dispose loop) with an empty
origin/main side, so this branch's lines are kept. A script resolved
only blocks whose main side was empty and would have refused any block
where both sides had content.

app/test/widgets/home_announcement_timer_test.dart — this side is a
strict superset: it carries main's 'announcement delay is cancelled on
dispose' test plus 'tab prewarm timers are cancelled on dispose'.
Confirmed by comparing the test names on both sides before taking ours.

Both tests pass after the merge.

Committed with OMI_SKIP_WEB_FORMAT=1. The pre-commit hook refuses to run
a floating prettier because the pinned 2.8.8 is not installed in
web/app, and it warns that a floating version reformats files into a
shape CI rejects. All 11 staged web files are byte-identical to
origin/main — they arrive through this merge and are already formatted
there — so there is nothing for the formatter to change, and the CI
formatting check still runs.

Co-Authored-By: Claude Opus 5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit b0f8455 into main Sep 17, 2026
43 checks passed
@Git-on-my-level
Git-on-my-level deleted the task/msd-ui-home-prewarm-timers branch September 17, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant