Repository navigation
fix(responsive): reconnect a re-parented host instead of tearing down (backport #1647) - #1664
Merged
Merged
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 (cherry picked from commit ce1af4d)
- 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> (cherry picked from commit 55d7a90)
…-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 (cherry picked from commit 0efe6ae)
7 of 13 tasks
kazo0
approved these changes
Oct 8, 2026
Merged
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.This is an automatic backport of pull request #1647 done by [Mergify](https://mergify.com).