Repository navigation
[iOS/Mac Catalyst] Fix stale MapElementId left on other map elements after updating one - #37265
Conversation
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37265Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37265" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
Hey there @@SyedAbdulAzeemSF4852! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 3 findings
See inline comments for details.
| if (element.MapElementId is IMKOverlay overlay) | ||
| RemoveOverlay(overlay); | ||
|
|
||
| _trackedMapElements?.Remove(element); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[minor] Regression Prevention and Test Coverage — These two lines are not covered by a discriminating test. The only caller of RemoveElements is MapHandler.UpdateMapElement, which immediately calls AddElements for the same element; that re-assigns MapElementId and (thanks to the new Contains guard on line 175) avoids a duplicate tracked entry. Deleting both _trackedMapElements?.Remove(element) and element.MapElementId = null leaves every test in MapTests.cs green — including the new UpdatingSingleElementPreservesTrackingForOtherElements, which passes purely because of the ??= change on line 171. The untrack and the Contains guard are mutually redundant given today's callers; keep whichever you consider the invariant, and if both stay, add a test that exercises RemoveElements in isolation (or assert Overlays.Length after an update) so a future edit can't silently drop one.
This comment has been minimized.
This comment has been minimized.
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR fixes an iOS/Mac Catalyst tracking bug in MauiMKMapView where updating a single MapElement could unintentionally drop other elements from the internal tracked set, leading to stale MapElementId values after later clears/removals.
Changes:
- Replace
_trackedMapElementsreinitialization with a persistent reference-equalityHashSetso updates to one element don’t wipe tracking for others. - Ensure
RemoveElementsremoves elements from the tracked set and clearsMapElementId. - Add a device regression test covering “update one element, then clear all” behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Core/maps/src/Platform/iOS/MauiMKMapView.cs | Preserve element tracking across incremental updates; clean up tracking + MapElementId on removal. |
| src/Controls/tests/DeviceTests/Elements/Map/MapTests.cs | Adds a regression test ensuring updating one polyline doesn’t break tracking/cleanup for other elements. |
| var overlaysBefore = await InvokeOnMainThreadAsync(() => platformView.Overlays?.Length); | ||
| var polyline2IdBefore = polyline2.MapElementId; | ||
|
|
||
| await InvokeOnMainThreadAsync(() => polyline1.Geopath.Add(new Location(47.62, -122.33))); | ||
|
|
||
| // Updating polyline1 must not leak/drop native overlays or disturb polyline2's overlay. | ||
| var overlaysAfter = await InvokeOnMainThreadAsync(() => platformView.Overlays?.Length); | ||
| Assert.Equal(overlaysBefore, overlaysAfter); | ||
| Assert.Same(polyline2IdBefore, polyline2.MapElementId); |
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
| // Updating polyline1 must not leak/drop native overlays or disturb polyline2's overlay. | ||
| var overlaysAfter = await InvokeOnMainThreadAsync(() => platformView.Overlays?.Length); | ||
| Assert.Equal(overlaysBefore, overlaysAfter); | ||
| Assert.Same(polyline2IdBefore, polyline2.MapElementId); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Regression Prevention and Test Coverage — This regression test cannot discriminate between "the single-element update ran and tracking survived" (the fixed behavior) and "the single-element update never ran at all". Nothing asserts that polyline1.Geopath.Add(...) actually routed through MapElementPropertyChanged → IMapHandler.UpdateMapElement → MauiMKMapView.RemoveElements/AddElements. Concrete failing scenario: if a future change stops raising PropertyChanged for Geopath mutations (or the UpdateMapElement command mapper stops firing), _trackedMapElements still holds {polyline1, polyline2} from the initial AddElements call, so overlaysBefore == overlaysAfter (2), polyline2.MapElementId is unchanged, and both ids are nulled by ClearMapElements after MapElements.Clear() — the test passes green while silently guarding nothing, which is exactly the regression it was written to catch. Capture polyline1.MapElementId before the Geopath mutation and assert it changed (e.g. Assert.NotSame(polyline1IdBefore, polyline1.MapElementId)), since RemoveElements + AddElements necessarily creates a new MKPolyline overlay; that turns the test into a real precondition check for the update path.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@SyedAbdulAzeemSF4852 — new AI review results are available based on commit
3434a3b.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ⚠️ INCONCLUSIVE
Platform: IOS · Base: main · Merge base: d235550b
🩺 Could not verify — environment/infrastructure error. The gate ran the tests but hit an environment error (an emulator/simulator/Appium/XHarness flake, a device that would not boot, or an empty/invalid result file), so it could not record a real pass/fail. The /review to retry on a fresh agent.
XHarness did not produce the expected fresh result 'testResults.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.MapTests' (the target tests did not run).
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
📱 MapTests (UpdatingSingleElementPreservesTrackingForOtherElements) Category=Map |
🔴 Without fix — 📱 MapTests (UpdatingSingleElementPreservesTrackingForOtherElements): ⚠️ ENV ERROR · 186s
No log file found
🟢 With fix — 📱 MapTests (UpdatingSingleElementPreservesTrackingForOtherElements): ⚠️ ENV ERROR · 82s
No log file found
⚠️ Failure Details
⚠️ MapTests (UpdatingSingleElementPreservesTrackingForOtherElements) without fix:XHarness did not produce the expected fresh result 'testResults.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.MapTests' (the target tests did not run).⚠️ MapTests (UpdatingSingleElementPreservesTrackingForOtherElements) with fix:XHarness did not produce the expected fresh result 'testResults.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.MapTests' (the target tests did not run).
📁 Fix files reverted (1 files)
src/Core/maps/src/Platform/iOS/MauiMKMapView.cs
📋 Pre-Flight — Context & Validation
PR #37265 Pre-Flight
Context
- Title:
[iOS/Mac Catalyst] Fix stale MapElementId left on other map elements after updating one - Issue: #37229
- Base / head:
main/fix-37229 - Local materialization: commit
57d3f5798aba2ff68f45cae99795277ac2612f94(PR #37265 squashed for review) - Target platform for STEP 5a: iOS
- Gate: INCONCLUSIVE because the prior gate could not build/run in the environment. Do not rerun the gate and do not interpret this as a fix failure.
Problem and Root Cause
On iOS and Mac Catalyst, changing one MapElement invokes
MapHandler.UpdateMapElement, which removes and re-adds only that element.
The baseline MauiMKMapView.AddElements replaces _trackedMapElements with a
new list on every call. Updating one element therefore drops every untouched
element from the tracking list. A later clear or map-pool cleanup removes the
native overlays but cannot null the untouched elements' MapElementId, leaving
stale native references.
The call path is:
- A
MapElementproperty changes (commonly aPolylineorPolygon
Geopathmutation). Map.MapElementPropertyChangedinvokes
IMapHandler.UpdateMapElement.- iOS
MapHandler.UpdateMapElementcallsRemoveElements(new[] { element })
andAddElements(new[] { element }). - Baseline
AddElementsreplaces the complete tracking list with that
one-element input. ClearMapElementslater nulls only the last-updated element's ID.
This tracking list was introduced for #30097 because
Handler.VirtualView.Elements is already empty when collection-clear mapping
runs.
Current PR Fix
The PR changes MauiMKMapView from List<IMapElement> to
HashSet<IMapElement> with ReferenceEqualityComparer.Instance, lazily
initializes it in AddElements, and makes RemoveElements both untrack the
element and clear its MapElementId. Its test mutates one of two polylines,
checks overlay count and the untouched polyline's ID identity, then clears and
requires both IDs to be null.
- List<IMapElement>? _trackedMapElements;
+ HashSet<IMapElement>? _trackedMapElements;
- _trackedMapElements = new List<IMapElement>();
+ _trackedMapElements ??= new HashSet<IMapElement>(ReferenceEqualityComparer.Instance);
foreach (IMapElement element in elements)
{
_trackedMapElements.Add(element);
...
}
if (element.MapElementId is IMKOverlay overlay)
RemoveOverlay(overlay);
+ _trackedMapElements?.Remove(element);
+ element.MapElementId = null;The PR also adds
UpdatingSingleElementPreservesTrackingForOtherElements to
src/Controls/tests/DeviceTests/Elements/Map/MapTests.cs.
Review-Relevant History
e76b6e92e6added clearing ofMapElementIdfor #30097.cfb19d73bb/5cfecbc366added the tracked list and map-pool cleanup for
#35479/#35690.- Prior PR review feedback prompted the current reference-identity
HashSet
and stronger overlay/identity assertions. - Candidate fixes must use a different root-cause strategy from the PR's
accumulatingHashSetapproach.
Bounded Validation
Use only:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 `
-Project Controls -Platform ios -TestFilter "Category=Map"This bounded category contains the primary
UpdatingSingleElementPreservesTrackingForOtherElements test and the directly
coupled map regressions:
ClearMapElementsResetsMapElementIdClearResetsMapElementIdForAllElementTypesRemoveSingleElementPreservesOtherMapElementIdsDisconnectClearsNativeMapStateBeforePooling
Do not run a full device-test or repository test suite.
Target Files
src/Core/maps/src/Platform/iOS/MauiMKMapView.cssrc/Core/maps/src/Handlers/Map/MapHandler.iOS.cssrc/Controls/Maps/src/Map.cssrc/Controls/tests/DeviceTests/Elements/Map/MapTests.cs
The worktree contains unrelated pre-existing changes under .github/ and
eng/. Preserve them. Use only EstablishBrokenBaseline.ps1 and its
-Restore mode for candidate baseline management.
🔬 Code Review — Deep Analysis
Code Review — PR #37265
Independent Assessment
What this changes: The iOS/Mac Catalyst map view now retains a reference-identity set of all currently tracked map elements across a single-element native overlay replacement. Removing an element also removes it from that set and clears its MapElementId.
Inferred motivation: MapHandler.UpdateMapElement removes and re-adds only the changed element. The prior AddElements implementation replaced the complete tracking list with that one-element input, so later map clearing could not clear the untouched elements' native IDs.
Reconciliation with PR Narrative
The submitted implementation and its stated root cause agree with the traced call path. The HashSet<IMapElement> remains instance-scoped and bounded: collection refresh and handler reuse call ClearMapElements, while point updates remove and re-add the same reference. No public API, startup, threading, or cross-platform behavior changes.
Prior Review Reconciliation
The GitHub review surfaces were unavailable because gh is unauthenticated. The supplied pre-flight context records earlier feedback that led to reference-identity tracking and stronger identity assertions; no unresolved prior error-level finding is identified there.
Blast Radius Assessment
- Runs for all instances: Only iOS/Mac Catalyst
MauiMKMapViewinstances that manage map elements. - Startup impact: None; tracking is initialized lazily by
AddElements. - Static/shared state: None; the set is per map view and cleared before pooling.
- Null/default state:
ClearMapElementsandRemoveElementssafely handle a null tracking set.
CI Status
- Required-check result: Gate inconclusive; the required tests could not be built or run because of an environment/build error.
- Classification: Undetermined, not a regression failure.
- Action taken: No gate rerun, as required; confidence is capped at low.
Findings
⚠️ Warning — Regression test does not prove the update path ran
src/Controls/tests/DeviceTests/Elements/Map/MapTests.cs:160 checks that overlay count and the untouched polyline's identity remain stable, then checks cleanup. All of those assertions also pass if the Geopath mutation never invokes UpdateMapElement, because the original two-element tracking state remains intact. Capture polyline1.MapElementId before mutation and assert that it changes afterward; replacing the updated polyline necessarily creates a new native overlay.
No production-code correctness error was found.
Failure-Mode Probing
- Full collection refresh:
MapElementscallsClearMapElementsbeforeAddElements, clearing all tracked IDs and starting a new set. - Repeated point updates:
RemoveElementsuntracks and nulls the updated element, thenAddElementsadds the same reference once; the set neither duplicates nor grows. - Individual collection removal: the collection mapper performs a full clear/repopulate, so removed elements are released and remaining elements are re-tracked.
- Handler reuse:
PrepareForReuseclears overlays and tracked IDs before the native view enters the pool. - Null handlers/platform state and threading: the changed methods retain the existing synchronous UI-thread call path and add no handler dereference.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: The production fix is sound on code inspection, but its new regression test can pass without exercising the behavior it claims to protect. The supplied gate is inconclusive, so the fix has no current execution evidence; the test assertion should be strengthened in the reviewer candidate.
🛠️ Try-Fix — Analysis & Comparison
PR #37265 — Try-Fix Candidates
Candidate 1 — claude-opus-5
Result: ✅ Pass — 5/5 tests in Category=Map passed on iOS.
Artifacts: CustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/
Findings count (inline MAUI expert self-review): 2 (0 critical, 0 major, 2 minor)
Approach: dedicated in-place single-element update path
Root-cause hypothesis (materially different from the PR's)
MauiMKMapView.AddElements is a full-snapshot repopulate. Its only legitimate
caller is the MapElements mapper, which always calls ClearMapElements() first:
public static void MapElements(IMapHandler handler, IMap map)
{
handler.PlatformView.ClearMapElements();
handler.PlatformView.AddElements((IList)map.Elements);
}Under that contract _trackedMapElements = new List<IMapElement>() is correct —
the list is a snapshot of the element collection, rebuilt whenever the collection is.
The real defect is a layering violation in the single-element update path:
public void UpdateMapElement(IMapElement element)
{
PlatformView.RemoveElements(new[] { element });
PlatformView.AddElements(new[] { element }); // truncates the snapshot to 1 element
}UpdateMapElement is a point mutation of one element's native overlay. Passing a
1-element list to a snapshot-replacement API is what drops every untouched element
from tracking, so a later ClearMapElements() / PrepareForReuse() can only null
the last-updated element's MapElementId.
Fix
- Extract the overlay-construction switch out of
AddElementsinto
static IMKOverlay? CreateOverlay(IMapElement)— behavior-neutral, removes the
duplication the new path would otherwise introduce. - Add
internal void UpdateElement(IMapElement element): swap only that element's
overlay in place, never touching_trackedMapElements. The element is
already in the snapshot and stays there. MapHandler.iOS.UpdateMapElementcallsPlatformView.UpdateElement(element).
_trackedMapElements stays a plain List<IMapElement>. AddElements and
RemoveElements keep their baseline behavior verbatim.
Ordering is deliberate: element.MapElementId is assigned before AddOverlay,
because AddOverlay synchronously drives GetViewForOverlayDelegate →
GetMapElement<T>, which resolves the owning element via
ReferenceEquals(element.MapElementId, overlay). Assigning after would throw
InvalidOperationException: MKOverlayRenderer not found.
How this differs from the PR
| PR #37265 | Candidate 1 | |
|---|---|---|
| Root-cause hypothesis | The tracking container has wrong semantics; it must accumulate | The container is fine; the single-element update path must not call the bulk snapshot API |
| Container | List → HashSet + ReferenceEqualityComparer |
stays List |
AddElements |
??= lazy-init, accumulates forever |
unchanged (new List) |
RemoveElements |
gains new responsibility (untrack + null MapElementId) |
unchanged |
MapHandler.iOS.cs |
untouched | UpdateMapElement rerouted to a dedicated in-place API |
| Retention | tracked set accumulates across every repopulate; elements removed from Map.MapElements stay referenced until an explicit clear |
snapshot lifetime stays bounded to the current element collection |
No accumulating set or list is introduced — this is not a cosmetic variation.
Files changed
src/Core/maps/src/Platform/iOS/MauiMKMapView.cs(+41/−20)src/Core/maps/src/Handlers/Map/MapHandler.iOS.cs(+1/−2)
No test files were modified: the PR's UpdatingSingleElementPreservesTrackingForOtherElements
regression test was used as-is to validate this candidate.
No public API surface change (UpdateElement and CreateOverlay are internal/static
private), so no PublicAPI.Unshipped.txt entry is required.
Exact diff
diff --git a/src/Core/maps/src/Handlers/Map/MapHandler.iOS.cs b/src/Core/maps/src/Handlers/Map/MapHandler.iOS.cs
index c04738c0b9..89fc1a578c 100644
--- a/src/Core/maps/src/Handlers/Map/MapHandler.iOS.cs
+++ b/src/Core/maps/src/Handlers/Map/MapHandler.iOS.cs
@@ -95,8 +95,7 @@ namespace Microsoft.Maui.Maps.Handlers
public void UpdateMapElement(IMapElement element)
{
- PlatformView.RemoveElements(new[] { element });
- PlatformView.AddElements(new[] { element });
+ PlatformView.UpdateElement(element);
}
void MoveToRegion(MapSpan mapSpan, bool animated = true)
diff --git a/src/Core/maps/src/Platform/iOS/MauiMKMapView.cs b/src/Core/maps/src/Platform/iOS/MauiMKMapView.cs
index 9c0c7f7e94..e312b5aff6 100644
--- a/src/Core/maps/src/Platform/iOS/MauiMKMapView.cs
+++ b/src/Core/maps/src/Platform/iOS/MauiMKMapView.cs
@@ -174,25 +174,7 @@ namespace Microsoft.Maui.Maps.Platform
{
_trackedMapElements.Add(element);
- IMKOverlay? overlay = null;
- switch (element)
- {
- case IGeoPathMapElement geoPathElement:
- if (geoPathElement is IFilledMapElement)
- overlay = MKPolygon.FromCoordinates(geoPathElement
- .Select(position => new CLLocationCoordinate2D(position.Latitude, position.Longitude))
- .ToArray());
- else
- overlay = MKPolyline.FromCoordinates(geoPathElement
- .Select(position => new CLLocationCoordinate2D(position.Latitude, position.Longitude))
- .ToArray());
- break;
- case ICircleMapElement circleElement:
- overlay = MKCircle.Circle(
- new CLLocationCoordinate2D(circleElement.Center.Latitude, circleElement.Center.Longitude),
- circleElement.Radius.Meters);
- break;
- }
+ IMKOverlay? overlay = CreateOverlay(element);
if (overlay != null)
{
@@ -202,6 +184,23 @@ namespace Microsoft.Maui.Maps.Platform
}
}
+ // Updates a single element's native overlay in place.
+ // AddElements is a full-snapshot operation (it rebuilds _trackedMapElements and is only
+ // valid immediately after ClearMapElements), so a single-element update must NOT route
+ // through it - doing so truncated the tracking snapshot to the updated element and left
+ // stale MapElementId values on every other element. See https://github.com/dotnet/maui/issues/37229.
+ internal void UpdateElement(IMapElement element)
+ {
+ if (element.MapElementId is IMKOverlay oldOverlay)
+ RemoveOverlay(oldOverlay);
+
+ IMKOverlay? overlay = CreateOverlay(element);
+ element.MapElementId = overlay;
+
+ if (overlay != null)
+ AddOverlay(overlay);
+ }
+
internal void RemoveElements(IList elements)
{
foreach (IMapElement element in elements)
@@ -211,6 +210,28 @@ namespace Microsoft.Maui.Maps.Platform
}
}
+ static IMKOverlay? CreateOverlay(IMapElement element)
+ {
+ switch (element)
+ {
+ case IGeoPathMapElement geoPathElement:
+ if (geoPathElement is IFilledMapElement)
+ return MKPolygon.FromCoordinates(geoPathElement
+ .Select(position => new CLLocationCoordinate2D(position.Latitude, position.Longitude))
+ .ToArray());
+
+ return MKPolyline.FromCoordinates(geoPathElement
+ .Select(position => new CLLocationCoordinate2D(position.Latitude, position.Longitude))
+ .ToArray());
+ case ICircleMapElement circleElement:
+ return MKCircle.Circle(
+ new CLLocationCoordinate2D(circleElement.Center.Latitude, circleElement.Center.Longitude),
+ circleElement.Radius.Meters);
+ default:
+ return null;
+ }
+ }
+
void Startup()
{
RegionChanged += MkMapViewOnRegionChanged;Test command and results
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 `
-Project Controls -Platform ios -TestFilter "Category=Map"One implementation/test pass; no correction round and no retest were needed
(1 of the 2 permitted test executions used).
XHarness exit code 0 on iPhone 11 Pro / iOS 26.5 simulator:
Tests run: 5 Passed: 5 Inconclusive: 0 Failed: 0 Ignored: 0 Skipped: 0
Per-test results (artifacts/log/xunit-test-ios-simulator-64_26.5-20260812_031943.xml):
| Test | Result |
|---|---|
UpdatingSingleElementPreservesTrackingForOtherElements (PR regression test) |
✅ Pass |
ClearMapElementsResetsMapElementId |
✅ Pass |
ClearResetsMapElementIdForAllElementTypes |
✅ Pass |
RemoveSingleElementPreservesOtherMapElementIds |
✅ Pass |
DisconnectClearsNativeMapStateBeforePooling |
✅ Pass |
Baseline was established with .github/scripts/EstablishBrokenBaseline.ps1
(reverted src/Core/maps/src/Platform/iOS/MauiMKMapView.cs to merge-base
d235550b), confirming the candidate was authored against the broken state and
not on top of the PR's fix.
Inline MAUI expert self-review
Performed inline against .github/agents/maui-expert-reviewer.md (Overarching
Principles + always-active dimensions Logic and Correctness / Regression
Prevention / Complexity Reduction + Handler Mapper and Property Patterns for the
handler change). No @maui-expert-reviewer sub-agent was spawned.
Summary: 2 findings — 0 critical, 0 major, 2 minor. No pre-test correction
round was required. Full JSON in
try-fix/attempt-1/reviewer-findings.json.
[minor] Logic and Correctness—MauiMKMapView.cs:192.UpdateElement
relies on the implicit invariant that an updated element is already in the
tracking snapshot. The invariant holds on every production path
(Map.MapElementPropertyChangedonly fires for elements inMap.MapElements,
which are always populated through theMapElementsmapper), so there is no
concrete failing scenario today.[minor] Complexity Reduction—MapHandler.iOS.cs:98. Rerouting
UpdateMapElementleavesMauiMKMapView.RemoveElementswith no production
caller on iOS. It isinternal, so there is no public API impact; deleting it
is out of scope for this fix.
Checks that passed explicitly: no allocation added to a hot path (element updates
are user-driven, not per-frame); no threading change (all calls stay on the main
thread, same as baseline); iOS-only change that cannot affect Android/Windows
(MapHandler.Android.cs / .Windows.cs untouched); MapElementId is assigned
before AddOverlay so the overlay-renderer lookup still resolves; git history for
e76b6e92e6 / cfb19d73bb / 5cfecbc366 reviewed via the pre-flight summary so
the #30097 and #35479/#35690 behavior (ClearMapElements nulling tracked IDs, and
PrepareForReuse on pooling) is preserved unchanged — confirmed by
ClearMapElementsResetsMapElementId, ClearResetsMapElementIdForAllElementTypes
and DisconnectClearsNativeMapStateBeforePooling all passing.
Failure analysis
Not applicable — the candidate passed. One environment note worth recording: the
iOS device-test build regenerates
src/Core/src/Handlers/HybridWebView/HybridWebView.js from TypeScript. It appears
in git diff and trips the try-fix Step 7.5 drift check even when no source was
edited during the test loop. The candidate's own diff was byte-identical before
and after the test run, so the self-review was already current and was not
rewritten; fix.diff / reviewer-findings.diff are scoped to src/Core/maps,
and the generated .js was reverted during restore.
Artifact paths
CustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/approach.mdCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/baseline.logCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/fix.diffCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/test-output.logCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/result.txtCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/analysis.mdCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/reviewer-findings.jsonCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-1/reviewer-findings.diff
Candidate 2 — gpt-5.6-sol
PR: #37265, STEP 5a
Result: ✅ Pass — the bounded Category=Map command completed
successfully; the in-app runner reported 5/5 tests passed on iOS.
Artifacts: CustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/
Findings count (inline MAUI expert self-review): 0
Approach: clear-delimited tracking snapshot
Root-cause hypothesis
AddElements serves two existing operations:
- A collection-wide refresh from the
MapElementsmapper, always preceded by
ClearMapElements. - Native overlay replacement for one existing element from
MapHandler.UpdateMapElement, not preceded by a clear.
ClearMapElements already sets _trackedMapElements to null. That null state is
therefore the lifecycle boundary indicating that the next AddElements call
must initialize a new complete snapshot. The defect is that baseline
AddElements unconditionally replaces the list even when no clear occurred.
The fix records whether the list was null on entry, initializes it only in that
case, and adds incoming elements to tracking only during that initialization.
The existing point-update remove/add path still replaces the updated native
overlay, but does not replace or append to the tracking snapshot.
The List<IMapElement> remains bounded to the current collection snapshot. It
does not accumulate duplicate point-update entries, and the next collection
refresh discards the old snapshot through the existing clear/null lifecycle.
Comparison with the PR and Candidate 1
| PR #37265 | Candidate 1 | Candidate 2 | |
|---|---|---|---|
| Root-cause strategy | Tracking container must accumulate identities correctly | Point updates must not call the bulk snapshot API | Tracking initialization must honor the existing clear/null lifecycle |
| Container | HashSet with reference equality |
Existing List |
Existing List |
| Point update | Existing remove/add path; set accumulates/untracks | New dedicated in-place UpdateElement path |
Existing remove/add path unchanged |
AddElements |
Lazily creates and always adds to accumulating set | Bulk path unchanged | Initializes/fills snapshot only after clear |
| New overlay helper | None | Extracts CreateOverlay |
None |
| Retention | Accumulating set, explicitly untracked on remove | Bounded collection snapshot | Bounded collection snapshot |
This is neither the PR's accumulating tracking-container strategy nor Candidate
1's dedicated single-overlay update under another name.
Files changed
src/Core/maps/src/Platform/iOS/MauiMKMapView.cs(+4/−2)
No test files were changed. The PR's regression test and its four coupled map
tests were exercised as-is. No public API surface changed.
Exact diff
diff --git a/src/Core/maps/src/Platform/iOS/MauiMKMapView.cs b/src/Core/maps/src/Platform/iOS/MauiMKMapView.cs
index 9c0c7f7e94..b175795724 100644
--- a/src/Core/maps/src/Platform/iOS/MauiMKMapView.cs
+++ b/src/Core/maps/src/Platform/iOS/MauiMKMapView.cs
@@ -168,11 +168,13 @@ namespace Microsoft.Maui.Maps.Platform
internal void AddElements(IList elements)
{
- _trackedMapElements = new List<IMapElement>();
+ bool initializeTrackedElements = _trackedMapElements is null;
+ _trackedMapElements ??= new List<IMapElement>();
foreach (IMapElement element in elements)
{
- _trackedMapElements.Add(element);
+ if (initializeTrackedElements)
+ _trackedMapElements.Add(element);
IMKOverlay? overlay = null;
switch (element)Test command and results
Exactly one test execution was used; no focused correction or retest was
needed:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform ios -TestFilter "Category=Map"- Build: succeeded with 0 errors.
- In-app result:
Tests run: 5 Passed: 5 Inconclusive: 0 Failed: 0 Ignored: 0 Skipped: 0. - XHarness exit code:
0(SUCCESS) on iPhone 11 Pro / iOS 26.5. - Script result:
Tests completed successfully.
The device communication did not transfer a results file, so the script's
post-processing summary showed Passed: 0, Failed: 0; the captured application
log nevertheless contains the explicit 5/5 runner result, and the command
returned success.
Inline MAUI expert self-review
Performed inline against .github/agents/maui-expert-reviewer.md; no reviewer
agent was spawned. Reviewed every Overarching Principle, the always-active
Logic and Correctness / Regression Prevention / Complexity Reduction
dimensions, and the routed Performance-Critical Path / Memory Leak Prevention /
iOS and Mac Catalyst Platform dimensions.
Summary: 0 findings — clean. The source diff was unchanged by testing, so
the pre-test review remained current. The change adds no per-update collection
allocation, keeps tracking bounded, changes no public API or threading
behavior, and remains scoped to the existing iOS/Mac Catalyst implementation.
The PR regression test covers the point-update branch while the existing clear,
remove, and disconnect tests cover snapshot reinitialization and cleanup.
Failure analysis
Not applicable; the candidate passed. The only test-run caveat was the results
file transfer issue described above, which did not affect the in-app 5/5 result,
XHarness success, or test command exit code.
Artifact paths
CustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/approach.mdCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/baseline.logCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/fix.diffCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/test-output.logCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/result.txtCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/analysis.mdCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/reviewer-findings.jsonCustomAgentLogsTmp/PRState/37265/PRAgent/try-fix/attempt-2/reviewer-findings.diff
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer
pr-plus-reviewer preserves the submitted production fix, which the expert review found correct, and resolves the review's only actionable issue by proving that the changed polyline actually receives a replacement native overlay. Its focused validation was blocked before test execution by the machine's Xcode 26.5 / .NET iOS SDK 26.0 incompatibility, so the candidate remains unverified rather than failed.
Comparative ranking
| Rank | Candidate | Validation | Review assessment | Decision |
|---|---|---|---|---|
| 1 | pr-plus-reviewer |
Sound submitted production fix; only expert finding resolved with a discriminating assertion | Winner | |
| 2 | try-fix-2 |
✅ 5/5 iOS Map tests passed | Smallest alternative production diff and no self-review findings, but it retains the submitted test's blind spot and relies on null as an implicit snapshot boundary |
Strong runner-up |
| 3 | try-fix-1 |
✅ 5/5 iOS Map tests passed | Dedicated update API is sound, but it is materially larger, leaves an implicit tracked-element invariant and dead RemoveElements path, and retains the test blind spot |
Correct but less focused |
| 4 | pr |
Production code is sound, but the regression test can pass without invoking UpdateMapElement |
Needs the reviewer test change |
No candidate failed the regression tests. The two STEP 5a alternatives therefore receive full credit for their passing runs; the winner's blocked run is explicitly not treated as a pass or a failure. The deciding factor is that pr-plus-reviewer combines the expert-approved submitted implementation with the strongest regression contract and avoids replacing a sound production approach with a broader alternative.
Required change
Add the reviewer candidate's two-line test strengthening:
- Capture
polyline1.MapElementIdbefore mutatingGeopath. - Assert
Assert.NotSame(polyline1IdBefore, polyline1.MapElementId)after mutation.
The focused Category=Map iOS tests still need execution in an environment where the installed Xcode version matches the .NET iOS workload.
📱 UI Tests — Button,Label,Layout
Detected UI test categories: Button,Label,Layout
❌ Deep UI tests — 354 passed, 1 failed, 8 skipped across 3 categories on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
Button |
71/72 (1 skipped) ✓ | — |
Label |
90/92 (2 skipped) ✓ | — |
Layout |
193/199 (1 ❌, 5 skipped) | — |
🔍 AI analysis of failures — PR-related vs unrelated
🔍 AI-generated triage (GitHub Copilot CLI) — a heuristic judgement of whether each deep UI test failure is connected to this PR's changes. Verify before relying on it.
Likely unrelated: the failures appear pre-existing, flaky, or infrastructure.
- ● Unrelated — Editor scrolling layout (~1 test):
EditorsScrollingPageTestfailed to locate a UI element, while the PR only changes iOS map-overlay tracking and a map device test, which cannot plausibly affect Editor layout behavior.
❌ Layout — 1 failed test
EditorsScrollingPageTest
OpenQA.Selenium.NoSuchElementException : An element could not be located on the page using the given search parameters.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
at OpenQA.Selenium.WebDriver.ExecuteAsync(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Appium.AppiumDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Appium.AppiumDriver.FindElement(String by, String value)
at OpenQA.Selenium.Appium.MobileBy.FindElement(ISearchContext context)
at OpenQA.Selenium.WebDriver.FindElement(By by)
at OpenQA.Selenium.Appium.AppiumDriver.FindElement(By by)
at Microsoft.Maui.TestCases.Tests.KeyboardScrolling.CloseiOSEditorKeyboard(AppiumDr
...
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)
🧭 Next Steps — reviewer patch required (pr-plus-reviewer)
The reviewer-enhanced candidate won, so the submitted PR still needs those changes.
Why: The submitted production fix is sound, and pr-plus-reviewer resolves the expert review's only actionable finding by proving the single-element update path actually replaced the changed polyline's native overlay. Its focused validation was blocked by an Xcode/.NET iOS SDK mismatch rather than a candidate failure.
Apply PRAgent/pr-plus-reviewer/reviewer.patch from the CopilotLogs
artifact (or follow the report's Required submitted-PR change), push the update, and run
the review again.
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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! - On iOS and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. Fixes #37229 - [ ] Windows - [ ] Android - [x] iOS - [x] Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…after updating one (#37265) <!-- 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 and Mac Catalyst, when a Map has multiple MapElements and one Polyline's Geopath is updated, the other untouched Polylines silently lose their tracking, so when the map is later cleared, their MapElementId is left stale instead of being reset to null. ### Root Cause - MauiMKMapView.AddElements on iOS/Mac Catalyst unconditionally replaced its internal _trackedMapElements list on every call, so when a single MapElement was updated (e.g. via Geopath.Add(...) triggering UpdateMapElement), tracking for every other previously-added element was silently wiped, leaving them with a stale MapElementId after the map was later cleared. ### Description of Change - Modified AddElements in MauiMKMapView.cs to initialize _trackedMapElements only if it's null and to prevent adding duplicate elements to the tracking list. - Updated RemoveElements in MauiMKMapView.cs to ensure that elements are removed from _trackedMapElements and their MapElementId is cleared when they are removed from the map. ### Issues Fixed Fixes #37229 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e235775a-f0e3-445e-a2a1-ea88a676407a"> | <video src="https://github.com/user-attachments/assets/f2336093-24df-410a-aa29-f4f1c4cbced6"> | --------- Co-authored-by: Copilot <223556219+Copilot@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
Root Cause
Description of Change
Issues Fixed
Fixes #37229
Validated the behaviour in the following platforms
Output
iOS_Before.mov
iOS_After.mov