Skip to content

Preserve selected feature tab in Performance page exports#9861

Open
gords2 wants to merge 2 commits into
flutter:masterfrom
gords2:fix/preserve-performance-selected-tab
Open

Preserve selected feature tab in Performance page exports#9861
gords2 wants to merge 2 commits into
flutter:masterfrom
gords2:fix/preserve-performance-selected-tab

Conversation

@gords2

@gords2 gords2 commented Jun 21, 2026

Copy link
Copy Markdown

Closes #5150

Description

The Performance page tracks the selected feature tab via PerformanceController.selectedFeatureTabIndex, but that index was never written to offline exports. As a result, loading exported performance data always reset the view to the first tab instead of the tab that was active when the data was exported.

This mirrors the behavior the Memory page already implements (OfflineMemoryData.selectedTab):

  • OfflinePerformanceData now has a selectedTab field that is serialized in toJson/fromJson (defaults to 0 for backward compatibility with older export files that don't contain the key).
  • prepareOfflineScreenData writes the current selectedFeatureTabIndex into the export.
  • _loadOfflineData restores selectedFeatureTabIndex from the loaded data.

Tests

  • Updated performance_model_test.dart to assert selectedTab is created, parsed, and serialized.
  • Updated the samplePerformanceData fixture so the existing toJson round-trip test stays in sync.

I don't have a Flutter/Dart toolchain set up locally, so I couldn't run dart analyze / the test suite myself — relying on CI to validate.

@gords2 gords2 requested review from a team and kenzieschmoll as code owners June 21, 2026 05:47
@gords2 gords2 requested review from srawlins and removed request for a team June 21, 2026 05:47
@google-cla

google-cla Bot commented Jun 21, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for exporting and restoring the selected feature tab index when saving and loading offline performance data. The review feedback highlights a potential logical bug where restoring the tab index without validation could lead to it being overwritten or causing an out-of-bounds crash in the UI. Additionally, it is recommended to add a test case to verify the serialization and deserialization of non-zero tab indices.

The Performance page tracked the selected feature tab via
`selectedFeatureTabIndex`, but it was never persisted to offline exports,
so loading exported data always reset to the first tab.

Mirror the Memory page's existing behavior: serialize the selected tab
index into `OfflinePerformanceData` and restore it when loading offline
data so the user lands on the tab they exported from.

Closes flutter#5150
@gords2 gords2 force-pushed the fix/preserve-performance-selected-tab branch from e35bf0a to ece7b80 Compare June 21, 2026 05:52
Address review feedback on the offline tab restoration:

- The restored selectedFeatureTabIndex was immediately reset to 0 by the
  default-feature activation in TabbedPerformanceView. Use the restored
  index (clamped to the available tabs) when activating the default
  feature instead of hardcoding 0.
- The number of visible tabs can be smaller when loading offline data
  than when it was exported, so an out-of-range index could be passed to
  AnalyticsTabbedView. Clamp the index passed as initialSelectedIndex.
- Add a round-trip test for a non-zero selectedTab.
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.

Preserve selected feature tab in Performance page exports

1 participant