Repository navigation
[iOS]Fix CollectionView items not rendered properly when SelectedItem assigned in ApplyQueryAttributes - #38614
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38614Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38614" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
Performance Review Summary
Performance ResultsI prepared isolated merge-base (
The workload was designed to exercise the changed scheduling path, not reproduce Shell navigation end to end. I did not run the Both Release MSBuild-task builds completed. The experimental harness passed 34 contract assertions, plus the existing parser/comparator suites. Those checks validate measurement tooling, not the PR's native functionality. Zero native launches and zero timing samples were collected. The simulator was never booted, the base app build was interrupted, and the head app build was not started. There is no speedup/regression or native-correctness verdict from this attempt. Findings & Follow-upWhat I tried locally: SDK 10.0.100, iOS workload 26.1.10494, Xcode 26.6, Release ARM64 simulator builds, and two-worker MSBuild limits. Both revisions request SDK The repository What happened: after 143.21 seconds of the base iOS app build, the supervisor observed WindowServer in U state across three consecutive three-second samples; Peak owned RSS during that build was 1,304.66 MiB, peak sampled owned CPU 229.7% (100% = one core), peak wired memory 5.98 GiB, and swap stayed zero. The final host check showed 95% free memory, no blocked processes, no thermal/performance warnings, and no remaining owned build processes. The dedicated simulator remained shut down. This happened on the merge-base build, before the PR's native app was built or run. I cannot attribute the host stall to this PR, especially with the toolchain overrides. @devanathan-vaithiyanathan, can you help explain whether a known SDK/iOS-workload/Xcode compatibility issue could account for this, and which supported combination you used to validate the fix? Requested changes before merge: please update the PR with the supported toolchain versions and a reproducible local test command plus results for the initial-selection fix. Please include the existing |
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis
🧪 CI Analysis — click to expand📊 maui-prNo failures found. 🧪 maui-pr-devicetestsNo failures found. 🧪 maui-pr-uitests
🧭 Follow-up — actions and refreshNext action: Rerun
|
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@devanathan-vaithiyanathan — new AI review results are available based on commit
df2ffda.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ❌ FAILED
Platform: IOS · Base: main · Merge base: 3d7ff41c
🩺 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) |
|---|---|---|
🖥️ Issue38443 Issue38443 |
❌ PASS — 427s | ✅ PASS — 87s |
🔴 Without fix — 🖥️ Issue38443: PASS ❌ · 427s
(no coded error found; showing last 1200 chars)
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.18] 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
>>>>> 9/23/2026 1:47:57 AM FixtureSetup for Issue38443(iOS)
>>>>> 9/23/2026 1:48:01 AM SelectedItemSetDuringShellNavigationUpdatesVisualState Start
>>>>> 9/23/2026 1:48:04 AM SelectedItemSetDuringShellNavigationUpdatesVisualState Stop
Passed SelectedItemSetDuringShellNavigationUpdatesVisualState [2 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue38443.trx
Test Run Successful.
Total tests: 1
Passed: 1
Total time: 1.1525 Minutes
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue38443.trx
🟢 With fix — 🖥️ Issue38443: PASS ✅ · 87s
(no coded error found; showing last 1200 chars)
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
>>>>> 9/23/2026 1:52:27 AM FixtureSetup for Issue38443(iOS)
>>>>> 9/23/2026 1:52:31 AM SelectedItemSetDuringShellNavigationUpdatesVisualState Start
>>>>> 9/23/2026 1:52:33 AM SelectedItemSetDuringShellNavigationUpdatesVisualState Stop
Passed SelectedItemSetDuringShellNavigationUpdatesVisualState [1 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue38443.trx
Test Run Successful.
Total tests: 1
Passed: 1
Total time: 18.5245 Seconds
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue38443.trx
⚠️ Failure Details
- ❌ Issue38443 PASSED without fix (should fail) — tests don't catch the bug
📁 Fix files reverted (1 files)
src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
📋 Pre-Flight — Context & Validation
PR #38614 Pre-Flight
Context
- PR:
[iOS]Fix CollectionView items not rendered properly when SelectedItem assigned in ApplyQueryAttributes - Issue: #38443, a regression from 10.0.90 to 10.0.100 reported on iPhone 7 / iOS 15.8.7.
- Symptom: assigning
CollectionView.SelectedItemfromIQueryAttributable.ApplyQueryAttributesduring Shell navigation can leave iOS CollectionView items or their selected visual state rendered incorrectly. Assigning later fromOnNavigatedToworks. - Platform for STEP 5a: iOS.
- Base / materialized head:
origin/mainat3d7ff41c8e; review commit66ebfa5246.
Existing PR approach
The functional change is limited to:
src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
When SelectItem observes an unloaded native UICollectionView, the PR replaces the existing empty PerformBatchUpdates callback with a _updateSelectionWhenAttached flag. AttachingToWindow clears that flag and calls UpdatePlatformSelection, re-reading current selection state instead of retaining the earlier item/source pair.
The PR also adds the Issue38443 HostApp page, one screenshot UI test, and platform snapshots. The PR body is stale: it describes DispatchQueue.MainQueue.DispatchAsync, but the materialized diff uses AttachingToWindow.
Direct diff assessment
- The active handler for iOS/MacCatalyst is correctly under
Handlers/Items2/iOS. - The PR assumes window attachment is the missing readiness boundary.
- A boolean coalesces all pre-attachment selection changes;
UpdatePlatformSelectionthen applies the latest virtual-view selection. - The existing loaded path still calls
ValidateAndSelectItemsynchronously. - Any alternative must use a different root-cause mechanism, not merely move the same attachment flag or callback.
- Only the functional source file is safely revertable by
EstablishBrokenBaseline.ps1; PR-added test/snapshot files are not candidate edit targets.
Test contract
Detected primary test:
pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform ios -TestFilter "Issue38443"No additional mandatory regression-test names were supplied in the STEP 5a request or detected by the gate. Do not invent or run a broad suite. Run only the primary filter above.
The completed gate must not be rerun. Its definitive result was:
- Without functional fix:
Issue38443passed on three runs. - With PR fix:
Issue38443passed. - Therefore the test does not reproduce the reported regression. A candidate may be marked
Passonly when the requested command passes, but its analysis must state that this proves only test compatibility, not that the candidate fixes #38443.
Constraints for candidates
- Use
try-fixexactly once per candidate and its script-only baseline/restore flow. - One implementation/test pass and at most one focused correction/retest.
- Do not edit PR-added files, rerun gate verification, run a full suite, or spawn expert/reviewer agents.
- Perform only the inline expert self-review required by
try-fix.
🔬 Code Review — Deep Analysis
Code Review — PR #38614
Independent Assessment
What this changes: The active Items2 iOS/MacCatalyst selection controller replaces an empty PerformBatchUpdates completion with a one-way _updateSelectionWhenAttached latch. A pre-attachment selection sets the latch; MovedToWindow reaches the new AttachingToWindow override, clears the latch, and re-reads the current virtual selection through UpdatePlatformSelection(). The PR also adds a Shell-navigation HostApp scenario and screenshot UI test.
Inferred motivation: SelectedItem may be assigned from IQueryAttributable.ApplyQueryAttributes before the native UICollectionView joins a window, so selecting immediately can miss UIKit item generation and the selected visual state.
Approach assessment: Coalescing pre-attachment updates and re-reading current state avoids retaining a stale item/source pair. The latch has a single set path and a single clear path; changes to SelectedItem, SelectedItems, SelectionMode, or ItemsSource before attachment are read again when the latch fires. The implementation is localized to the correct Items2 platform layer. However, AttachingToWindow() executes synchronously from MovedToWindow; the diff does not establish that window attachment is late enough for cell generation/layout to have completed.
Reconciliation with PR Narrative
The motivation and platform scope match the code, but the current PR description is stale: it says the implementation uses DispatchQueue.MainQueue.DispatchAsync, while submitted HEAD uses an attachment latch and a synchronous AttachingToWindow() replay.
Prior Review Reconciliation
| Prior ❌ Error Finding | Source | Status | Evidence |
|---|---|---|---|
| The regression test is non-discriminating and does not fail without the fix. | MauiBot inline review on Issue38443.cs:23 |
❌ Unresolved | The trusted Gate reports three broken-baseline passes and one PR-fix pass for the same Issue38443 command. |
Synchronous replay from AttachingToWindow() may still run during UIKit attachment/item generation. |
Copilot inline review on SelectableItemsViewController2.cs:82 |
❌ Unresolved | The author dismissed the concern based on the related test, but that test also passes without the fix and therefore cannot validate the timing boundary. |
The single newly authorized maui-expert-reviewer pass produced no additional validated inline findings; inline-findings.json is a valid empty JSON array.
Blast Radius Assessment
- Runs for all instances: No; only valid programmatic selections requested while the Items2 native collection is not attached set the latch.
- Startup impact: No app-startup impact, but the path runs during CollectionView page initialization/navigation.
- Static/shared state: None.
- Reconnect behavior: The latch is cleared on the first attachment and subsequent selection mappings run normally. No subscription is added.
- Adjacent scenarios: Single and multiple selection share
SelectItem; empty, grouped, source-replacement, detach/reattach, and rapid pre-attachment selection changes are not behaviorally covered.
CI Status
- Required-check result: Undetermined.
gh pr checks --requiredwas unavailable because the CLI is unauthenticated. - Trusted Gate result: ❌ Failed — the test did not behave as required. It passed both without and with the production fix.
- Classification: The submitted regression test does not prove #38443 or distinguish the scheduling change.
- Action taken: Do not rerun the Gate; cap confidence at low.
Findings
❌ Error — Regression test does not detect the regression
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38443.cs:23 only compares against a screenshot baseline. The trusted Gate demonstrates that the same test passes on the broken baseline, so it cannot establish that the fix changes native selection or selected visual state. A deterministic assertion must observe the selected visual-state transition and fail when the production fix is removed.
⚠️ Warning — Attachment is not proven to be the UIKit readiness boundary
src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs:82 synchronously replays selection inside MovedToWindow. Window attachment proves IsLoaded(), but it does not itself prove that the collection has finished its attach/layout/item-generation cycle. Because the only test is non-discriminating, this timing assumption remains unresolved rather than empirically validated.
Failure-Mode Probing
- Selection changes repeatedly before attachment: the boolean coalesces requests and
UpdatePlatformSelection()reads the latest state, avoiding stale captured values. - Selection becomes null or mode becomes
Nonebefore attachment: the replay reads current state and clears/does nothing as appropriate. - ItemsSource is replaced before attachment: mapper propagation re-evaluates selection; the replay uses current state rather than the old source.
- Handler disconnects before attachment: no callback subscription or captured closure is retained, but no regression test covers reconnect behavior.
MovedToWindowfires before the selected cell is materialized: the code attempts selection synchronously; the submitted test does not distinguish whether this is sufficient.
External Output Contract
Not applicable.
Verdict: NEEDS_CHANGES
Confidence: low
Summary: The latch is a focused, stale-state-safe improvement over retaining a delayed item/source pair, and the expert pass found no new inline defect. The PR is not ready because its regression test demonstrably passes without the fix, leaving the synchronous attachment timing assumption unverified.
🛠️ Try-Fix — Analysis & Comparison
Try-Fix Aggregate (PR #38614)
Candidate 1
Try-Fix Candidate 1 (PR #38614, Issue #38443)
Approach Description
Candidate 1 changes iOS unloaded-selection timing in SelectableItemsViewController2.SelectItem by replacing the unloaded path CollectionView.PerformBatchUpdates(...ValidateAndSelectItem...) callback with DispatchQueue.MainQueue.DispatchAsync(() => ValidateAndSelectItem(...)), and adds using CoreFoundation; for DispatchQueue.
Prior Approach Avoided
Avoided the PR’s _updateSelectionWhenAttached + AttachingToWindow replay flag mechanism.
Mechanism-Level Difference
The PR persists pending selection state across lifecycle boundaries and replays it during window attachment. Candidate 1 does not persist pending state and does not use attach-time replay; it defers selection validation to the next iOS main-runloop turn so item generation/layout can settle in the same navigation cycle, then revalidates source/index/item identity before selecting.
Files Changed
src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
Exact Captured Diff
diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
index 3f594d7c0b..a65ba9c554 100644
--- a/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
+++ b/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using CoreFoundation;
using Foundation;
using Microsoft.Maui.Controls.Handlers.Items;
using Microsoft.Maui.Controls.Platform;
@@ -58,10 +59,7 @@ namespace Microsoft.Maui.Controls.Handlers.Items2
// Ensure the selected index is updated after the collection view's items generation is completed
if (!CollectionView.IsLoaded())
{
- CollectionView.PerformBatchUpdates(null, _ =>
- {
- ValidateAndSelectItem(selectedItem, originalSource);
- });
+ DispatchQueue.MainQueue.DispatchAsync(() => ValidateAndSelectItem(selectedItem, originalSource));
}
else
{Test Command
pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform ios -TestFilter "Issue38443"
Test Results
Execution 1: Fail (compile)
CS0103: The name 'DispatchQueue' does not exist in the current context- Focused correction applied: added
using CoreFoundation;
Execution 2: Pass
SelectedItemSetDuringShellNavigationUpdatesVisualStatepassedTest Run Successful. Total tests: 1. Passed: 1
Self-Review Count
0 findings (reviewer-findings.json is [])
Result
Pass (test-command compatibility)
Limitation / Failure Analysis Context
Gate already proved Issue38443 passes both without and with fix. Therefore this candidate pass proves only compatibility with the supplied command, not bug-fix efficacy proof for #38443.
Restore Verification
Ran required restore command:
pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore- Output reported
Restored True
Candidate 2
Try-Fix Candidate 2 (PR #38614, Issue #38443)
Approach Description
Candidate 2 removes the unloaded UICollectionView.PerformBatchUpdates callback and immediately calls ValidateAndSelectItem once the selected item resolves to a valid managed index. Its root-cause hypothesis was that the empty batch transaction itself disrupts UIKit's initial data/layout transaction on an unattached collection view, while UIKit can record the valid native selection synchronously before cells display. After the first execution failed, the one permitted focused correction kept selection synchronous but passed CollectionView.IsLoaded() as the animation flag, disabling animation only before load while preserving animated selection for loaded collections.
Prior Mechanisms Avoided
- Existing PR: persist
_updateSelectionWhenAttachedwhile unloaded, then clear it and callUpdatePlatformSelectionfromAttachingToWindow. Candidate 2 adds no attachment callback, pending flag, or state replay. - Candidate 1: replace the unloaded batch callback with
DispatchQueue.MainQueue.DispatchAsync, using one main-runloop deferral. Candidate 2 uses no dispatch, task, timer, or runloop delay.
Mechanism-Level Difference
Both prior mechanisms assume selection must be retried after a later readiness boundary: either native window attachment or the next main-runloop turn. Candidate 2 instead applies validated native selection at the original call site and removes the pre-attachment empty update transaction. Its focused correction changes only whether that immediate UIKit selection is animated; it still does not postpone selection. Thus its cause-to-effect chain is synchronous selection without a pre-display batch/animation transaction, rather than deferred selection after lifecycle readiness.
Files Changed
src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs(+2/-13)- No tests, snapshots, public APIs, or other production files were edited.
Exact Captured Diff
diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
index 3f594d7c0b..74d2d63595 100644
--- a/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
+++ b/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs
@@ -55,18 +55,7 @@ namespace Microsoft.Maui.Controls.Handlers.Items2
if (index.Section > -1 && index.Item > -1)
{
- // Ensure the selected index is updated after the collection view's items generation is completed
- if (!CollectionView.IsLoaded())
- {
- CollectionView.PerformBatchUpdates(null, _ =>
- {
- ValidateAndSelectItem(selectedItem, originalSource);
- });
- }
- else
- {
- ValidateAndSelectItem(selectedItem, originalSource);
- }
+ ValidateAndSelectItem(selectedItem, originalSource);
}
}
@@ -98,7 +87,7 @@ namespace Microsoft.Maui.Controls.Handlers.Items2
return;
}
- CollectionView.SelectItem(updatedIndex, true, UICollectionViewScrollPosition.None);
+ CollectionView.SelectItem(updatedIndex, CollectionView.IsLoaded(), UICollectionViewScrollPosition.None);
}
// Called by Forms to clear the native selectionExact Test Results
Only the supplied command was used:
pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform ios -TestFilter "Issue38443"Execution 1 — immediate selection with existing animation
- Command exit code:
1 - Build completed and the single test executed.
- Exact failure:
Failed SelectedItemSetDuringShellNavigationUpdatesVisualState [3 s] Snapshot different than baseline: SelectedItemSetDuringShellNavigationUpdatesVisualState.png (7.56% difference) Test Run Failed. Total tests: 1 Failed: 1 Total time: 20.7082 Seconds ❌ Tests failed with exit code 1
Execution 2 — focused correction, no animation while unloaded
- Command exit code:
1 - Build completed and the single test executed.
- Exact failure:
Failed SelectedItemSetDuringShellNavigationUpdatesVisualState [3 s] Snapshot different than baseline: SelectedItemSetDuringShellNavigationUpdatesVisualState.png (7.56% difference) Total tests: 1 Test Run Failed. Failed: 1 Total time: 20.0177 Seconds ❌ Tests failed with exit code 1
The two executions are the contract maximum: one implementation/test pass plus one focused correction/retest. No gate verification or broader tests were run.
Inline Expert Self-Review
findings_count: 1
One critical Logic and Correctness finding was recorded against final changed line 58: the exact Issue38443 scenario demonstrates that synchronous pre-generation selection does not preserve expected rendering; both executions produced the same 7.56% snapshot mismatch. No reviewer or child agent was launched.
Result
Fail
Failure Analysis
The first failure shows that simply removing the empty batch transaction and selecting synchronously is not compatible with the expected visual result. The focused correction falsifies the narrower theory that a pre-load selection animation caused the mismatch: disabling that animation produced an identical 7.56% difference. The evidence therefore indicates that selection at the original pre-generation point is too early for correct visual state, or that later item-generation reconciliation is required. No additional mechanism was attempted because the contract permits only one focused correction.
The existing gate remains non-discriminatory for efficacy: Issue38443 passed three times without any fix and passed with the PR fix. Therefore a passing candidate would establish compatibility only, not prove that it fixes #38443. Candidate 2 instead yielded concrete incompatibility evidence because it failed the supplied command twice.
Attempt Artifacts
CustomAgentLogsTmp/PRState/38614/PRAgent/try-fix/attempt-2/approach.mdCustomAgentLogsTmp/PRState/38614/PRAgent/try-fix/attempt-2/fix.diffCustomAgentLogsTmp/PRState/38614/PRAgent/try-fix/attempt-2/test-output.logCustomAgentLogsTmp/PRState/38614/PRAgent/try-fix/attempt-2/reviewer-findings.jsonCustomAgentLogsTmp/PRState/38614/PRAgent/try-fix/attempt-2/analysis.md
Bounded Summary
Exactly two total candidates were attempted. Candidate 1 used one main-runloop deferral and passed the supplied command after one namespace correction; Candidate 2 used synchronous selection without an empty batch transaction and failed both executions with the same 7.56% snapshot mismatch, including after its one animation-focused correction. Because the gate test also passed without any fix, neither candidate is ranked as a proven fix for #38443; the evidence establishes compatibility for Candidate 1 and incompatibility for Candidate 2 only.
📝 PR Finalize — Recommended Title & Description
Assessment: ✏️ Recommend updating — the title formatting is malformed and the description still documents DispatchQueue.MainQueue.DispatchAsync, while submitted HEAD uses a pending-selection latch replayed synchronously from AttachingToWindow.
Recommended title
[iOS] CollectionView: Fix SelectedItem visual state during Shell navigation
Recommended description
### Issue Details
On iOS, when navigating to a page containing a `CollectionView`, setting `SelectedItem` immediately in `IQueryAttributable.ApplyQueryAttributes` does not update the native selection or selected visual state.
The native selection can be requested before the `UICollectionView` is attached to a window. Applying selection at that point can leave the native selection and item visual state out of sync as the collection is generated.
### Description of Changes
Updated `SelectableItemsViewController2.SelectItem` to mark native selection as pending when the `CollectionView` is not yet loaded.
Added an `AttachingToWindow` override that clears the pending flag and calls `UpdatePlatformSelection` after the native collection attaches to a window. Re-reading the current selection state at attachment time coalesces any pre-attachment changes instead of retaining an earlier item or items-source reference.
Added the `Issue38443` HostApp Shell-navigation scenario and screenshot UI test for setting `SelectedItem` from `ApplyQueryAttributes`, together with the platform snapshot baselines.
Fixes #38443
**Tested the behavior in the following platforms.**
- [ ] Android
- [ ] Windows
- [x] iOS
- [ ] Mac
| Before | After |
|--------|-------|
| **iOS**<br> <video src="https://github.com/user-attachments/assets/47dfe037-7cb7-43b0-8313-085eb459251e" width="300" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/eff1a4d7-6670-41e9-a23c-d17646953c26" width="300" height="600"> |
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer
pr-plus-reviewer is the strongest candidate because it combines the submitted attachment gate with the reviewer's missing post-attachment main-queue deferral, safely re-arms the pending selection if detachment wins the race, and replaces screenshot-only verification with a direct observation that the expected cyan cell entered Selected and applied its black stroke. Its one required iOS validation run passed. This is still compatibility evidence rather than a proven reproduction: the trusted Gate showed that the submitted screenshot test also passed without any production fix.
Comparative ranking
| Rank | Candidate | Required validation | Assessment |
|---|---|---|---|
| 1 | pr-plus-reviewer |
PASS — 1/1 targeted iOS test | Best lifecycle design and most direct assertion. It addresses both unresolved prior-review concerns while preserving current selection state across pre-attachment changes. |
| 2 | pr |
PASS, but the trusted Gate also passed three broken-baseline runs | The attachment latch is focused and stale-state-safe, but it replays synchronously inside MovedToWindow; the test cannot validate that attachment alone is a sufficient UIKit readiness boundary. |
| 3 | try-fix-1 |
PASS after its permitted namespace correction | A next-main-runloop dispatch is compatible, but it is scheduled before attachment and never rechecks IsLoaded(). It can therefore run before MovedToWindow, the timing risk called out in prior review. |
| 4 | try-fix-2 |
FAIL twice — identical 7.56% screenshot mismatch | Immediate pre-attachment selection failed both with normal animation and with animation disabled. Per contract, a candidate failing the targeted regression command ranks below passing candidates. |
Expert review
The single authorized maui-expert-reviewer pass wrote a valid empty inline-findings.json. Prior-review reconciliation nevertheless found two unresolved concerns on the submitted PR:
- The screenshot regression test is non-discriminating; the trusted Gate proves it passes without the fix.
- Synchronous selection from
AttachingToWindow()is not proven to occur after UIKit item generation/layout, and the author's test-based dismissal is invalidated by that Gate result.
Why the submitted PR should not be approved as-is
The raw pr candidate does not win, and the trusted Gate explicitly forbids treating its test as regression proof. The winning changes must be applied to the submitted branch before approval: defer replay after attachment with a loaded-state recheck, and replace the screenshot-only assertion with direct selected-state verification. Even then, confidence remains limited until a negative-control run demonstrates that the refined test fails on the broken baseline.
Candidate artifacts
- Reviewer delta:
pr-plus-reviewer/reviewer.patch - Complete candidate diff:
pr-plus-reviewer/candidate.patch - Focused validation:
pr-plus-reviewer/validation.log - Candidate summary:
pr-plus-reviewer/content.md
📱 UI Tests — CollectionView
Detected UI test categories: CollectionView
✅ Deep UI tests — 432 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 |
432/437 (5 skipped) ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
🧭 Next Steps — reviewer changes required
The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.
Why: pr-plus-reviewer won because it preserves the PR's attachment gate, adds the missing post-attachment main-queue deferral with a detach-safe loaded-state recheck, and directly verifies the selected visual state. Its targeted iOS validation passed, although the failed Gate means efficacy against the broken baseline remains unproven.
Address the actionable findings in this review before merging.
… assigned in ApplyQueryAttributes (#38614) <!-- 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! ### Issue Details On iOS, when navigating to a page containing a CollectionView, setting SelectedItem immediately in ApplyQueryAttributes does not update the native selection or selected visual state. The issue occurs because selection is applied before the native UICollectionView has completed its current UI processing and generated the required item. ### Description of Changes Updated SelectableItemsViewController2.SelectItem to defer the initial native selection using DispatchQueue.MainQueue.DispatchAsync when the CollectionView is not yet loaded. This allows pending UIKit navigation and collection setup work to complete before applying selection. Compared with an empty PerformBatchUpdates call, DispatchAsync more directly represents the required behavior because no collection insert, delete, move, or reload operation is being performed. Fixes #38443 **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/47dfe037-7cb7-43b0-8313-085eb459251e" width="300" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/eff1a4d7-6670-41e9-a23c-d17646953c26" width="300" height="600"> |
… assigned in ApplyQueryAttributes (#38614) <!-- 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! ### Issue Details On iOS, when navigating to a page containing a CollectionView, setting SelectedItem immediately in ApplyQueryAttributes does not update the native selection or selected visual state. The issue occurs because selection is applied before the native UICollectionView has completed its current UI processing and generated the required item. ### Description of Changes Updated SelectableItemsViewController2.SelectItem to defer the initial native selection using DispatchQueue.MainQueue.DispatchAsync when the CollectionView is not yet loaded. This allows pending UIKit navigation and collection setup work to complete before applying selection. Compared with an empty PerformBatchUpdates call, DispatchAsync more directly represents the required behavior because no collection insert, delete, move, or reload operation is being performed. Fixes #38443 **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/47dfe037-7cb7-43b0-8313-085eb459251e" width="300" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/eff1a4d7-6670-41e9-a23c-d17646953c26" width="300" height="600"> |
… assigned in ApplyQueryAttributes (#38614) <!-- 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! ### Issue Details On iOS, when navigating to a page containing a CollectionView, setting SelectedItem immediately in ApplyQueryAttributes does not update the native selection or selected visual state. The issue occurs because selection is applied before the native UICollectionView has completed its current UI processing and generated the required item. ### Description of Changes Updated SelectableItemsViewController2.SelectItem to defer the initial native selection using DispatchQueue.MainQueue.DispatchAsync when the CollectionView is not yet loaded. This allows pending UIKit navigation and collection setup work to complete before applying selection. Compared with an empty PerformBatchUpdates call, DispatchAsync more directly represents the required behavior because no collection insert, delete, move, or reload operation is being performed. Fixes #38443 **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/47dfe037-7cb7-43b0-8313-085eb459251e" width="300" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/eff1a4d7-6670-41e9-a23c-d17646953c26" width="300" height="600"> |
|
/backport to inflight/candidate |
|
Started backporting to |
…vigation (#39327) <!-- 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. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Backport of #38614 to `inflight/candidate`, intentionally targeting the SR12 staging branch rather than `main`. Fixes the documented 10.0.100 iOS CollectionView rendering/selection regression when SelectedItem is assigned in ApplyQueryAttributes during Shell navigation. Carries the original modern Apple CollectionView controller correction, Issue38443 regression page and UI test, and all five source snapshots. No legacy-handler, API, dependency or unrelated inflight changes are added. Original GitHub merge: `4022ea1d0f9a7d945366b59e5a50489d5b27a408`; rebased current equivalent: `63f74ce66c9e92ec9c47af513fc42777030f8041`. Backport head: `ff41f61a3434f7e1f885ff244aa66682373fc889`. **Validation** - `git diff --binary 3d96e23 ff41f61 | git patch-id --stable` — passed: complete binary-inclusive source patch identity matches `c13cebec3bb19538ec0db115d33dced8b732a4d7`. - `git diff --check 3d96e23 ff41f61` — passed. - Local builds and runtime/UI tests were not rerun for this unchanged automated replay. PR-head CI results are pending; this is not a merge-readiness verdict. No XCTest, Appium, simulator/emulator or GUI execution was performed. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38443 in the SR12 Candidate selection. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> /cc @kubaflo @devanathan-vaithiyanathan --------- Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
… assigned in ApplyQueryAttributes (#38614) <!-- 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! ### Issue Details On iOS, when navigating to a page containing a CollectionView, setting SelectedItem immediately in ApplyQueryAttributes does not update the native selection or selected visual state. The issue occurs because selection is applied before the native UICollectionView has completed its current UI processing and generated the required item. ### Description of Changes Updated SelectableItemsViewController2.SelectItem to defer the initial native selection using DispatchQueue.MainQueue.DispatchAsync when the CollectionView is not yet loaded. This allows pending UIKit navigation and collection setup work to complete before applying selection. Compared with an empty PerformBatchUpdates call, DispatchAsync more directly represents the required behavior because no collection insert, delete, move, or reload operation is being performed. Fixes #38443 **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/47dfe037-7cb7-43b0-8313-085eb459251e" width="300" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/eff1a4d7-6670-41e9-a23c-d17646953c26" width="300" height="600"> |
…vigation (#39327) <!-- 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. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Backport of #38614 to `inflight/candidate`, intentionally targeting the SR12 staging branch rather than `main`. Fixes the documented 10.0.100 iOS CollectionView rendering/selection regression when SelectedItem is assigned in ApplyQueryAttributes during Shell navigation. Carries the original modern Apple CollectionView controller correction, Issue38443 regression page and UI test, and all five source snapshots. No legacy-handler, API, dependency or unrelated inflight changes are added. Original GitHub merge: `4022ea1d0f9a7d945366b59e5a50489d5b27a408`; rebased current equivalent: `63f74ce66c9e92ec9c47af513fc42777030f8041`. Backport head: `ff41f61a3434f7e1f885ff244aa66682373fc889`. **Validation** - `git diff --binary 3d96e23 ff41f61 | git patch-id --stable` — passed: complete binary-inclusive source patch identity matches `c13cebec3bb19538ec0db115d33dced8b732a4d7`. - `git diff --check 3d96e23 ff41f61` — passed. - Local builds and runtime/UI tests were not rerun for this unchanged automated replay. PR-head CI results are pending; this is not a merge-readiness verdict. No XCTest, Appium, simulator/emulator or GUI execution was performed. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38443 in the SR12 Candidate selection. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> /cc @kubaflo @devanathan-vaithiyanathan --------- Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
… assigned in ApplyQueryAttributes (#38614) <!-- 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! ### Issue Details On iOS, when navigating to a page containing a CollectionView, setting SelectedItem immediately in ApplyQueryAttributes does not update the native selection or selected visual state. The issue occurs because selection is applied before the native UICollectionView has completed its current UI processing and generated the required item. ### Description of Changes Updated SelectableItemsViewController2.SelectItem to defer the initial native selection using DispatchQueue.MainQueue.DispatchAsync when the CollectionView is not yet loaded. This allows pending UIKit navigation and collection setup work to complete before applying selection. Compared with an empty PerformBatchUpdates call, DispatchAsync more directly represents the required behavior because no collection insert, delete, move, or reload operation is being performed. Fixes #38443 **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/47dfe037-7cb7-43b0-8313-085eb459251e" width="300" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/eff1a4d7-6670-41e9-a23c-d17646953c26" width="300" height="600"> |
…vigation (#39327) <!-- 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. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Backport of #38614 to `inflight/candidate`, intentionally targeting the SR12 staging branch rather than `main`. Fixes the documented 10.0.100 iOS CollectionView rendering/selection regression when SelectedItem is assigned in ApplyQueryAttributes during Shell navigation. Carries the original modern Apple CollectionView controller correction, Issue38443 regression page and UI test, and all five source snapshots. No legacy-handler, API, dependency or unrelated inflight changes are added. Original GitHub merge: `4022ea1d0f9a7d945366b59e5a50489d5b27a408`; rebased current equivalent: `63f74ce66c9e92ec9c47af513fc42777030f8041`. Backport head: `ff41f61a3434f7e1f885ff244aa66682373fc889`. **Validation** - `git diff --binary 3d96e23 ff41f61 | git patch-id --stable` — passed: complete binary-inclusive source patch identity matches `c13cebec3bb19538ec0db115d33dced8b732a4d7`. - `git diff --check 3d96e23 ff41f61` — passed. - Local builds and runtime/UI tests were not rerun for this unchanged automated replay. PR-head CI results are pending; this is not a merge-readiness verdict. No XCTest, Appium, simulator/emulator or GUI execution was performed. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38443 in the SR12 Candidate selection. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> /cc @kubaflo @devanathan-vaithiyanathan --------- Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
… assigned in ApplyQueryAttributes (#38614) <!-- 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! ### Issue Details On iOS, when navigating to a page containing a CollectionView, setting SelectedItem immediately in ApplyQueryAttributes does not update the native selection or selected visual state. The issue occurs because selection is applied before the native UICollectionView has completed its current UI processing and generated the required item. ### Description of Changes Updated SelectableItemsViewController2.SelectItem to defer the initial native selection using DispatchQueue.MainQueue.DispatchAsync when the CollectionView is not yet loaded. This allows pending UIKit navigation and collection setup work to complete before applying selection. Compared with an empty PerformBatchUpdates call, DispatchAsync more directly represents the required behavior because no collection insert, delete, move, or reload operation is being performed. Fixes #38443 **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/47dfe037-7cb7-43b0-8313-085eb459251e" width="300" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/eff1a4d7-6670-41e9-a23c-d17646953c26" width="300" height="600"> |
…vigation (#39327) <!-- 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. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Backport of #38614 to `inflight/candidate`, intentionally targeting the SR12 staging branch rather than `main`. Fixes the documented 10.0.100 iOS CollectionView rendering/selection regression when SelectedItem is assigned in ApplyQueryAttributes during Shell navigation. Carries the original modern Apple CollectionView controller correction, Issue38443 regression page and UI test, and all five source snapshots. No legacy-handler, API, dependency or unrelated inflight changes are added. Original GitHub merge: `4022ea1d0f9a7d945366b59e5a50489d5b27a408`; rebased current equivalent: `63f74ce66c9e92ec9c47af513fc42777030f8041`. Backport head: `ff41f61a3434f7e1f885ff244aa66682373fc889`. **Validation** - `git diff --binary 3d96e23 ff41f61 | git patch-id --stable` — passed: complete binary-inclusive source patch identity matches `c13cebec3bb19538ec0db115d33dced8b732a4d7`. - `git diff --check 3d96e23 ff41f61` — passed. - Local builds and runtime/UI tests were not rerun for this unchanged automated replay. PR-head CI results are pending; this is not a merge-readiness verdict. No XCTest, Appium, simulator/emulator or GUI execution was performed. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38443 in the SR12 Candidate selection. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> /cc @kubaflo @devanathan-vaithiyanathan --------- Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
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!
Issue Details
On iOS, when navigating to a page containing a CollectionView, setting SelectedItem immediately in ApplyQueryAttributes does not update the native selection or selected visual state.
The issue occurs because selection is applied before the native UICollectionView has completed its current UI processing and generated the required item.
Description of Changes
Updated SelectableItemsViewController2.SelectItem to defer the initial native selection using DispatchQueue.MainQueue.DispatchAsync when the CollectionView is not yet loaded.
This allows pending UIKit navigation and collection setup work to complete before applying selection. Compared with an empty PerformBatchUpdates call, DispatchAsync more directly represents the required behavior because no collection insert, delete, move, or reload operation is being performed.
Fixes #38443
Tested the behavior in the following platforms.
Before-38443.mov
After-38443.mov