Skip to content

[Inflight/Candidate][iOS] Fix for unnecessary arrange passes in CollectionView2 - #39396

Merged
kubaflo merged 1 commit into
dotnet:inflight/candidatefrom
BagavathiPerumal:fix-39395
Oct 16, 2026
Merged

kubaflo merged 1 commit into
dotnet:inflight/candidatefrom
BagavathiPerumal:fix-39395

Conversation

@BagavathiPerumal

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Root cause

The issue occurs because TemplatedCell2 used the most recent managed arrange size to determine whether UIKit had changed the cell’s native bounds. Preferred-size calculations can update this value before UIKit applies its final bounds, making native size changes difficult to detect. PR #38815 allowed any pending arrange to trigger a final arrangement, resulting in redundant arrange passes when the native bounds had not changed and increasing the count to approximately 354.

Solution description

The fix involves tracking UIKit’s native bounds size separately from the last managed arrange size. LayoutSubviewscompares consecutive native bounds and performs a pending final arrangement only when the native bounds have changed. This preserves the rotation correction and required inline arrangements for dynamically rebuilt content while avoiding redundant final arrangements when the native bounds remain unchanged. The corrected implementation reduced the arrange-pass count to approximately 327–328.

Reason for test level changes:

The CollectionView2 arrange count increased because recycled or rebound cells now require an inline managed arrangement after measurement invalidation. This work is necessary to ensure dynamically rebuilt child content receives valid geometry and does not render blank. In addition, a genuine native bounds change, such as device rotation, requires a final arrangement using the bounds supplied by UIKit.

These required arrangements raise the valid count above the previous baseline, which was established before the current dynamic-content and rotation layout lifecycle. The baseline is therefore increased from 276 to 313 based on repeated corrected runs producing 327–328 arrangements after the existing 5% margin is applied. This is the smallest baseline that accepts valid behavior while continuing to reject the redundant 354-pass behavior.

Regression PR

PR #38815

Validated the behavior in the following platforms

  • iOS
  • Mac
  • Window
  • Android

Issues Fixed

Fixes #39395

Output

Platform Before After
iOS
BeforeFix-25671.mov
AfterFix-25671.mov

…iOS CollectionView2 by tracking native bounds changes separately and refining the conditions for inline and final arrangements.
@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Oct 15, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@BagavathiPerumal BagavathiPerumal added the community ✨ Community Contribution label Oct 15, 2026
@BagavathiPerumal BagavathiPerumal changed the title [WIP][Inflight/Candidate][iOS] Fix unnecessary arrange passes in CollectionView2 [WIP][Inflight/Candidate][iOS] Fix for unnecessary arrange passes in CollectionView2 Oct 15, 2026
@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 15, 2026
@kubaflo

This comment has been minimized.

@github-actions github-actions 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.

Expert Review — 0 findings

Reviewed commit cd659ce.

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Expert Review — 1 findings

See inline comments for details.

MauiBot

This comment was marked as outdated.

@BagavathiPerumal

Copy link
Copy Markdown
Contributor Author

AI Review Summary

@BagavathiPerumal — new AI review results are available based on commit cd659ce.

Gate Partial Confidence Low Platform iOS

🗂️ Review Sessions — click to expand

🚦 Gate — Test Before & After Fix

Gate Result: ❌ FAILED

Platform: IOS · Base: inflight/candidate · Merge base: 40a966c8

🩺 Test does not reproduce the bug — ran the same in both states (PASS without fix, PASS with fix). The repro test is not exercising the issue. Strengthen the test before reviewing the fix.

Test Without Fix (expect FAIL) With Fix (expect PASS)
🖥️ Issue25671 Issue25671 ❌ PASS — 630s ✅ PASS — 130s
🔴 Without fix — 🖥️ Issue25671: PASS ❌ · 630s
(no coded error found; showing last 1200 chars)

n, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.07]   Discovering: Controls.TestCases.iOS.Tests
[xUnit.net 00:00:00.20]   Discovered:  Controls.TestCases.iOS.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 10/15/2026 5:48:49 AM FixtureSetup for Issue25671(iOS)
>>>>> 10/15/2026 5:48:54 AM LayoutPassesShouldNotIncrease Start
>>>>> 10/15/2026 5:49:13 AM LayoutPassesShouldNotIncrease Stop
Measure passes: 271, Arrange passes: 227
  Passed LayoutPassesShouldNotIncrease [18 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 1.7327 Minutes
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx

🟢 With fix — 🖥️ Issue25671: PASS ✅ · 130s
(no coded error found; showing last 1200 chars)

, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.05]   Discovering: Controls.TestCases.iOS.Tests
[xUnit.net 00:00:00.19]   Discovered:  Controls.TestCases.iOS.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 10/15/2026 5:55:29 AM FixtureSetup for Issue25671(iOS)
>>>>> 10/15/2026 5:55:33 AM LayoutPassesShouldNotIncrease Start
>>>>> 10/15/2026 5:55:51 AM LayoutPassesShouldNotIncrease Stop
Measure passes: 312, Arrange passes: 231
  Passed LayoutPassesShouldNotIncrease [18 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 37.8105 Seconds
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx

⚠️ Failure Details

  • ❌ Issue25671 PASSED without fix (should fail) — tests don't catch the bug

📁 Fix files reverted (1 files)

  • src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

📋 Pre-Flight — Context & Validation

Pre-Flight Context

PR snapshot: #39396 is a draft targeting inflight/candidate (40a966c82c8a) from fix-39395 (cd659ceb838b). The immutable submission contains one commit and modifies two files: 15 additions and 14 deletions. This is context gathering only, not an exhaustive review or recommendation.

Reported problem and provenance

Changed files and mechanism

File Submitted change
src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs Separates native UIKit bounds history from managed arrange history and changes when preferred sizing or LayoutSubviews performs an arrange.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25671.cs Raises the iOS CollectionViewHandler2 arrange baseline from 276 to 313; the measure baseline remains 373.
The production lifecycle now works as follows:

  • Binding or reuse resets managed arrange state and invalidates measurement.
  • During PreferredLayoutAttributesFittingAttributes, an external invalidation or changed constraints permits synchronous inline arrangement. An arrange-induced invalidation can also arrange when measurement produces a different size.
  • This effectively restores the broader preferred-sizing behavior needed by [iOS] CollectionView2: Fix layout for dynamically rebuilt item content #37437 instead of always deferring constraint changes as [Inflight/Candidate] [iOS] Fix for CollectionView layout issue after iOS device rotation #38815 did.
  • Two new fields, _hasNativeBoundsSize and _lastNativeBoundsSize, track consecutive UIKit Bounds.Size values independently of _lastArrangedSize.
  • LayoutSubviews records every observed native size. A pending final arrange no longer triggers by itself: outside safe-area changes, native bounds must have changed, together with either pending arrange work or compatibility between measured constraints and current bounds.
  • Safe-area reconciliation remains a separate reason to arrange.
  • ResetArrangeState resets managed arrange state but does not reset the two new native-bounds fields. Consequently, native bounds history persists across PrepareForReuse, Unbind, and rebinding of the same cell; whether that persistence is intentional is not established by the submitted tests.

The pass-count test scrolls down three times and up twice, regenerates a 200-item source with different text lengths, then scrolls down twice and up twice before reading aggregate measure/arrange counters. For CollectionViewHandler2 on iOS:

  • Measure assertion: 373 × 1.05 = 391.65.
  • Submitted arrange assertion: 313 × 1.05 = 328.65, meaning an integer count of 328 passes but 329 fails.
  • The previous effective arrange ceiling was 276 × 1.05 = 289.8.
  • The reported approximately 354-pass behavior would still exceed the submitted ceiling.

Platform-sensitive paths

  • The implementation is the UIKit-backed Items2/iOS/TemplatedCell2 path used by CollectionViewHandler2. The related [iOS] CollectionView2: Fix layout for dynamically rebuilt item content #37437 history explicitly identifies this handler as shared by iOS and MacCatalyst, although [Inflight/Candidate][iOS] Fix for unnecessary arrange passes in CollectionView2 #39396 reports validation only on iOS.
  • The changed test compiles under ANDROID || IOS, but the modified threshold is inside the iOS branch and applies only when the displayed handler name is CollectionViewHandler2. Android limits and the legacy iOS handler limits are unchanged.
  • The affected lifecycle includes ordinary item cells, recycled/rebound cells, supplementary headers and footers, vertical and horizontal constraints, MeasureFirstItem caching, and explicit non-uniform safe-area edges.
  • Rotation is especially sensitive because preferred constraints can change before UIKit applies final bounds. RTL variable-height content is covered by the existing [MAUI] I1_RTL_FlowDirection - Rotating the iOS simulator causes the item layout to change #38622 screenshot scenario.
  • MacCatalyst runtime behavior remains relevant because of the shared handler, but its pass-count and rotation behavior are not covered by this submission’s changed test or the PR’s checked validation list.

Required later validation

The specified validation platform is iOS. The supplied gate result is authoritative: Gate ❌ FAILED — tests did NOT behave as expected. It was not rerun. The failing test identity, observed values, base/head behavior, and failure logs were not supplied, so those details remain unknown.

A later dedicated validation should establish:

  1. The exact Issue25671.LayoutPassesShouldNotIncrease measure and arrange counts over repeated iOS CollectionViewHandler2 runs, including the attached LayoutPasses.log, and whether head remains at or below the effective 328-pass ceiling.
  2. Whether the expected gate relationship holds on immutable base versus head; the current failed gate cannot be interpreted as either a production failure or a test-threshold problem without its detailed output.
  3. The [MAUI] I1_RTL_FlowDirection - Rotating the iOS simulator causes the item layout to change #38622 RTL rotation screenshot behavior, ensuring cells retain correct size and position after UIKit changes bounds.
  4. The CollectionView item content renders with zero width on iOS (CollectionViewHandler2) #37427 dynamic-content rendered-pixel regression after recycling/rebinding, because the preferred-sizing conditions were changed specifically to preserve synchronous content arrangement.
  5. Focused coverage for the adjacent paths touched by the same state machine: safe-area reconciliation, MeasureFirstItem, grouped supplementary views, horizontal layouts/CarouselView, and reuse where native bounds do not change.
  6. Whether retaining _lastNativeBoundsSize across reuse and rebinding correctly distinguishes a real UIKit transition from stale bounds history.
  7. MacCatalyst behavior separately if that shared-handler impact is required for acceptance; the PR currently marks Mac validation unchecked.

Remaining uncertainties

  • The gate’s concrete evidence is unavailable beyond the supplied failed status.
  • The Azure build linked from [inflight regression] LayoutPassesShouldNotIncrease UI test failing in candidate PR 38782 #39395 and the PR-triggered pipeline outcomes are unknown; GitHub comments only establish that pipelines were started.
  • The claimed approximately 327–328 corrected count and approximately 354 regressed count are PR-description claims, not independently verified results in the available context.
  • The submitted test only raises an aggregate upper bound; it does not directly assert the native-bounds transition logic, absence of redundant final arrangements, or correct rendering after rotation/reuse.
  • No new regression test specifically models consecutive native bounds snapshots or persistence of those snapshots across cell reuse.
  • iOS simulator/device version, orientation sequence, repeated-run variance, and the exact environment used to derive the new baseline are unspecified.
  • Videos attached to the PR description were not inspected, so their demonstrated behavior is unknown.

🔬 Code Review — Deep Analysis

Code Review — PR #39396

Independent Assessment

What this changes: The submitted production change separates UIKit bounds history from managed arrange history in TemplatedCell2, allows additional inline arrangements during preferred-size calculation, and limits pending final arrangements in LayoutSubviews to native-bounds transitions or safe-area reconciliation. The submitted test change raises the iOS CollectionViewHandler2 arrange baseline from 276 to 313.

Inferred motivation: The state split is intended to preserve required synchronous arrangements for recycled or dynamically rebuilt cells while avoiding a redundant final arrangement when UIKit has not changed the cell bounds.

Reconciliation with PR Narrative

Author claims: The submitted state machine preserves rotation and dynamic-content correctness while reducing the regressed arrange count from approximately 354 to 327–328; the raised baseline is described as the smallest value that accepts the corrected behavior.

Agreement/disagreement: The production mechanism is consistent with the stated intent, and the expert review did not establish a separate production-code defect. The baseline claim is not supported by the authoritative Gate evidence: the focused test passed both without the production fix and with it, so the changed assertion does not distinguish the reported regression from the submitted fix.

Prior Review Reconciliation

No prior error-level findings were found across the available top-level reviews, inline review comments, or PR issue comments.

Blast Radius Assessment

  • Runs for all instances: The per-cell state-machine change runs throughout the iOS and MacCatalyst CollectionViewHandler2 layout lifecycle, not only in the reported rotation scenario.
  • Startup impact: No direct startup-path impact was identified.
  • Static/shared state: No new static state was added; the new state is retained per cell across layout and reuse callbacks.
  • Adjacent scenarios: Rotation, reuse/rebinding, dynamic templates, safe-area changes, MeasureFirstItem, supplementary views, horizontal layouts, and CarouselView share or exercise this layout path.

CI and Gate Status

  • Required-check result: Undetermined from authenticated gh; anonymous commit/check evidence was mixed or pending.
  • Authoritative Gate result: ❌ FAILED.
  • Gate evidence: Issue25671.LayoutPassesShouldNotIncrease passed without the production fix (measure 271, arrange 227) and with the production fix (measure 312, arrange 231).
  • Classification: The submitted regression assertion does not reproduce or discriminate the bug. Gate was not rerun.

Findings

❌ Error — Raised arrange threshold does not prove the regression fix

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25671.cs:51 raises the iOS CollectionViewHandler2 arrange baseline from 276 to 313, but the authoritative Gate observed the focused test passing in both the unfixed and fixed states. This loosens the accepted aggregate arrange count without demonstrating that the test rejects the reported redundant-arrange behavior. The regression coverage must discriminate the broken and corrected states before the threshold increase can support the fix.

Failure-Mode Probing

  • Unfixed implementation under the submitted assertion: It passes, so the asserted ceiling does not catch the regression in the Gate environment.
  • Additional redundant arrangements below the new ceiling: They can pass without identifying which lifecycle transition caused them.
  • Reuse with unchanged native bounds: Native bounds history persists across reset/rebind paths, but the expert review did not establish a concrete incorrect transition from the submitted source.
  • Rotation and dynamic-content paths: The aggregate-count test does not directly prove either behavioral requirement; their correctness remains separate validation evidence.

External Output Contract

Not applicable.

Verdict: NEEDS_CHANGES

Confidence: low

Summary: Gate independently vetoes approval, and the changed test threshold is a concrete blocking defect because it does not discriminate the unfixed and fixed states. The expert review found no separately proven production mechanism defect, so any evidence-first refinement should remain limited to repairing the regression assertion rather than redesigning the production state machine.

Evidence-First Refinement Threshold

Met. The non-discriminating threshold increase is concrete, actionable, and backed by the focused base/head Gate results. A refinement may address only that test defect; no broader production rewrite is justified by the current evidence.

🛠️ Try-Fix — Analysis & Comparison

Alternative generation: not requested

Evidence-first mode intentionally omits routine Try-Fix attempts. This is not a failed attempt, a completed alternative search, or evidence that alternatives have no value. The expert review may still produce one evidence-backed PR refinement.

📝 PR Finalize — Recommended Title & Description

Assessment: ✏️ Recommend updating — remove WIP/inflight title noise, correct the unsupported claim that the raised threshold proves the fix, and retain the existing technical, platform, regression, issue, and media details.

Recommended title

[iOS] CollectionView2: Avoid redundant final arrange passes

Recommended description

### Root cause

The issue occurs because `TemplatedCell2` used the most recent managed arrange size to determine whether UIKit had changed the cell's native bounds. `PreferredLayoutAttributesFittingAttributes` can update that managed arrange state before UIKit applies its final bounds, making native size transitions difficult to detect independently.

PR https://github.com/dotnet/maui/pull/38815 allowed any pending arrange to trigger a final arrangement in `LayoutSubviews`. That preserved the rotation correction, but it could also produce a redundant final arrange when UIKit had not changed the native bounds; the reported arrange-pass count increased to approximately 354.

### Description of Change

Track UIKit's native `Bounds.Size` separately from the last managed arrange size by adding native-bounds history to `TemplatedCell2`.

- `PreferredLayoutAttributesFittingAttributes` performs required inline arrangements for external invalidation or changed constraints, and for arrange-induced invalidation when measurement changes the size.
- `LayoutSubviews` compares consecutive native bounds before satisfying a pending final arrangement, while preserving the separate safe-area reconciliation path.
- This keeps the rotation correction and required synchronous arrangements for recycled cells whose templates dynamically rebuild content, while avoiding a redundant final arrangement when native bounds remain unchanged.

The author-reported corrected runs produced approximately 327–328 arrange passes.

### Test threshold and current evidence

The submitted change raises the iOS `CollectionViewHandler2` arrange baseline in `Issue25671.LayoutPassesShouldNotIncrease` from 276 to 313. With the existing 5% margin, this accepts up to 328 integer arrange passes while continuing to reject the reported approximately 354-pass result.

The current Gate did not establish that this threshold discriminates the regression: the focused test passed without the production fix at measure 271 / arrange 227 and with the production fix at measure 312 / arrange 231. Regression coverage still needs to demonstrate a failing broken state and a passing corrected state before the threshold change can serve as proof of the fix.

### Regression PR

https://github.com/dotnet/maui/pull/38815

### Platforms validated

- [x] iOS
- [ ] MacCatalyst
- [ ] Windows
- [ ] Android

### Issues Fixed

Fixes https://github.com/dotnet/maui/issues/39395

### Output

| Platform | Before | After |
|---|---|---|
| iOS | <video src="https://github.com/user-attachments/assets/7ae5fb9f-ed59-4c3a-8b88-02e52d20d104"> | <video src="https://github.com/user-attachments/assets/ea367492-c6b5-45d3-ace7-3d8848cdcb6c"> |

🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Phase Status

Phase Status Notes
Pre-Flight ✅ COMPLETE Trusted evidence-first context captured for submitted HEAD cd659ceb838b
Expert Review NEEDS_CHANGES (low confidence) 1 blocking test-coverage error; no separately proven production-code defect
Gate ❌ FAILED Issue25671 passed both without and with the production fix
Try-Fix NOT REQUESTED Evidence-first mode intentionally omitted routine alternatives
Refinement ⚠️ BLOCKED VALIDATION One test-only refinement implemented; its sole validation used SDK packs from the raw PR worktree and cannot count
Report ✅ COMPLETE Compared only the submitted PR and the implemented refinement

Code Review and Candidate Comparison

Candidate Change Regression Evidence Expert Finding Assessment
pr Separates native bounds history from managed arrange history and raises the iOS CollectionViewHandler2 arrange baseline from 276 to 313 ❌ Gate failed because the focused test passed in both unfixed and fixed states ❌ Leaves the unsupported, non-discriminating threshold increase in place Not merge-ready
pr-plus-reviewer Keeps the submitted production fix but restores the prior arrange baseline of 276 ⚠️ The one focused run completed successfully, but candidate provenance is invalid because it consumed /Users/cloudtest/vss/_work/1/s/.dotnet/packs; validation is therefore BLOCKED ✅ Removes the unsupported threshold loosening Better than the raw submission, but still not demonstrated merge-ready
Selected Fix: pr-plus-reviewer. It is the stronger candidate because it removes the concrete expert finding instead of weakening regression protection without discriminating evidence. This selection does not convert the blocked run into a pass: the submitted PR still requires the refinement, and neither candidate satisfies the required fail-without-fix regression proof.

Summary

Request changes. The raw PR cannot be approved because Gate failed and the expert review found that its raised arrange threshold does not distinguish the reported regression from the fix. The reviewer refinement removes that unsupported threshold change, but its single permitted validation pass was provenance-blocked and the original regression obligation remains unmet.

Root Cause

The production issue is attributed to conflating managed arrange history with UIKit native bounds transitions: preferred-size work can advance managed state before UIKit applies final bounds, while pending arrange state can cause an unnecessary final arrangement when native bounds did not change. The submitted production change introduces separate native-bounds tracking and changes preferred-size/final-arrange conditions to reconcile rotation and dynamic-content requirements.

The review blocker is evidentiary rather than a separately proven production-state-machine defect. Issue25671.LayoutPassesShouldNotIncrease passed without the production fix at measure 271 / arrange 227 and with it at measure 312 / arrange 231. Raising the arrange baseline from 276 to 313 therefore loosens the assertion without showing that the unfixed state fails.

Fix Quality

The submitted state split is targeted and plausible, but the available evidence does not validate its required behavior or regression boundary. The aggregate pass-count test does not directly prove rotation correctness, dynamically rebuilt content, reuse with unchanged native bounds, or absence of redundant final arrangements. The refinement preserves the submitted production logic and avoids the unsupported test relaxation, but its blocked validation cannot establish candidate fidelity or safety. Approval requires isolated candidate validation and regression coverage that fails for the broken behavior and passes for the corrected behavior.

📱 UI Tests — CollectionView

Detected UI test categories: CollectionView

✅ Deep UI tests — 438 passed, 0 failed, 5 skipped across 1 category on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
CollectionView 438/443 (5 skipped) ✓ —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)
🧭 Next Steps — reviewer changes required

The existing test reproduces the regression in candidate CI with 354 arrange passes, exceeding the old limit of 289.8. The proposed limit of 328.65 still rejects this failure while accepting the corrected 327–328 passes reported in this PR. The gate’s 227/231 results did not reproduce the candidate CI scenario. Therefore, the current fix is necessary to resolve the candidate CI failure.

@BagavathiPerumal BagavathiPerumal changed the title [WIP][Inflight/Candidate][iOS] Fix for unnecessary arrange passes in CollectionView2 [Inflight/Candidate][iOS] Fix for unnecessary arrange passes in CollectionView2 Oct 16, 2026
@sheiksyedm
sheiksyedm marked this pull request as ready for review October 16, 2026 15:24
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 16, 2026
@kubaflo

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

/review gate was not started: another review or Gate is already running for this PR.

This command is not queued. Submit it again after the current run finishes.

@kubaflo
kubaflo merged commit 9aaa126 into dotnet:inflight/candidate Oct 16, 2026
198 of 216 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR12 milestone Oct 16, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI Review Summary

@BagavathiPerumal — new AI review results are available based on commit cd659ce.

Gate Partial Confidence Low Platform iOS


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ❌ FAILED

Platform: IOS · Base: inflight/candidate · Merge base: d099f2e9

🩺 Test does not reproduce the bug — ran the same in both states (PASS without fix, PASS with fix). The repro test is not exercising the issue. Strengthen the test before reviewing the fix.

Test Without Fix (expect FAIL) With Fix (expect PASS)
🖥️ Issue25671 Issue25671 ❌ PASS — 467s ✅ PASS — 103s
🔴 Without fix — 🖥️ Issue25671: PASS ❌ · 467s

(no coded error found; showing last 1200 chars)

please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.05]   Discovering: Controls.TestCases.iOS.Tests
[xUnit.net 00:00:00.16]   Discovered:  Controls.TestCases.iOS.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 10/16/2026 10:12:00 AM FixtureSetup for Issue25671(iOS)
>>>>> 10/16/2026 10:12:04 AM LayoutPassesShouldNotIncrease Start
>>>>> 10/16/2026 10:12:22 AM LayoutPassesShouldNotIncrease Stop
Measure passes: 271, Arrange passes: 227
  Passed LayoutPassesShouldNotIncrease [18 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 1.3976 Minutes
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
🟢 With fix — 🖥️ Issue25671: PASS ✅ · 103s

(no coded error found; showing last 1200 chars)

lease wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.04]   Discovering: Controls.TestCases.iOS.Tests
[xUnit.net 00:00:00.14]   Discovered:  Controls.TestCases.iOS.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 10/16/2026 10:17:18 AM FixtureSetup for Issue25671(iOS)
>>>>> 10/16/2026 10:17:21 AM LayoutPassesShouldNotIncrease Start
>>>>> 10/16/2026 10:17:38 AM LayoutPassesShouldNotIncrease Stop
Measure passes: 317, Arrange passes: 233
  Passed LayoutPassesShouldNotIncrease [17 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 33.4632 Seconds
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx

⚠️ Failure Details

  • ❌ Issue25671 PASSED without fix (should fail) — tests don't catch the bug
📁 Fix files reverted (1 files)
  • src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

📋 Pre-Flight — Context & Validation

Pre-Flight Context

Scope and PR state

  • #39396 contains one commit (cd659ceb838b8381d54445b290a5da47e549efe5) targeting inflight/candidate at base 40a966c82c8aed0cf3cd41f5814b4475a3fcf59b.
  • GitHub reports it merged on October 16, 2026, into the .NET 10 SR12 candidate line.
  • The immutable submitted diff changes two files: one iOS CollectionView2 implementation file and one shared UI-test file.
  • This is context gathering only, not an exhaustive or expert review.

Reported problem and lineage

  • #39395 reports that the iOS LayoutPassesShouldNotIncrease UI test failed in SR12 candidate PR #38782 after the rotation-layout fix from #38771 entered the candidate branch through backport #38815.
  • The issue contains no standalone reproduction steps, reproduction project, affected iOS version, logs, or workaround. A maintainer comment reports reproduction on iOS from the candidate branch.
  • The PR description attributes the increased arrange count to TemplatedCell2 comparing UIKit bounds against the most recent managed arrange size. Preferred-size calculations could update that managed value before UIKit supplied final bounds, obscuring whether native bounds actually changed.
  • Reported counts are approximately 354 arrange passes for the candidate regression and 327–328 after this change. These numbers are reported evidence, not independently verified here.
  • #38815 had addressed a rotation/RTL geometry problem by deferring constraint-change arrangement until LayoutSubviews; #39396 adjusts that lifecycle again while attempting to retain both rotation correction and synchronous layout for dynamically rebuilt content.

Changed files and mechanism

src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

  • Adds _hasNativeBoundsSize and _lastNativeBoundsSize, separating consecutive UIKit Bounds.Size observations from _lastArrangedSize, which remains the last size passed to the managed virtual view’s Arrange.
  • In PreferredLayoutAttributesFittingAttributes:
    • External measure invalidations now request an inline arrange even when outer size is unchanged.
    • Constraint changes also request an inline arrange.
    • Arrange-induced invalidations with unchanged constraints arrange inline only when the newly calculated size differs from _lastArrangedSize.
    • The resulting predicate arranges when an arrange is pending and any of these hold: inline arrangement is requested, no managed arrangement has occurred, or preferred size differs from the last managed arrangement.
  • In LayoutSubviews:
    • Native bounds changes are detected by comparing current Bounds.Size with the previous native bounds rather than with _lastArrangedSize.
    • A pending arrange alone no longer unconditionally triggers another final arrange.
    • Outside safe-area changes, final arrangement occurs only after native bounds change and when either an arrange remains pending or measured constraints match the applied bounds.
  • Existing surrounding lifecycle remains relevant:
    • ArrangeVirtualView marks when arrangement is in progress and updates _lastArrangedSize.
    • Measure invalidation records whether all coalesced invalidations occurred during arrangement.
    • Binding and reuse call ResetArrangeState; that method resets managed-arrange state but does not reset the newly added native-bounds fields. Whether retaining native bounds across reuse/rebinding is intentional requires validation.
    • Safe-area reconciliation can independently trigger arrangement.

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25671.cs

  • Changes only the iOS CollectionViewHandler2 arrange baseline from 276 to 313; the measure baseline remains 373.
  • Because the assertion permits a 5% margin, the effective arrange limit changes from 289.8 to 328.65.
  • The scenario scrolls, regenerates items, scrolls again, then parses displayed measure/arrange counters. No new targeted scenario was added for rotation, native-bound transitions, recycling, or dynamic-content geometry.
  • Legacy iOS-handler limits and Android limits are unchanged. The test itself is conditionally compiled only for Android or iOS and uses the new threshold only when the heading identifies CollectionViewHandler2.

Platform-sensitive paths

  • Required validation platform is iOS.
  • The implementation is in the UIKit-based CollectionView2 cell lifecycle and affects PreferredLayoutAttributesFittingAttributes, LayoutSubviews, measure invalidation, managed arrangement, native bounds, and safe-area handling.
  • Sensitive scenarios include device rotation and RTL layout, vertical versus horizontal collection constraints, dynamically rebuilt templates, recycled or rebound cells, unchanged-size invalidations, MeasureFirstItem caching, supplementary headers/footers, and explicit safe-area edges.
  • This is the Items2/CollectionViewHandler2 path, not the legacy CollectionView handler.
  • Mac Catalyst applicability should be confirmed because this is shared UIKit-oriented handler code; the PR reports iOS validation only and explicitly leaves Mac unchecked. Android and Windows do not use the changed production file.

Validation requirements and gate evidence

  • The supplied Gate result is failed because the tests did not behave as expected; it must not be rerun.
  • Available GitHub discussion records that the existing test reportedly passed both without and with the production change in the gate environment, with observed counts of 227 and 231. The author separately reported 354 passes in candidate CI and 327–328 after the fix. The ordering of the gate’s two counts and the reason for the large environment-dependent difference are not established here.
  • Later validation therefore needs to establish, on iOS and under the actual candidate configuration:
    • that the unpatched candidate reproduces the excessive-arrange condition;
    • that the patched version reduces it while the updated threshold still rejects the reported 354-pass behavior;
    • that the selected handler and exact UI-test scenario are the same in both runs;
    • that rotation uses final UIKit bounds and preserves RTL geometry;
    • that dynamic content, rebinding, and recycling receive valid geometry without blank content;
    • that unchanged native bounds do not cause redundant final arrangements;
    • that genuine native-bound and safe-area changes still receive the required final arrangement.

Remaining uncertainties

  • The reason the gate did not discriminate between patched and unpatched behavior is unknown.
  • The linked Azure Pipelines build details, attached videos, and raw test artifacts were not established from the available GitHub context.
  • It is unknown whether the candidate-only 354-pass result depends on device model, iOS version, orientation, timing, handler selection, or broader candidate contents.
  • Direct regression coverage for the native-bounds mechanism is not present in the submitted diff; coverage from other existing tests is unknown.
  • Mac Catalyst behavior and the intended lifetime of native-bounds tracking across cell reuse remain unverified.
  • The issue remains open in GitHub despite #39396 being reported as merged.

🔬 Code Review — Deep Analysis

Expert Evaluation — PR #39396

Independent Assessment

What this changes: The submitted fix separates the last UIKit Bounds.Size observed by TemplatedCell2 from the last size used for managed arrangement. Preferred sizing can still arrange invalidated content inline, while LayoutSubviews performs a final managed arrangement only for a safe-area change or a genuine native-bounds transition that still requires it. The UI test raises only the iOS CollectionViewHandler2 arrange-pass threshold from 276 to 313.

Inferred motivation: Preferred-size calculation can advance managed arrange state before UIKit applies final cell bounds. Comparing UIKit bounds with that managed size conflates two lifecycles and can either hide a native transition or cause an unnecessary final arrangement.

Platform and Lifecycle Trace

  • The production change is confined to the current Items2 handler used by iOS and Mac Catalyst.
  • External measure invalidation or a constraint change requests an inline arrangement; an arrange-induced, same-size invalidation does not.
  • _needsArrange remains pending after preferred sizing until LayoutSubviews reconciles native bounds or establishes convergence.
  • Rotation/resize can receive both the preferred-size arrangement and a final arrangement using UIKit bounds when native bounds change.
  • Safe-area reconciliation remains an independent reason to arrange.
  • Rebinding and reuse reset managed arrangement state. Retaining the last native bounds does not by itself skip the required first managed arrangement because _hasArrangedSize is reset and bind invalidates measure.

Findings

The single MAUI expert review produced no validated file-line findings. inline-findings.json is the validated empty JSON array ([]). No concrete actionable source defect or unresolved behavioral mechanism met the evidence threshold for a pr-plus-reviewer refinement.

Validation Evidence

  • Gate: ❌ FAILED — the supplied Gate did not discriminate the production change. The existing test reportedly passed both without and with the fix in that environment, with counts far below the candidate-branch observations.
  • Regression coverage: The submitted diff adjusts an aggregate performance threshold but adds no focused coverage for native-bounds transitions, rotation/RTL geometry, cell reuse, or dynamic-content geometry.
  • Consequence: The code mechanism is plausible, but the available evidence does not demonstrate that this submitted change fixes the candidate-only regression while preserving the adjacent layout behaviors. The Gate failure independently blocks approval.

Failure-Mode Probing

  • Same-size external invalidation: Preferred sizing arranges inline because the invalidation did not originate from arrangement.
  • Same-size arrange-induced invalidation: The size comparison suppresses another inline arrange, and unchanged native bounds allow LayoutSubviews to clear the pending work without a redundant cell-level arrange.
  • Rotation or resize: Changed constraints request inline arrangement, and a subsequent native-bounds change permits final arrangement with UIKit's applied bounds.
  • Reuse or rebinding: Reset managed state forces an initial arrangement; a changed native size is still detected against the retained prior bounds.
  • Safe-area transition: A changed cell safe-area override remains sufficient to trigger arrangement independently of native-bounds tracking.

External Output Contract

Not applicable.

Verdict: NEEDS_DISCUSSION

Confidence: low

Summary: No concrete code defect survived the expert review, so there is no evidence-backed refinement to implement. However, the failed and non-discriminating Gate leaves the central regression claim unverified; approval is not supported until iOS candidate validation distinguishes patched from unpatched behavior and covers the required layout lifecycle.


🛠️ Try-Fix — Analysis & Comparison

Alternative generation: not requested

Evidence-first mode intentionally omits routine Try-Fix attempts. This is not a failed
attempt, a completed alternative search, or evidence that alternatives have no value.
The expert review may still produce one evidence-backed PR refinement.


🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Phase Status

Phase Status Notes
Pre-Flight ✅ COMPLETE Trusted evidence-first context consumed
Code Review NEEDS_DISCUSSION (low) 0 validated inline errors, 0 warnings; validation remains inconclusive
Gate ❌ FAILED iOS tests did not behave as expected and did not discriminate the fix
Try-Fix NOT REQUESTED Evidence-first mode intentionally omitted alternative generation
Refinement NOT CREATED No concrete expert finding met the evidence threshold
Report ✅ COMPLETE

Code Review and Candidate Comparison

pr is the only real candidate. The single expert pass found no validated file-line defect, and no evidence-backed pr-plus-reviewer patch was implemented. Routine Try-Fix was not requested; this is not a failed or exhausted alternative search.

The submitted change plausibly separates native UIKit bounds tracking from managed arrange state and suppresses redundant final arrangements without removing inline arrangements for invalidated content. Nevertheless, the trusted Gate failed: the available test passed both without and with the production change in the Gate environment, so it did not prove that the fix addresses the candidate-only regression. With no validated alternative candidate, pr is selected solely as the submitted implementation, not as a demonstrated merge-ready fix.

Summary

Request changes because the failed, non-discriminating Gate independently vetoes approval. The submitted mechanism has no blocking expert file-line finding, but the evidence does not establish that it reduces the reported candidate arrange count while preserving rotation, RTL, dynamic-content, reuse, and safe-area behavior.

Root Cause

TemplatedCell2 used the most recent managed arrange size to infer whether UIKit had changed native cell bounds. Preferred sizing can update managed arrange state before UIKit applies final bounds, conflating managed and native layout state and allowing unnecessary final arrangements.

Fix Quality

The production change introduces dedicated native-bounds state and narrows final arrangement to safe-area or genuine native-bounds transitions. It is localized and consistent with the intended lifecycle, but the only submitted test change raises an aggregate arrange threshold and did not reproduce or distinguish the reported regression under Gate. Candidate-configuration iOS evidence is still required before the raw PR can support approval.


📱 UI Tests — CollectionView

Detected UI test categories: CollectionView

✅ Deep UI tests — 438 passed, 0 failed, 5 skipped across 1 category on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
CollectionView 438/443 (5 skipped) ✓ —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)

🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Oct 16, 2026
kubaflo pushed a commit that referenced this pull request Oct 18, 2026
…ctionView2 (#39396)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!


<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Root cause

The issue occurs because TemplatedCell2 used the most recent managed
arrange size to determine whether UIKit had changed the cell’s native
bounds. Preferred-size calculations can update this value before UIKit
applies its final bounds, making native size changes difficult to
detect. PR #38815 allowed any pending arrange to trigger a final
arrangement, resulting in redundant arrange passes when the native
bounds had not changed and increasing the count to approximately 354.

### Solution description

The fix involves tracking UIKit’s native bounds size separately from the
last managed arrange size. LayoutSubviewscompares consecutive native
bounds and performs a pending final arrangement only when the native
bounds have changed. This preserves the rotation correction and required
inline arrangements for dynamically rebuilt content while avoiding
redundant final arrangements when the native bounds remain unchanged.
The corrected implementation reduced the arrange-pass count to
approximately 327–328.
 
**Reason for test level changes:**
 
The CollectionView2 arrange count increased because recycled or rebound
cells now require an inline managed arrangement after measurement
invalidation. This work is necessary to ensure dynamically rebuilt child
content receives valid geometry and does not render blank. In addition,
a genuine native bounds change, such as device rotation, requires a
final arrangement using the bounds supplied by UIKit.
 
These required arrangements raise the valid count above the previous
baseline, which was established before the current dynamic-content and
rotation layout lifecycle. The baseline is therefore increased from 276
to 313 based on repeated corrected runs producing 327–328 arrangements
after the existing 5% margin is applied. This is the smallest baseline
that accepts valid behavior while continuing to reject the redundant
354-pass behavior.

### Regression PR

PR #38815

Validated the behavior in the following platforms
 
- [x] iOS
- [ ] Mac
- [ ] Window
- [ ] Android
 
### Issues Fixed
  
Fixes #39395

### Output

|Platform|Before|After|
|--|--|--|
|iOS| <video
src="https://github.com/user-attachments/assets/7ae5fb9f-ed59-4c3a-8b88-02e52d20d104">|
<video
src="https://github.com/user-attachments/assets/ea367492-c6b5-45d3-ace7-3d8848cdcb6c">|
kubaflo pushed a commit that referenced this pull request Oct 27, 2026
…e after iOS device rotation #38771 (#39707)

The backport PR #38815 caused LayoutPassesShouldNotIncrease to fail (iOS
18.5) in the previous candidate #38782. This PR #39396 fixed that
failure, and the candidate was subsequently merged into main.

However, the current inflight candidate, #39597, appears to have
overwritten that fix with the earlier backport similar changes, possibly
during conflict resolution, causing LayoutPassesShouldNotIncrease to
fail again.

I have now reverted the conflicting changes
4c29bf0
in the candidate to preserve the fix already present in main.
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
…e after iOS device rotation #38771 (#39707)

The backport PR #38815 caused LayoutPassesShouldNotIncrease to fail (iOS
18.5) in the previous candidate #38782. This PR #39396 fixed that
failure, and the candidate was subsequently merged into main.

However, the current inflight candidate, #39597, appears to have
overwritten that fix with the earlier backport similar changes, possibly
during conflict resolution, causing LayoutPassesShouldNotIncrease to
fail again.

I have now reverted the conflicting changes
4c29bf0
in the candidate to preserve the fix already present in main.
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 16, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — cd659ceb Deployed Oct 15, 2026 by BagavathiPerumal via conclusion #2358
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-failed AI could not verify tests catch the bug s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[inflight regression] LayoutPassesShouldNotIncrease UI test failing in candidate PR 38782

4 participants