Skip to content

fix(navigation): clamp navigateViewGroup viewIndex to valid tab range#2220

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-identification-6e85
Closed

fix(navigation): clamp navigateViewGroup viewIndex to valid tab range#2220
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-identification-6e85

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented May 18, 2026

Description

Fixes a crash when navigateViewGroup is executed with only viewIndex and that index is outside the current ViewGroup menu (for example from evaluated YAML or bad app data). The action previously forwarded the raw index to PageController.jumpToPage and viewGroupNotifier.updatePage, which led to RangeError when indexing pagePayloads during rebuild.

Related Issue

None filed; found by tracing NavigateViewGroupAction vs PageGroupState initialization (which already clamps viewIndex from pageArgs).

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 cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

What Has Changed

  • Added clampViewGroupTabIndex and viewGroupMenuItemCountForContext in page_group.dart to bound indices using the nearest PageGroup ancestor’s menu length.
  • NavigateViewGroupAction now clamps viewIndex before jumpToPage / updatePage when that ancestor is found.
  • Added test/view_group_tab_index_clamp_test.dart for the clamp helper.

How to Test

  1. From modules/ensemble, run flutter test test/view_group_tab_index_clamp_test.dart.
  2. Manual: in a ViewGroup with N tabs, invoke navigateViewGroup with viewIndex set to N or higher (or negative); the app should switch to the last (or first) tab instead of throwing.

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

Note: The automation sandbox did not have flutter on PATH; please run flutter test / flutter analyze locally for the checklist items.

Duplicate check

  • Open PRs (including drafts): searched for overlapping navigateViewGroup / viewIndex / ViewGroup bounds work; no existing PR clamps this path. Related drafts (e.g. page header timers, upload path traversal, ListView scroll sync) address different root causes.
  • Merged PRs: no merged fix for unbounded NavigateViewGroupAction viewIndex.
  • Branches: no other automation branch identified for this issue.
Open in Web View Automation 

Out-of-range viewIndex values caused RangeError when updating the
global ViewGroupNotifier or calling PageController.jumpToPage.

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.

2 participants