Repository navigation
[Testing] Revert "[Windows] ScrollView: Prevent automatic Entry focus (#37428)" - #39014
TamilarasanSF4853 wants to merge 1 commit into
Conversation
|
Hey there @@TamilarasanSF4853! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
|
/azp run |
|
Note 🔍
|
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 2 findings
See inline comments for details.
| control.IsTabStop = localValue; | ||
| else | ||
| control.ClearValue(Control.IsTabStopProperty); | ||
| control.IsTabStop = isTabStop; |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Windows Platform Specifics — UnfocusControl now restores IsTabStop by writing a local value (control.IsTabStop = isTabStop) instead of restoring binding/local-value ownership. Concrete failure: style-owned or binding-owned IsTabStop becomes locally overridden after unfocus, so later style/binding updates no longer flow (the scenario covered by #37428 regression tests).
| _tabStopGeneration++; | ||
| RestoreIsTabStop(platformView); | ||
| base.DisconnectHandler(platformView); | ||
| platformView.ViewChanged -= ViewChanged; |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Logic and Correctness — This revert removes the Loading/Loaded/Unloaded temporary-tab-stop lifecycle and leaves only ViewChanged wiring, which reintroduces the original startup-focus behavior from #31039 (first Entry inside ScrollView receives focus when window opens). The gate confirms the revert is only a diagnostic workaround for leak detection, not a production-safe fix.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@TamilarasanSF4853 — new AI review results are available based on commit
8bc3b70.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ✅ PASSED
Platform: WINDOWS · Base: inflight/candidate · Merge base: eaf170ab
✅ Fix verified — 1 test(s) reproduce the bug (FAIL without the fix → PASS with it). 1 test(s) pass in both states and are not bug-reproducing; under the "at least one test reproduces the bug and none regress" rule they don't block the gate.
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
📱 EntryTests Category=Entry |
❌ PASS — 1074s | ✅ PASS — 318s |
📱 ScrollViewTests Category=ScrollView |
✅ FAIL — 321s | ✅ PASS — 320s |
🔴 Without fix — 📱 EntryTests: PASS ❌ · 1074s
(no coded error found; showing last 1200 chars)
press the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
Platform\Windows\TabbedPage\TabbedPageStyle.xaml(13,13): XamlCompiler warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive with the respective binding data context and marking the type declaration with the 'WinRT.GeneratedBindableCustomProperty' attribute or the 'Microsoft.UI.Xaml.Data.Bindable' attribute. If you are unable to do either but can ensure the data type is attributed correctly, then you can also suppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
0 Error(s)
Time Elapsed 00:05:21.39
Passed: 13
Failed: 0
Skipped: 4
Total: 17
Tests completed successfully
🟢 With fix — 📱 EntryTests: PASS ✅ · 318s
(no coded error found; showing last 1200 chars)
press the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
Platform\Windows\TabbedPage\TabbedPageStyle.xaml(13,13): XamlCompiler warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive with the respective binding data context and marking the type declaration with the 'WinRT.GeneratedBindableCustomProperty' attribute or the 'Microsoft.UI.Xaml.Data.Bindable' attribute. If you are unable to do either but can ensure the data type is attributed correctly, then you can also suppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
0 Error(s)
Time Elapsed 00:05:04.10
Passed: 13
Failed: 0
Skipped: 4
Total: 17
Tests completed successfully
🔴 Without fix — 📱 ScrollViewTests: FAIL ✅ · 321s
(no coded error found; showing last 1200 chars)
the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
Platform\Windows\TabbedPage\TabbedPageStyle.xaml(13,13): XamlCompiler warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive with the respective binding data context and marking the type declaration with the 'WinRT.GeneratedBindableCustomProperty' attribute or the 'Microsoft.UI.Xaml.Data.Bindable' attribute. If you are unable to do either but can ensure the data type is attributed correctly, then you can also suppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
0 Error(s)
Time Elapsed 00:05:03.19
Passed: 10
Failed: 1
Skipped: 0
Total: 11
Tests completed with exit code: 1
🟢 With fix — 📱 ScrollViewTests: PASS ✅ · 320s
(no coded error found; showing last 1200 chars)
press the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
Platform\Windows\TabbedPage\TabbedPageStyle.xaml(13,13): XamlCompiler warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive with the respective binding data context and marking the type declaration with the 'WinRT.GeneratedBindableCustomProperty' attribute or the 'Microsoft.UI.Xaml.Data.Bindable' attribute. If you are unable to do either but can ensure the data type is attributed correctly, then you can also suppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
0 Error(s)
Time Elapsed 00:05:04.55
Passed: 11
Failed: 0
Skipped: 0
Total: 11
Tests completed successfully
⚠️ Failure Details
- ❌ EntryTests PASSED without fix (should fail) — tests don't catch the bug
📁 Fix files reverted (2 files)
src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cssrc/Core/src/Platform/Windows/ViewExtensions.cs
📋 Pre-Flight — Context & Validation
PR #39014 Pre-Flight
Context
- Title:
[Testing] Revert "[Windows] ScrollView: Prevent automatic Entry focus (#37428)" - State: Open draft; explicitly a diagnostic PR that must not be merged.
- Base / head:
inflight/candidateateaf170abddfd51a230f04b6a219911ae5ab0ba5f/candidate-failure-checkat8bc3b7001c17122b048c7eafdbb06a453f27b95c. - Purpose: Determine whether #37428 caused Windows
Controls.DeviceTestsfailures in candidate CI. - Gate: Already passed. Do not rerun gate verification and do not alter
gate/content.md.
Direct Diff Assessment
The PR is a one-commit revert of #37428. It removes four changes:
src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs- Removes
Loading,Loaded, andUnloadedsubscriptions. - Removes transient
ScrollViewer.IsTabStopstate/binding capture and queued restoration. - Removes generation/platform-view guards around queued callbacks.
- Removes
src/Core/src/Platform/Windows/ViewExtensions.cs- Reverts binding/local/style-aware
IsTabStoprestoration inUnfocusControlto a simple effective-value save/restore.
- Reverts binding/local/style-aware
src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Windows.cs- Removes the style-owned
IsTabStopregression test.
- Removes the style-owned
src/Controls/tests/DeviceTests/Elements/ScrollView/ScrollViewTests.Windows.cs- Deletes the Windows focus/lifecycle/ownership regression suite added by #37428.
The #37428 mechanism makes the native ScrollViewer a temporary tab stop during WinUI loading so initial focus does not move into the first child Entry, then restores dependency-property ownership after loading. Its queued dispatcher callbacks and lifecycle subscriptions are the key lifetime-sensitive area.
Reproduced Regression
The gate ran Windows Controls device-test categories against the broken baseline and PR state:
- Primary:
Category=ScrollView- Without the revert: 10 passed, 1 failed.
- With the revert: 11 passed, 0 failed.
- Exact failure:
ScrollViewTests.DoesNotLeak. WaitForGCreports live references toMicrosoft.Maui.Controls.ScrollView,Microsoft.Maui.Handlers.ScrollViewHandler, andMicrosoft.UI.Xaml.Controls.ScrollViewer.
- Mandatory regression:
Category=Entry- Passed in both states (13 passed, 4 skipped in the gate run).
This establishes the candidate objective: preserve #37428's Windows startup-focus behavior and dependency-property ownership semantics while removing the lifetime root exposed by DoesNotLeak. A full revert is not an acceptable production solution because it restores the original automatic-Entry-focus bug (#31039).
Bounded Validation
Run only these commands, in this order:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform windows -TestFilter "Category=ScrollView"
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform windows -TestFilter "Category=Entry"Do not run a full suite. Each candidate gets one implementation/test pass and at most one focused correction/retest.
Candidate Boundaries
- Platform: Windows.
- Production investigation starts in:
src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cssrc/Core/src/Platform/Windows/ViewExtensions.cs
- The baseline script's
RevertedFilesis the authoritative edit allow-list. - Candidate 2 must consume candidate 1's recorded result and use a mechanism-level alternative rather than reopening or rerunning it.
- Each invocation must run the
try-fixskill end to end, capture artifacts, perform its inline expert self-review, and restore only withEstablishBrokenBaseline.ps1 -Restore.
🔬 Code Review — Deep Analysis
Code Review — PR #39014 (RAW submitted revert)
Independent Assessment (code-first)
What this changes:
- Reverts #37428 in Windows ScrollView/Entry focus handling.
- Deletes temporary
IsTabStoplifecycle logic inScrollViewHandler.Windows.cs(Loading/Loaded/Unloadedsubscriptions, transient binding token, guarded restore paths). - Simplifies
ViewExtensions.UnfocusControlto effective-value save/restore (control.IsTabStop) and removes binding/local-value ownership restoration. - Deletes the Windows ScrollView regression suite and removes Entry Windows style-owned
IsTabStopregression test.
Inferred motivation:
- Diagnostic confirmation that #37428 introduced the Windows
ScrollViewTests.DoesNotLeakfailure seen in candidate CI.
Reconciliation with PR Narrative
Author claims: This is a testing-only revert to verify whether #37428 caused candidate failures; explicitly not for merge.
Agreement/disagreement:
- Agree: the revert aligns with diagnostic intent and gate evidence confirms category behavior changes.
- Disagree for production readiness: the revert is not production-safe because it removes #37428 bug-fix behavior and regression coverage.
Prior Review Reconciliation
| Prior ❌ Error Finding | Source | Status | Evidence |
|---|---|---|---|
| No prior ❌ Error findings found on review bodies or inline comments. | Anonymous PR reviews + inline comments endpoints | n/a | Both surfaces returned empty arrays in this environment. |
| No AI/human issue-comment error finding markers relevant to code correctness. | PR issue comments surface | n/a | Issue comments were policy/pipeline chatter and /azp run, no technical ❌ finding threads. |
Blast Radius Assessment
- Runs for all instances: Yes.
ScrollViewHandler.WindowsandViewExtensions.UnfocusControlare framework-level Windows paths used by all Windows ScrollView/focus flows. - Startup impact: Yes. Removed logic specifically changed load-time focus behavior.
- Static/shared state: No new static state added, but removal affects lifecycle/state ownership semantics globally.
CI / Gate Evidence
- Trusted gate artifact: PASSED for diagnostic goal.
Category=ScrollView: FAIL without revert → PASS with revert.Category=Entry: PASS both states.
- Interpretation: Confirms correlation with the leak scenario; does not establish production safety of full revert.
- Required-check surface:
gh pr checks --requiredunavailable here due unauthenticated GH CLI, so full required-check matrix was not directly queried in this run.
Findings
❌ Error — Full revert reintroduces previously fixed focus behavior and strips regression protection
src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs:51(and surrounding removed lifecycle block): reverting #37428 removes the temporary tab-stop load lifecycle (Loading/Loaded/Unloaded) that prevented auto-focus from moving into first Entry in ScrollView (#31039 scenario).src/Controls/tests/DeviceTests/Elements/ScrollView/ScrollViewTests.Windows.cs(deleted): deletes focused regression suite proving the behavior contract.- Why this matters: this PR proves a leak correlation but does so by removing established behavior and tests; merging would trade one regression for another.
⚠️ Warning — Dependency property ownership semantics regressed in unfocus path
src/Core/src/Platform/Windows/ViewExtensions.cs:405- Reverted implementation restores
IsTabStopvia local assignment (control.IsTabStop = isTabStop) rather than restoring original binding/local/style ownership. This can convert style/binding-owned state to local DP state after unfocus, preventing later style/binding updates from propagating.
Failure-Mode Probing
- What happens when style/binding owns
IsTabStop? AfterUnfocusControl, local value wins and ownership can be lost; later style flips may stop applying. - What happens during window load focus pass? Without transient tab-stop lifecycle, focus can re-enter content (first Entry) at startup; the removed tests were explicitly validating those load-order scenarios.
- Handler reconnect/disconnect safety? Revert removes generation/ownership restore guards around load/unload transitions, so previous #37428 lifecycle protections are gone.
External Output Contract
Not applicable (no external-output regex/classifier change in this diff).
Explicit assessment requested: full revert impact
Yes — this full revert removes #37428 behavior and its Windows regression tests. It is suitable only as a temporary diagnostic experiment and is not production-safe to merge as-is.
Verdict: NEEDS_CHANGES
Confidence: medium
Summary:
The raw PR succeeds as a diagnostic probe (gate proves ScrollView leak test behavior changes), but it is not an acceptable fix. It reintroduces the original Windows startup-focus bug path and regresses DP ownership semantics in unfocus while deleting the associated regression tests. Keep this PR as test-only evidence; do not merge the revert into production.
🛠️ Try-Fix — Analysis & Comparison
Try-Fix Aggregate
Candidate 1
- Approach: Weak-reference static dispatcher restore callback in
ScrollViewHandler.Windows.cs. - Mechanism difference from revert: Preserves #37428 startup focus prevention + ownership restoration; changes callback lifetime capture only.
- Result: Fail.
- Primary:
Category=ScrollViewfailed (DoesNotLeak; 11 run / 10 pass / 1 fail). - Regression:
Category=Entrypassed (57 run / 53 pass / 0 fail / 4 ignored). - Self-review: 0 findings (
reviewer-findings.json=[]). - Candidate 2 guidance: Avoid callback-capture-only hypotheses; investigate lifecycle/state ownership roots.
Candidate 1 Diff
diff --git a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
index 973b1eb000..fac77fcc65 100644
--- a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
+++ b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
@@ -132,15 +132,10 @@ namespace Microsoft.Maui.Handlers
void QueueTemporaryTabStopRestore(ScrollViewer scrollViewer, bool restoreWhenLoaded)
{
var generation = ++_tabStopGeneration;
- void RestoreIfCurrent()
- {
- if (generation == _tabStopGeneration &&
- ReferenceEquals(_tabStopPlatformView, scrollViewer) &&
- scrollViewer.IsLoaded == restoreWhenLoaded)
- {
- RestoreIsTabStop(scrollViewer);
- }
- }
+ var handlerReference = new WeakReference<ScrollViewHandler>(this);
+ var scrollViewerReference = new WeakReference<ScrollViewer>(scrollViewer);
+ void RestoreIfCurrent() =>
+ RestoreTemporaryTabStopIfCurrent(handlerReference, scrollViewerReference, generation, restoreWhenLoaded);
var queued = restoreWhenLoaded
? scrollViewer.DispatcherQueue?.TryEnqueue(RestoreIfCurrent)
@@ -154,6 +149,26 @@ namespace Microsoft.Maui.Handlers
}
}
+ static void RestoreTemporaryTabStopIfCurrent(
+ WeakReference<ScrollViewHandler> handlerReference,
+ WeakReference<ScrollViewer> scrollViewerReference,
+ int generation,
+ bool restoreWhenLoaded)
+ {
+ if (!handlerReference.TryGetTarget(out var handler) ||
+ !scrollViewerReference.TryGetTarget(out var scrollViewer))
+ {
+ return;
+ }
+
+ if (generation == handler._tabStopGeneration &&
+ ReferenceEquals(handler._tabStopPlatformView, scrollViewer) &&
+ scrollViewer.IsLoaded == restoreWhenLoaded)
+ {
+ handler.RestoreIsTabStop(scrollViewer);
+ }
+ }
+
void RestoreIsTabStop(ScrollViewer scrollViewer)
{
if (!_isTabStopTemporary)Candidate 2
- Approach: Break persistent native ownership of the handler by weak-routing all four native ScrollViewer events and the native content panel's layout owner.
- Result: Pass after one focused correction.
- Files changed:
src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs(+74/-9 relative to the established broken baseline).ViewExtensions.cswas intentionally unchanged from #37428's binding/local/style-aware baseline implementation. - Self-review: 0 findings (
reviewer-findings.json=[]).
Mechanism-Level Difference
The PR full revert deletes #37428's load-time focus prevention and dependency-property ownership restoration, reintroducing #31039. Candidate 1 only weakens queued dispatcher captures, but its callbacks drain and DoesNotLeak still retained the MAUI ScrollView, handler, and native ScrollViewer. Candidate 2 leaves the queued restoration algorithm and temporary binding token intact. It instead breaks persistent ownership edges: native events reference a proxy that holds the handler weakly, and the native ContentPanel references a weak layout proxy rather than the handler's ICrossPlatformLayout implementation. Thus startup focus behavior, reload handling, generation guards, and binding/local/style restoration remain unchanged while detached native objects cannot keep the handler alive.
Exact Test Results
- Initial primary pass:
- Command:
pwsh .github\skills\run-device-tests\scripts\Run-DeviceTests.ps1 -Project Controls -Platform windows -TestFilter "Category=ScrollView" - Failed: 11 selected, 10 passed, 1 failed.
- Failure:
ScrollViewTests.DoesNotLeak; the MAUIScrollView,ScrollViewHandler, and nativeScrollViewerall remained alive.
- Command:
- Single permitted focused correction and primary retest:
- Command:
pwsh .github\skills\run-device-tests\scripts\Run-DeviceTests.ps1 -Project Controls -Platform windows -TestFilter "Category=ScrollView" - Passed: 11 selected, 11 passed, 0 failed, 0 ignored.
- Command:
- Mandatory regression after the passing primary:
- Command:
pwsh .github\skills\run-device-tests\scripts\Run-DeviceTests.ps1 -Project Controls -Platform windows -TestFilter "Category=Entry" - Passed: 57 selected, 53 passed, 0 failed, 4 ignored.
- Command:
Inline Expert Self-Review
Final-diff review count: 0 findings. The final reviewer-findings.json is []; reviewer-findings.diff snapshots the reviewed candidate delta. Connect/disconnect symmetry, weak-reference lifetime behavior, reload guards, UI-thread assumptions, native default/DP ownership, fallback sizes, platform scope, API surface, and complexity were checked.
Failure Analysis and Focused Correction
The first implementation replaced the three #37428 lifecycle instance callbacks with static callbacks and weak-keyed state, yet the primary leak failed identically. That ruled out those three callback targets alone. The one allowed correction completed the ownership boundary by weak-routing ViewChanged as well and replacing the content panel's direct ICrossPlatformLayout handler reference with a weak proxy. The passing retest establishes the combined final ownership graph; the bounded run did not independently toggle those two corrected edges.
Complete Candidate Diff
diff --git a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
index 973b1eb000..457d10edd9 100644
--- a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
+++ b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
@@ -22,6 +22,7 @@ namespace Microsoft.Maui.Handlers
ScrollViewer? _tabStopPlatformView;
int _tabStopGeneration;
bool _isTabStopTemporary;
+ ScrollViewEventProxy? _eventProxy;
// Stores a scroll request that arrived before the content was laid out.
internal ScrollToRequest? PendingScrollToRequest { get; private set; }
@@ -44,10 +45,8 @@ namespace Microsoft.Maui.Handlers
protected override void ConnectHandler(ScrollViewer platformView)
{
base.ConnectHandler(platformView);
- platformView.Loading += OnPlatformViewLoading;
- platformView.Loaded += OnPlatformViewLoaded;
- platformView.Unloaded += OnPlatformViewUnloaded;
- platformView.ViewChanged += ViewChanged;
+ _eventProxy ??= new ScrollViewEventProxy(this);
+ _eventProxy.Connect(platformView);
_tabStopPlatformView = platformView;
}
@@ -59,10 +58,7 @@ namespace Microsoft.Maui.Handlers
// causing a WinUI COM exception "Element already has a parent" (Issue #35277).
// Cascading here ensures ToPlatform() creates a fresh native view with no parent.
VirtualView?.PresentedContent?.Handler?.DisconnectHandler();
- platformView.Loading -= OnPlatformViewLoading;
- platformView.Loaded -= OnPlatformViewLoaded;
- platformView.Unloaded -= OnPlatformViewUnloaded;
- platformView.ViewChanged -= ViewChanged;
+ _eventProxy?.Disconnect(platformView);
_tabStopPlatformView = null;
_tabStopGeneration++;
RestoreIsTabStop(platformView);
@@ -189,6 +185,57 @@ namespace Microsoft.Maui.Handlers
_isTabStopTemporary = false;
}
+ // Every native subscription must avoid retaining the handler, including ViewChanged.
+ sealed class ScrollViewEventProxy
+ {
+ readonly WeakReference<ScrollViewHandler> _handler;
+
+ public ScrollViewEventProxy(ScrollViewHandler handler) => _handler = new(handler);
+
+ public void Connect(ScrollViewer platformView)
+ {
+ platformView.Loading += OnLoading;
+ platformView.Loaded += OnLoaded;
+ platformView.Unloaded += OnUnloaded;
+ platformView.ViewChanged += OnViewChanged;
+ }
+
+ public void Disconnect(ScrollViewer platformView)
+ {
+ platformView.Loading -= OnLoading;
+ platformView.Loaded -= OnLoaded;
+ platformView.Unloaded -= OnUnloaded;
+ platformView.ViewChanged -= OnViewChanged;
+ }
+
+ void OnLoading(FrameworkElement sender, object args)
+ {
+ if (_handler.TryGetTarget(out var handler))
+ handler.OnPlatformViewLoading(sender, args);
+ }
+
+ void OnLoaded(object sender, RoutedEventArgs args)
+ {
+ if (_handler.TryGetTarget(out var handler))
+ handler.OnPlatformViewLoaded(sender, args);
+ }
+
+ void OnUnloaded(object sender, RoutedEventArgs args)
+ {
+ if (_handler.TryGetTarget(out var handler))
+ handler.OnPlatformViewUnloaded(sender, args);
+ }
+
+ void OnViewChanged(object? sender, ScrollViewerViewChangedEventArgs args)
+ {
+ if (_handler.TryGetTarget(out var handler) &&
+ ((IElementHandler)handler).PlatformView is ScrollViewer platformView &&
+ ReferenceEquals(platformView, sender) &&
+ ((IElementHandler)handler).VirtualView is not null)
+ handler.ViewChanged(sender, args);
+ }
+ }
+
void OnContentPanelSizeChanged(object sender, SizeChangedEventArgs e)
{
((FrameworkElement)sender).SizeChanged -= OnContentPanelSizeChanged;
@@ -353,7 +400,7 @@ namespace Microsoft.Maui.Handlers
var paddingShim = new ContentPanel()
{
- CrossPlatformLayout = crossPlatformLayout,
+ CrossPlatformLayout = new WeakCrossPlatformLayout(crossPlatformLayout),
Tag = ContentPanelTag
};
@@ -362,6 +409,24 @@ namespace Microsoft.Maui.Handlers
scrollViewer.Content = paddingShim;
}
+ // The native content panel must not keep its owning handler alive through layout callbacks.
+ sealed class WeakCrossPlatformLayout : ICrossPlatformLayout
+ {
+ readonly WeakReference<ICrossPlatformLayout> _layout;
+
+ public WeakCrossPlatformLayout(ICrossPlatformLayout layout) => _layout = new(layout);
+
+ public Size CrossPlatformMeasure(double widthConstraint, double heightConstraint) =>
+ _layout.TryGetTarget(out var layout)
+ ? layout.CrossPlatformMeasure(widthConstraint, heightConstraint)
+ : Size.Zero;
+
+ public Size CrossPlatformArrange(Rect bounds) =>
+ _layout.TryGetTarget(out var layout)
+ ? layout.CrossPlatformArrange(bounds)
+ : Size.Zero;
+ }
+
Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint)
{
var scrollView = VirtualView;📝 PR Finalize — Recommended Title & Description
Assessment: ✏️ Recommend updating — the current metadata captures the diagnostic intent but omits the reverted Windows code paths and deleted regression coverage.
Recommended title
[Windows] ScrollView: Revert automatic Entry focus prevention for testing
Recommended description
### Description of Change
On Windows, the `Controls.DeviceTests` suite is failing in candidate PR https://github.com/dotnet/maui/pull/38782 CI, although the failures cannot be reproduced locally. PR https://github.com/dotnet/maui/pull/37428 is suspected, so this testing-only PR fully reverts it to confirm whether its changes caused the failures.
The submitted revert:
- removes the `ScrollViewHandler` load-time temporary `IsTabStop` lifecycle
- restores the previous `ViewExtensions.UnfocusControl` `IsTabStop` handling
- removes the Windows Entry and ScrollView regression tests added by #37428
<img width="797" height="522" alt="image" src="https://github.com/user-attachments/assets/23dbe2e4-bbba-4c77-830e-70fe48a48b97" />
**Note: Do not merge this PR; it is for testing purposes only**
### Issues Fixed
Diagnostic only; this PR does not fix an issue.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer. The submitted revert is useful diagnostic evidence, but the expert review confirmed that it is not production-safe: it reintroduces the Windows startup-focus behavior fixed by #37428, replaces binding/local/style-aware IsTabStop restoration with a local-value write, and deletes the tests that protect those contracts. The winning candidate preserves those behaviors and fixes the demonstrated lifetime problem by weak-routing native events and the native content panel's layout owner.
Comparative Ranking
| Rank | Candidate | Required validation | Behavior and safety assessment |
|---|---|---|---|
| 1 | pr-plus-reviewer |
PASS — ScrollView 27/27; Entry 54 passed, 4 ignored, 0 failed | Restores all code and tests removed by the revert, resolves both expert findings, and breaks the persistent native ownership paths. Fresh validation ran from the exact required candidate sandbox. |
| 2 | try-fix-2 |
PASS — ScrollView 11/11; Entry 53 passed, 4 ignored, 0 failed | Mechanically equivalent production fix: weak-routes all four native events and the content panel's layout owner while preserving #37428. Ranked just below the winner because pr-plus-reviewer is the expert-feedback-integrated candidate validated afresh in the prescribed sandbox. |
| 3 | pr |
Gate PASS for its diagnostic objective — ScrollView 11/11; Entry 13 passed, 4 skipped | Fixes the leak only by fully reverting #37428. Expert review found two merge-blocking behavior regressions, and the PR intentionally says not to merge. |
| 4 | try-fix-1 |
FAIL — ScrollView 10/11 (DoesNotLeak failed); Entry 53 passed, 4 ignored |
Preserves #37428 and weakens queued dispatcher captures, but does not remove the actual persistent lifetime roots. It ranks below every candidate whose required ScrollView regression validation passed. |
Why pr-plus-reviewer Wins
The raw PR proves causality but trades the leak for known focus and dependency-property ownership regressions. try-fix-1 disproves the queued-callback-only hypothesis. Both try-fix-2 and pr-plus-reviewer address the actual native ownership graph and pass the required categories; pr-plus-reviewer is selected as the single winner because it explicitly incorporates the expert's two actionable findings into the submitted PR baseline and has fresh, path-verified validation.
Required PR Changes
Replace the submitted full revert with the pr-plus-reviewer patch recorded at pr-plus-reviewer/reviewer.patch. The production delta against the PR base is in pr-plus-reviewer/candidate.patch.
Validation Scope and Uncertainty
Only the required Windows ScrollView and Entry categories were run. The combined event-proxy and weak-layout fix passed, but the bounded evidence does not isolate the necessity of each ownership edge independently; no full suite was run by contract.
📱 UI Tests — ViewBaseTests
Detected UI test categories: ViewBaseTests
[!WARNING]
No UI test results were produced for the detected categories. The PR build itself was
fine — the deep UI stage was skipped or interrupted on infrastructure (the
merge-for-testing step, emulator/simulator boot, or an Appium hang), not by this PR's code.
This is usually transient; the review re-runs on new commits (a maintainer can also re-run it).
🧭 Next Steps — reviewer changes required
The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.
Why: pr-plus-reviewer preserves the Windows startup-focus and IsTabStop ownership behavior removed by the submitted revert while breaking the native ownership paths responsible for the leak. It passed both required targeted categories from the exact candidate sandbox, whereas the raw PR has expert-confirmed behavior regressions and try-fix-1 failed ScrollView validation.
Address the actionable findings in this review before merging.
|
Closed this PR as not needed |
On Windows, the Controls.DeviceTest test case is failing in the candidate PR #38782 CI. These failures cannot be reproduced locally. PR #37428 is suspected, so its changes were reverted to confirm the cause of the failures.

Note: Do not merge this PR; it is for testing purposes only