Repository navigation
fix(responsive): reconnect a re-parented host instead of tearing down - #1647
Conversation
- Debug.Assert required a null delegate Target, but Roslyn emits a non-capturing lambda as an instance method on a cached singleton, so the assert fired for every caller and failed every Debug runtime test reaching CreateWeakHandler - compare captured state instead: a closure's display class declares an instance field per captured variable, the cached singleton declares none
- OnHostUnloaded dropped the process-lifetime pins and the tracking entry with nothing re-arming Loaded, so an element that was unloaded and loaded again kept the value it last resolved - drop the pins as before, then re-arm Loaded: a host that is really gone still takes the extension with it, a re-parented one reconnects - runtime test re-parents a host while the size changes and asserts it re-resolves; it fails without this change with Expected:<Narrow> Actual:<Wide>
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://polite-field-01aa64f0f-1647.eastus2.azurestaticapps.net |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The bound-instance delegate case in WeakEventHelper remains unresolved.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Fixes ResponsiveExtension reconnection after host re-parenting and updates weak-handler validation with regression coverage.
Changes:
- Re-arms
Loadedafter host unload. - Updates delegate capture validation.
- Adds a re-parenting runtime test.
| File | Review summary |
|---|---|
src/Uno.Toolkit.UI/Markup/ResponsiveExtension.cs |
Reconnects unloaded hosts and resolves the current size. |
src/Uno.Toolkit.UI/Helpers/WeakEventHelper.cs |
Moderate issue (3 votes): bound instance delegates with zero fields may still be strongly retained. Nit (2 votes): clarify wording. |
src/Uno.Toolkit.RuntimeTests/Tests/ResponsiveExtensionsReconnectTests.cs |
Adds regression coverage for re-parented host behavior. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
…-free target - a zero-field check alone also accepted an instance method on a stateless object, whose target the wrapper still keeps alive - require the target's type to be compiler-generated as well, which the singleton Roslyn caches non-capturing lambdas on is and an ordinary class is not
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://polite-field-01aa64f0f-1647.eastus2.azurestaticapps.net |
|
@Mergifyio backport servicing/10.0 |
✅ Backports have been createdDetails
|
… (backport #1647) (#1664) Co-authored-by: Kunal22shah <[email protected]>


GitHub Issue (If applicable): #1646
PR Type
What is the current behavior?
Since #1608,
ResponsiveExtension.OnHostUnloadedtears the extension down for good: it drops the hard self-reference, removes the tracking entry and detaches from the staticWindowSizeChanged, and nothing re-armsLoaded. An element that is unloaded and loaded again therefore never reconnects. It keeps the value it last resolved and ignores every later size change.Any host that re-parents live content hits this: a
ContentControlswapping its content back, aFramere-showing a cached page, a designer or preview surface moving a previewed tree into and out of a canvas. The firstLoadedresolves against whatever size is in effect then, the move unloads and reloads the element, and from that point the value is frozen.It looks intermittent, because whether a given run is wrong depends only on whether the reload lands before or after the next size change.
A second, unrelated bug in the same area blocked the tests that would have caught this.
WeakEventHelper.AssertStaticassertsDelegate.Target is null, but Roslyn emits a non-capturing lambda as an instance method on a cached singleton, so the target is never null and the assert fires for every caller. Every Debug runtime test that reachesCreateWeakHandlerfails onmaintoday, includingResponsiveExtensionsLeakTests.What is the new behavior?
An element that is unloaded and loaded again resolves against the size in effect on its next
Loaded, exactly like a freshly created one.OnHostUnloadedstill drops both process-lifetime roots — theHardSelfReferencesentry and the staticWindowSizeChangedsubscription — so #1608's goal is unchanged: nothing static roots a dead extension, and an abandoned host graph (and its collectibleAssemblyLoadContext) is still collectible. It then re-armsLoadedthrough the existingConnectWhenLoadedpath. The re-armed subscription is held by the host, not by a static, so a host that really is gone still takes the extension with it.AssertStaticnow compares captured state instead of the target reference: a closure's display class declares one instance field per captured variable, while the singleton Roslyn caches a non-capturing lambda on declares none.PR Checklist
Other information
ResponsiveExtensionsReconnectTests.Reparented_Host_ResolvesForTheSizeInEffectOnReloadre-parents a host while the override size changes underneath it, then asserts the value follows. Run through the Material sample's desktop runtime-test host:ResponsiveExtensionsfilterOnHostUnloadedchangeThe one failure is the new test, and it fails with
Expected:<Narrow>. Actual:<Wide>.— the frozen value.ResponsiveExtensionsLeakTests.Connected_Extension_IsCollectible_WithoutResizeOrExplicitUninstallpasses in both runs, so the collectibility #1608 established is intact.Both runs need the
AssertStaticcommit; without it the same filter is 1 passed, 3 failed onmainfor a reason unrelated to either change. The two commits are separable, and the assert one stands on its own.One consequence worth a reviewer's eye: an unloaded extension now stays in the public
TrackedInstanceslist, where #1608 removed it, because it is dormant rather than dead.GetInstanceForcan therefore return an extension whose host is out of the tree. That is the intended meaning of "tracked fromInstalluntilUninstall", andUninstallstill removes it, but it is a semantic widening for anything that read a non-null result as "live".Reproduced and fixed against
10.0.0-dev.3;9.2.0-dev.20contains #1608 too and has the same defect.