Skip to content

fix(page): cancel header poll timers and dedupe title bar storage listeners#2217

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-identification-4a99
Draft

fix(page): cancel header poll timers and dedupe title bar storage listeners#2217
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-identification-4a99

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented May 17, 2026

Description

Fixes lifecycle issues in PageState when optional header features attach storage-driven rebuild hooks: the title-bar height path accidentally registered the same ModelChangeEvent listener three times, and periodic Timer instances were never cancelled in dispose(). Both patterns waste work after navigation and increase the risk of calling setState while the page is tearing down.

Related Issue

None filed; found during review of Page header / device-metric code paths.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Documentation update
  • Refactoring (no functional changes)

What Has Changed

  • Replaced the three identical eventBus.on<ModelChangeEvent>().listen blocks in _listenToTitleBarHeightChanges with a single subscription stored in _titleBarHeightStorageSubscription.
  • Stored the collapsible-header storage listener in _headerVisibilityStorageSubscription (same pattern, single listener) and guarded callbacks with mounted where missing.
  • _setupPeriodicStorageCheck / _setupPeriodicVisibilityCheck now assign to _titleBarHeightPollTimer / _headerVisibilityPollTimer (cancelling any prior timer before replacing).
  • dispose() cancels those subscriptions and timers before removing route observers and disposing the scope manager.

How to Test

  1. From modules/ensemble, run flutter analyze lib/framework/view/page.dart.
  2. Run flutter test (or at least smoke tests) for the module.
  3. Manually: enable listenTitleBarHeightStorage / collapsible header storage bindings, navigate away quickly, and confirm no exceptions from timers or event bus callbacks (sandbox here had no Flutter SDK on PATH).

Screenshots / Videos

N/A

Checklist

  • I have run flutter analyze and addressed any new warnings
  • I have run flutter test and all tests pass
  • I have tested my changes on the relevant platform(s)
  • I have updated documentation if needed
  • My changes do not introduce new warnings or errors

Duplicate check

Open in Web View Automation 

PageState registered the same ModelChangeEvent listener three times for
titleBarHeight storage updates, and never cancelled periodic Timers in dispose.

Co-authored-by: Sharjeel Yunus <sharjeelyunus@users.noreply.github.com>
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