Repository navigation
Description
Split out of #985, which fixed the same class of bug for Padding, CornerRadius, BorderThickness, BorderBrush, Background and IsEnabled but deliberately scoped itself to the six properties the issue enumerated.
The leak
Reconciler.ApplyModifiers writes both content-alignment properties onto any Control receiver:
// src/Reactor/Core/Reconciler.cs:3775-3786
if (fe is WinUI.Control contentAlignmentControl)
{
// ... HorizontalContentAlignment / VerticalContentAlignment
}src/Reactor/Core/ElementPool.cs has zero occurrences of ContentAlignment. So the same mechanism #985 describes applies unchanged:
- On mount
oldM is null, soApplyModifiersruns no unset arm. - A pooled
Button/ScrollViewer/ any poolableControltherefore starts life carrying the local value its previous renter set. - A local value outranks every
Stylesetter in WinUI's dependency-property precedence order, so the new renter silently renders with the old control's content alignment and cannot be corrected by a style.
Why it wasn't fixed in #985
-
[Bug] ElementPool.CleanElement never releases Panel.Background, or any Control-level Padding/CornerRadius/BorderThickness/BorderBrush/Background/IsEnabled #985 enumerates its scope explicitly and says such adjacent finds should be "a separate, deliberate change that shouldn't ride along".
-
HorizontalContentAlignmentis currently the last ungatedREACTOR_MOD_002anchor in the analyzer test suite. Flipping it topoolReset: trueescalates it toREACTOR_POOL_001and destroys the premise of two tests intests/Reactor.Tests/AnalyzerTests/ModifierAvailableAnalyzerTests.cs:CodeFix_Chains_Across_Both_Rule_Ids_In_One_Body(~line 501) — pairs a POOL_001 subject with a MOD_002 subject precisely to prove the two-id code-fix path. Both sides become POOL_001.- the MOD_002 expectation at ~line 294.
A comment at
ModifierAvailableAnalyzerTests.cs:486-489documents this dependency. Whoever takes this needs to re-anchor those two tests on a property that stays MOD_002 (the font family/size/weight rows,TextWrappingandTextTrimmingare all still MOD_002, so the id is not orphaned) before flipping the table rows.
Suggested fix
Extend the if (fe is Control resetControl) arm that #985 added to CleanElement's FrameworkElement-common region (it is deliberately placed before the switch so the pool ⇄ analyzer consistency invariants can see it):
resetControl.ClearValue(Control.HorizontalContentAlignmentProperty);
resetControl.ClearValue(Control.VerticalContentAlignmentProperty);Then, in the same change:
- flip both rows to
poolReset: trueinsrc/Reactor.Analyzers/ModifierTable.cs, leaving thecontrolGateuntouched; - add the two pins to
CleanElementRequiredClearsintests/Reactor.Tests/AnalyzerTests/ModifierUnsetClearValueTests.csso an outright deletion fails positively rather than merely un-tripping an invariant; - re-anchor the two
ModifierAvailableAnalyzerTestscases above; - add a selftest fixture alongside
ModifierPoolClearValueControlPanelintests/Reactor.AppTests.Host/SelfTest/Fixtures/ModifierEventFixtures.cs, registered in bothAllFixturesand theCreate()switch.
Non-vacuity notes for the fixture
Copying the constraints that made the #985 fixtures meaningful:
- Keep a
ReferenceEquals(first, second)instance-reuse guard — without it every "cleared" assertion passes trivially on a freshly constructed control. - Assert
ReadLocalValue(dp) == DependencyProperty.UnsetValue, never "equals the default value". Assigning the default instead of clearing is exactly the [Bug] Unsetting a common modifier writes the DP default as a local value instead of ClearValue, permanently overriding Style-provided values #952 bug and would sail past a default-value oracle. - Keep a phase-1 "returned to the pool" check. Without it the reconciler may update in place, and the cleared assertions would be exercising
ApplyModifiers' unset arm rather thanCleanElement. - Carry the modifiers on a control whose descriptor does not write the property on every mount, or the oracle is vacuous. (
ScrollViewerwas used in [Bug] ElementPool.CleanElement never releases Panel.Background, or any Control-level Padding/CornerRadius/BorderThickness/BorderBrush/Background/IsEnabled #985 for exactly this reason —ButtonElement's descriptor writesIsEnabledunconditionally.)
Severity fallout
Same shape as #985: .Set(c => c.HorizontalContentAlignment = …) moves from REACTOR_MOD_002 (Info) to REACTOR_POOL_001 (Warning). The suggested fix and the shipped code fix are unchanged; consumers building with TreatWarningsAsErrors may need to convert those call sites. Worth a CHANGELOG note.
Activity
PaperHammer commentedon Nov 1, 2026
Hi, I’d be happy to work on this if no one is already handling it.
I reproduced the locally: CleanElement leaves the previous element’s local content-alignment values on the pooled control, and a new mount has no previous modifiers to trigger their removal.
Following your suggestion, I added both clears and the required-clear pins. Removing either clear makes the corresponding unit test fail. I also extended the existing ModifierPoolClearValueControlPanel fixture, retaining its pool-return and instance-reuse guards; it is already registered in both places.
I kept the analyzer severity unchanged based on the later clarification in #1195: cleanup on pool return alone does not justify promoting MOD_002 to POOL_001, since setters run again on the next mount. The existing analyzer test anchors therefore remain valid.
Below are screenshots of the key changes. Please let me know if this looks appropriate; I’d be happy to prepare a PR once validation is complete.
azchohfi commentedon Nov 7, 2026
Thanks! This still applies on
main:ElementPool.cshas noContentAlignmentclear yet. Please go ahead with the PR.You're right to keep
HorizontalContentAlignment/VerticalContentAlignmentatREACTOR_MOD_002. #1195 established that clearing a property on pool return doesn't by itself discard a.Setwrite, because the next mount re-runs setters. So the issue's steps about flippingpoolResetand re-anchoring the twoModifierAvailableAnalyzerTestscases no longer apply. Please put that reasoning in the PR description so reviewers don't raise it again.Putting the clears in the existing
if (fe is Control resetControl)arm looks right. For the PR:ModifierPoolClearValueControlPanelfixture, keep all the non-vacuity guards from the issue:ReferenceEqualsinstance reuseReadLocalValue(dp) == DependencyProperty.UnsetValue, not a default-value comparisonScrollViewerworks) whose descriptor doesn't write the property itself### FixedCHANGELOG entry citing [Bug] ElementPool.CleanElement never releases Control.HorizontalContentAlignment / VerticalContentAlignment #1013. No severity change means no analyzer note.PaperHammer commentedon Nov 7, 2026
Thank you for confirming the approach. I’ve added both clears, preserved the fixture’s non-vacuity guards, and kept the analyzer severity unchanged. The tests and changelog are updated, and the PR description explains the reasoning from #1195.