Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d0e7006
Add missing unset arms for modifiers that never released (#986)
azchohfi Jul 31, 2026
e640196
fix(reconciler): guard deferred LabeledBy against stale re-application
azchohfi Jul 31, 2026
953a462
Close the type-branch blind spot and address code-quality review
azchohfi Jul 31, 2026
ebe6499
test: address code-quality review round 2 on the #986 modifier gates
azchohfi Jul 31, 2026
68cedec
test: pin the deferred LabeledBy staleness-guard ordering
azchohfi Aug 1, 2026
aa27d69
fix: avoid allocating ReactorState on the sync LabeledBy path; docume…
azchohfi Aug 1, 2026
37e6585
test: fix a WaitFor short-circuit and split the release oracle from i…
azchohfi Aug 1, 2026
ec57b97
docs: correct the transform-family caveat; fix a stale remark on the …
azchohfi Aug 1, 2026
b4ce350
Merge remote-tracking branch 'origin/main' into azchohfi-modifier-uns…
azchohfi Aug 1, 2026
37d0d9e
Merge remote-tracking branch 'origin/main' into azchohfi-modifier-uns…
azchohfi Aug 1, 2026
47945d8
Merge remote-tracking branch 'origin/main' into azchohfi-modifier-uns…
adqwdqw Aug 1, 2026
e34ac94
test: locate the CleanElement FE-common boundary via Roslyn, not a te…
adqwdqw Aug 1, 2026
d5782e8
docs: name the four presence-shaped detectors the boundary does not r…
adqwdqw Aug 1, 2026
a653dbb
Calibrate the type-gated pair floor to the population it guards
adqwdqw Aug 1, 2026
fde7db5
test: give the type-gated parity test a clear-side non-vacuity floor
adqwdqw Aug 2, 2026
0ae38c5
docs: correct a false premise in the clear-side skip comment
adqwdqw Aug 2, 2026
8a008d6
test: catch a deleted unset arm the exclusion list hid
adqwdqw Aug 2, 2026
c493084
test: scope the unset-arm identifier names to both scanned methods
adqwdqw Aug 2, 2026
20aef88
test: hoist a per-method non-vacuity floor into ReadUnsetArms
adqwdqw Aug 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/_pipeline/templates/modifier-system.md.dt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ would pin it permanently rather than hand the property back to the
style. Render a themed `Button` with `.Padding(24)` and then without
`.Padding()` and you get the *themed* padding back, not `0`.

<!-- ai:caveat -->
The four transform modifiers are the current exception. `.Scale()`,
`.Rotation()`, `.Translation()` and `.CenterPoint()` have no unset arm yet,
so dropping one leaves the last value on the element. An un-animated write
goes straight to the XAML facade property, so a future fix can clear those
the usual way; but when an animation curve is in scope the value is driven
by a composition animation on the element's visual, which outranks the
property — releasing that case has to stop the animation as well, which is
why this is not simply a missing `ClearValue`. Until it is fixed, reset
these by writing the identity value explicitly — `.Scale(1f)`,
`.Rotation(0f)`, `.Translation(0f, 0f, 0f)` and `.CenterPoint(Vector3.Zero)`
— rather than by omitting the call. Note `.CenterPoint()` takes only a
`Vector3`, so it has no component-wise overload to spell the identity with.
<!-- /ai:caveat -->

Reference modifiers are the exception to "just write this value" in the
implementation, but not in the authoring model. `.Ref(cell)` binds the
current element into an `ElementRef` cell; reference-property modifiers
Expand Down
13 changes: 13 additions & 0 deletions docs/guide/modifier-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ would pin it permanently rather than hand the property back to the
style. Render a themed `Button` with `.Padding(24)` and then without
`.Padding()` and you get the *themed* padding back, not `0`.

> **Caveat:** The four transform modifiers are the current exception. `.Scale()`,
> `.Rotation()`, `.Translation()` and `.CenterPoint()` have no unset arm yet,
> so dropping one leaves the last value on the element. An un-animated write
> goes straight to the XAML facade property, so a future fix can clear those
> the usual way; but when an animation curve is in scope the value is driven
> by a composition animation on the element's visual, which outranks the
> property — releasing that case has to stop the animation as well, which is
> why this is not simply a missing `ClearValue`. Until it is fixed, reset
> these by writing the identity value explicitly — `.Scale(1f)`,
> `.Rotation(0f)`, `.Translation(0f, 0f, 0f)` and `.CenterPoint(Vector3.Zero)`
> — rather than by omitting the call. Note `.CenterPoint()` takes only a
> `Vector3`, so it has no component-wise overload to spell the identity with.

Reference modifiers are the exception to "just write this value" in the
implementation, but not in the authoring model. `.Ref(cell)` binds the
current element into an `ElementRef` cell; reference-property modifiers
Expand Down
128 changes: 113 additions & 15 deletions src/Reactor/Core/Reconciler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,18 @@ internal sealed class ReactorState
// (pool return / ClearCurrentEventHandlers / DetachReactorState) so a
// stale arm can't suppress the first real event of a later lifecycle.
public Func<object?, bool>? PendingEchoMatch;
// Issue #986 — the AutomationId a deferred LabeledBy resolution is still
// waiting to bind. ApplyAccessibilityModifiers can only resolve LabeledBy
// once the element is in the visual tree, so an unresolved request parks a
// Loaded handler. That handler outlives the render that created it, so it
// must not write blindly: by the time Loaded fires the modifier may have
// been dropped (reset arm) or retargeted at a different id, and a blind
// write would stomp the reset and re-pin the stale label forever. The
// handler therefore compares its captured id against this slot and no-ops
// on a mismatch. Cleared on resolve, on unset, and everywhere the echo
// state is cleared (pool return / ClearCurrentEventHandlers /
// DetachReactorState) so a stale arm can't fire into a later lifecycle.
public string? PendingLabeledBy;
// Spec 042 Phase 1 — keyed-list reconciliation state. Set when the
// host element is a templated items control (ListView/GridView/
// ItemsRepeater). The internal ObservableCollection<ReactorRow> in
Expand Down Expand Up @@ -714,6 +726,7 @@ internal static void ClearCurrentEventHandlers(FrameworkElement fe)
state.EchoSuppressCount = 0;
state.EchoSuppressScopeDepth = 0;
state.PendingEchoMatch = null;
state.PendingLabeledBy = null;
}
}

Expand Down Expand Up @@ -741,6 +754,7 @@ public static void DetachReactorState(FrameworkElement fe)
state.EchoSuppressCount = 0;
state.EchoSuppressScopeDepth = 0;
state.PendingEchoMatch = null;
state.PendingLabeledBy = null;
}

// ════════════════════════════════════════════════════════════════════
Expand Down Expand Up @@ -1022,6 +1036,7 @@ public void ReturnControl<T>(T control, PoolPolicy<T>? policy = null) where T :
rs.EchoSuppressCount = 0;
rs.EchoSuppressScopeDepth = 0;
rs.PendingEchoMatch = null;
rs.PendingLabeledBy = null;
rs.Element = null;
}
// Clear Reactor-set DataContext (FrameworkElement-only DP).
Expand Down Expand Up @@ -3804,6 +3819,14 @@ internal void ApplyModifiers(FrameworkElement fe, ElementModifiers? oldM, Elemen
// clearing the XAML DP does not cancel it — neither did the previous
// `fe.Opacity = 1.0`, so this is not a regression.
fe.ClearValue(UIElement.OpacityProperty);
// Transform family — Scale / Rotation / Translation / CenterPoint deliberately have
// NO unset arm yet (issue #1001). These are XAML facade properties whose live value
// lives on the element's composition visual: when a curve is ambient the set path
// above calls visual.StartAnimation, which outranks the DP and leaves no local value
// for ClearValue to release. Undoing that needs a StopAnimation companion and a
// selftest that exercises the animated path, so it is tracked separately rather than
// given the mechanical arm the plain-DP modifiers below get.
// ModifierUnsetClearValueTests.MissingUnsetArmExceptions records the same four names.
if (m.Scale.HasValue && m.Scale != oldM?.Scale)
AnimationHelper.SetOrAnimateVector3(fe, "Scale", m.Scale.Value);
if (m.Rotation.HasValue && m.Rotation != oldM?.Rotation)
Expand Down Expand Up @@ -3963,15 +3986,26 @@ internal void ApplyModifiers(FrameworkElement fe, ElementModifiers? oldM, Elemen
fe.ClearValue(WinUI.TitleBar.IsDragRegionProperty);

// ElementSoundMode (on Control, not FrameworkElement)
// The reset arm re-tests `fe is Control` under its own pattern variable rather than
// reusing `ctrl`: reaching the `else` only proves the whole set condition was false,
// which a non-Control satisfies while still having the modifier set. Without the
// re-test a Border that carries `.SoundMode(...)` would take the reset branch and
// clear a property it never had. Same shape as IsEnabled above (issue #986).
if (m.ElementSoundMode.HasValue && m.ElementSoundMode != oldM?.ElementSoundMode && fe is WinUI.Control ctrl)
ctrl.ElementSoundMode = m.ElementSoundMode.Value;
else if (!m.ElementSoundMode.HasValue && oldM?.ElementSoundMode.HasValue == true && fe is WinUI.Control ctrlSnd)
ctrlSnd.ClearValue(WinUI.Control.ElementSoundModeProperty);

// ── Accessibility — Tier 1 (inline properties) ──────────────
if (m.HeadingLevel.HasValue && m.HeadingLevel != oldM?.HeadingLevel)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetHeadingLevel(fe, m.HeadingLevel.Value);
else if (!m.HeadingLevel.HasValue && oldM?.HeadingLevel.HasValue == true)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.HeadingLevelProperty);

if (m.IsTabStop.HasValue && m.IsTabStop != oldM?.IsTabStop)
fe.IsTabStop = m.IsTabStop.Value;
else if (!m.IsTabStop.HasValue && oldM?.IsTabStop.HasValue == true)
fe.ClearValue(UIElement.IsTabStopProperty);

if (m.IsHitTestVisible.HasValue && m.IsHitTestVisible != oldM?.IsHitTestVisible)
fe.IsHitTestVisible = m.IsHitTestVisible.Value;
Expand All @@ -3980,6 +4014,8 @@ internal void ApplyModifiers(FrameworkElement fe, ElementModifiers? oldM, Elemen

if (m.TabIndex.HasValue && m.TabIndex != oldM?.TabIndex && fe is WinUI.Control tabIdxCtrl)
tabIdxCtrl.TabIndex = m.TabIndex.Value;
else if (!m.TabIndex.HasValue && oldM?.TabIndex.HasValue == true && fe is WinUI.Control tabIdxCtrl2)
tabIdxCtrl2.ClearValue(WinUI.Control.TabIndexProperty);

if (m.AccessKey is not null && m.AccessKey != oldM?.AccessKey)
fe.AccessKey = m.AccessKey;
Expand All @@ -3988,6 +4024,8 @@ internal void ApplyModifiers(FrameworkElement fe, ElementModifiers? oldM, Elemen

if (m.XYFocusKeyboardNavigation.HasValue && m.XYFocusKeyboardNavigation != oldM?.XYFocusKeyboardNavigation)
fe.XYFocusKeyboardNavigation = m.XYFocusKeyboardNavigation.Value;
else if (!m.XYFocusKeyboardNavigation.HasValue && oldM?.XYFocusKeyboardNavigation.HasValue == true)
fe.ClearValue(UIElement.XYFocusKeyboardNavigationProperty);

// ── Accessibility — Tier 2/3 (lazy sub-record) ─────────────
var a11y = m.Accessibility;
Expand Down Expand Up @@ -4223,69 +4261,129 @@ private static void AssertTypedRefMatch(Microsoft.UI.Reactor.Input.ElementRef r,
// Accessibility modifiers (Tier 2/3 sub-record)
// ════════════════════════════════════════════════════════════════

/// <summary>
/// Applies the Tier 2/3 accessibility sub-record.
/// </summary>
/// <remarks>
/// Called whenever <em>either</em> bag is non-null, which includes the case where the whole
/// sub-record was dropped this render (<paramref name="a"/> null, <paramref name="oldA"/>
/// not). That is why there is no <c>a is null</c> early return any more: it swallowed
/// exactly the transition it needed to handle, so dropping <c>.HelpText(...)</c> — or the
/// entire accessibility bag — left every automation property pinned on the control forever
/// (issue #986). Every property is therefore null-tolerant on <paramref name="a"/> — set
/// arms guard with <c>a is not null &amp;&amp; a.X…</c>, reset arms read <c>a?.X</c> — so the
/// dropped-bag case takes the same reset path as dropping one modifier from a surviving bag.
/// <para>
/// Resets go through <c>ClearValue</c>, never through writing the property's default: a
/// local value outranks every <c>Style</c> setter in WinUI's precedence order, so the
/// assignment would pin the default rather than hand the property back (issue #952).
/// </para>
/// </remarks>
private static void ApplyAccessibilityModifiers(FrameworkElement fe, AccessibilityModifiers? oldA, AccessibilityModifiers? a)
{
if (a is null) return;
if (a is null && oldA is null) return;

if (a.HelpText is not null && a.HelpText != oldA?.HelpText)
if (a is not null && a.HelpText is not null && a.HelpText != oldA?.HelpText)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetHelpText(fe, a.HelpText);
else if (a?.HelpText is null && oldA?.HelpText is not null)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.HelpTextProperty);

if (a.FullDescription is not null && a.FullDescription != oldA?.FullDescription)
if (a is not null && a.FullDescription is not null && a.FullDescription != oldA?.FullDescription)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetFullDescription(fe, a.FullDescription);
else if (a?.FullDescription is null && oldA?.FullDescription is not null)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.FullDescriptionProperty);

if (a.LandmarkType.HasValue && a.LandmarkType != oldA?.LandmarkType)
if (a is not null && a.LandmarkType.HasValue && a.LandmarkType != oldA?.LandmarkType)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLandmarkType(fe, a.LandmarkType.Value);
else if (a?.LandmarkType.HasValue != true && oldA?.LandmarkType.HasValue == true)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.LandmarkTypeProperty);

if (a.AccessibilityView.HasValue && a.AccessibilityView != oldA?.AccessibilityView)
if (a is not null && a.AccessibilityView.HasValue && a.AccessibilityView != oldA?.AccessibilityView)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetAccessibilityView(fe, a.AccessibilityView.Value);
else if (a?.AccessibilityView.HasValue != true && oldA?.AccessibilityView.HasValue == true)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.AccessibilityViewProperty);

if (a.IsRequiredForForm.HasValue && a.IsRequiredForForm != oldA?.IsRequiredForForm)
if (a is not null && a.IsRequiredForForm.HasValue && a.IsRequiredForForm != oldA?.IsRequiredForForm)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetIsRequiredForForm(fe, a.IsRequiredForForm.Value);
else if (a?.IsRequiredForForm.HasValue != true && oldA?.IsRequiredForForm.HasValue == true)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.IsRequiredForFormProperty);

if (a.LiveSetting.HasValue && a.LiveSetting != oldA?.LiveSetting)
if (a is not null && a.LiveSetting.HasValue && a.LiveSetting != oldA?.LiveSetting)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLiveSetting(fe, a.LiveSetting.Value);
else if (a?.LiveSetting.HasValue != true && oldA?.LiveSetting.HasValue == true)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.LiveSettingProperty);

if (a.PositionInSet.HasValue && a.PositionInSet != oldA?.PositionInSet)
if (a is not null && a.PositionInSet.HasValue && a.PositionInSet != oldA?.PositionInSet)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetPositionInSet(fe, a.PositionInSet.Value);
else if (a?.PositionInSet.HasValue != true && oldA?.PositionInSet.HasValue == true)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.PositionInSetProperty);

if (a.SizeOfSet.HasValue && a.SizeOfSet != oldA?.SizeOfSet)
if (a is not null && a.SizeOfSet.HasValue && a.SizeOfSet != oldA?.SizeOfSet)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetSizeOfSet(fe, a.SizeOfSet.Value);
else if (a?.SizeOfSet.HasValue != true && oldA?.SizeOfSet.HasValue == true)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.SizeOfSetProperty);

if (a.Level.HasValue && a.Level != oldA?.Level)
if (a is not null && a.Level.HasValue && a.Level != oldA?.Level)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLevel(fe, a.Level.Value);
else if (a?.Level.HasValue != true && oldA?.Level.HasValue == true)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.LevelProperty);

if (a.ItemStatus is not null && a.ItemStatus != oldA?.ItemStatus)
if (a is not null && a.ItemStatus is not null && a.ItemStatus != oldA?.ItemStatus)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetItemStatus(fe, a.ItemStatus);
else if (a?.ItemStatus is null && oldA?.ItemStatus is not null)
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.ItemStatusProperty);

if (a.TabFocusNavigation.HasValue && a.TabFocusNavigation != oldA?.TabFocusNavigation)
if (a is not null && a.TabFocusNavigation.HasValue && a.TabFocusNavigation != oldA?.TabFocusNavigation)
fe.TabFocusNavigation = a.TabFocusNavigation.Value;
else if (a?.TabFocusNavigation.HasValue != true && oldA?.TabFocusNavigation.HasValue == true)
fe.ClearValue(UIElement.TabFocusNavigationProperty);

// LabeledBy — resolve AutomationId string to the target element in the visual tree.
// During mount the element may not be in the visual tree yet (XamlRoot is null),
// so defer resolution to the Loaded event if needed.
if (a.LabeledBy is not null && a.LabeledBy != oldA?.LabeledBy)
if (a is not null && a.LabeledBy is not null && a.LabeledBy != oldA?.LabeledBy)
{
var target = FindByAutomationId(fe, a.LabeledBy);
if (target is not null)
{
// Resolved synchronously — retire any deferred request from an
// earlier render so its parked handler can't overwrite this one.
// TryGet, not GetOrCreate: with no state there is no parked handler
// and nothing to retire, and this is the common path — allocating and
// attaching a ReactorState here would cost one per element that ever
// resolves a LabeledBy synchronously.
if (TryGetReactorState(fe, out var resolvedState))
resolvedState.PendingLabeledBy = null;
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLabeledBy(fe, target);
}
else
{
// Element not yet in visual tree — defer until Loaded.
// Element not yet in visual tree — defer until Loaded. The handler
// outlives this render, so publish the request first and have the
// handler re-check it: if LabeledBy is dropped or retargeted before
// Loaded fires, the stale handler must no-op rather than stomp the
// reset arm below (issue #986).
var labelId = a.LabeledBy;
GetOrCreateReactorState(fe).PendingLabeledBy = labelId;
void OnLoaded(object sender, RoutedEventArgs _)
{
fe.Loaded -= OnLoaded;
if (!TryGetReactorState(fe, out var pending) || pending.PendingLabeledBy != labelId)
return;
pending.PendingLabeledBy = null;
var deferred = FindByAutomationId(fe, labelId);
if (deferred is not null)
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLabeledBy(fe, deferred);
}
fe.Loaded += OnLoaded;
}
}
else if (a.LabeledBy is null && oldA?.LabeledBy is not null)
else if (a?.LabeledBy is null && oldA?.LabeledBy is not null)
{
// Cancel a still-parked deferred resolution before clearing, or it would
// re-apply the dropped label the moment the element loads.
if (TryGetReactorState(fe, out var pendingState))
pendingState.PendingLabeledBy = null;
fe.ClearValue(Microsoft.UI.Xaml.Automation.AutomationProperties.LabeledByProperty);
}
}
Expand Down
Loading