You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tag controls mounted through Reconciler.RegisterType - #1301
Controls mounted through the per-host Reconciler.RegisterType<TElement, TControl>(mount, update, unmount) were never given their element tag (ReactorAttached.StateProperty → ReactorState.Element). The V1 arm tags in V1HandlerAdapter, and the composition wrappers tag since #1147, but the registered-type arm just returned whatever the author's mount returned. Only XamlInterop tagged by hand. Every reader of the tag therefore skipped these controls:
The unmount callback.UnmountRecursive and UnmountAndCollect find the registration through the tag, so the callback never ran, keyed or not.
.Ref(...) cleanup.CleanupReferenceStateForUnmount clears the ref through the tag, so ElementRef.Current kept pointing at the removed control, which the pool may already have recycled.
Exit transitions.RemoveChildWithExitTransition reads .Transition(...) from the tag, so the control was removed without its exit animation.
Repro (on main)
The selftests in RegisterTypeElementTagFixtures.cs never tag by hand. With Reconciler.cs reverted to origin/main, 26 of their checks fail, plus the two tightened fixtures below. A sample:
not ok RegisterTypeTag_KeyedGrid_Grow_ContentMatchesGridCell - 10 of 20 children show another cell's content: child 3 '1,0@0' at (0,3); child 4 '1,1@0' at (0,4); child 5 '1,2@0' at (1,0); ...
not ok RegisterTypeTag_KeyedGrid_Reverse_ContentMatchesGridCell - 19 of 20 children show another cell's content: ...
not ok RegisterTypeTag_Unmount_UnkeyedRemoved_UnmountCallbackRanOnce - unmount callback saw: none; expected #0 exactly once
not ok RegisterTypeTag_Unmount_KeyedRemoved_UnmountCallbackRanOnce - unmount callback saw: none; expected #0 exactly once
not ok RegisterTypeTag_Unmount_RootReplaced_UnmountCallbackRanOnce - unmount callback saw: none; expected #0 exactly once
not ok RegisterTypeTag_Ref_ClearedOnUnmount_RefClearedOnUnmount - ref still points at a TextBlock showing ''
not ok RegisterTypeTag_ExitTransition_ReadFromTag_RemovalPlayedExitTransition - the control was removed without its exit transition
not ok RegisterTypeTag_TagOnlyWhereRead_Mount_Keyed_TaggedWithCurrentElement - tag is null
A (keyed misplacement) and B (unmount never runs) both reproduce. B fails for unkeyed and keyed elements, and through both teardown paths: removal from a panel (UnmountAndCollect), and replacement by another type or a root swap (UnmountRecursive). The '' in the ref failure is ElementPool.CleanElement clearing the TextBlock: the ref points at a control that is already back in the pool.
Two existing selftests had been written around this bug. This PR makes both assert:
NativeDocking_Reliability_FloatingWindowClosesOnHostUnmount reported ok Reliability_FloatOutlive_TrackerClearedByUnmount # SKIP Host swap did not drain the docking unmount lambda in the headless harness. The lambda never ran at all. It was not a harness quirk.
RBC_CustomTypeRegister had _ = unmountCount; // the variable may not increment — keep the test green and a H.Check(..., true).
Docking impact in a real app
DockingNativeInterop (RegisterType<DockManager, Border>) and the splitter/overlay registrations have unmount callbacks and never tag. I drove the Reactor IDE sample (samples/apps/reactor-ide, Debug x64, --devtools run) without the mouse: I floated the Output tool window through the devtools MCP docking.dock tool, then invoked View ▸ Reset Layout over UI Automation. Reset Layout remounts the dock host under a new key. The host registry comes from docking.list:
top-level windows after Reset Layout
DockHostRegistry after Reset Layout
main
Preview — IdeApp, Output
dh:1, dh:2, dh:3, dh:4 (nothing unregistered)
this PR
Preview — IdeApp, Output
dh:1, dh:2, dh:4 (dh:3, the host's last element, unregistered)
On main the docking unmount callback never runs. With this PR it runs, and it unregisters dh:3. The floating window still survives in the IDE, though, because of a separate docking bug that this fix exposes and does not fix: the callback cleans up only NativeHostState.LastElement. DockFloatingTracker, DockHostRegistry and DockChordBridge are keyed by DockManager element instance, and the IDE (like any app following the docs) builds a new DockManager every render, so a floating window opened under an earlier instance is never closed. A throwaway selftest, not committed, confirmed it. When the element instance is stable, FloatingWindowClosesOnHostUnmount now closes the window deterministically. The CHANGELOG entry says the docking cleanup is only partly restored.
Fix (all in Reconciler.cs)
TypeRegistration tags the control after mount and after update:
always when the registration has an unmount callback, because that lookup goes through the tag whatever the element carries;
on the control update returns when it replaces the control (the callback built that control, not mount), and on the patched control otherwise;
except when the control already carries the tag of an element of another type. The comparison is by exact runtime type, because registration is exact-type and a derived type can have its own registration. A registration can hand back the control the reconciler mounted for a child element (r.Mount(Button(...))); that element's click trampoline and its own unmount read the tag, so it keeps it. The RegisterType docs now say that mount/update should return a control the registration owns. This is the single-slot collision Flyout / MenuFlyout / CommandBarFlyout silently disable their target's own callbacks #942 tracks for decorators.
Coupled to making the tag and the unmount callback reachable:
An update callback that returns the control it was handed is treated as patched in place (null), as the V1 arm already does, including a second managed wrapper for the same native control. The child reconcilers read any non-null result as a replacement and UnmountChild the control they hold, which would have run unmount (for example editor.Dispose()) on a control that stays mounted. Native identity is established through the ReactorState on the native object, which every wrapper reads. When the result is a different wrapper, the handed-in control gets a state if it has none. That allocation lands on the control being replaced, so an untagged replacement stays untagged.
CleanupReferenceStateForUnmount clears the producer ref only while it still names the control being unmounted, compared by native identity. When update returns a replacement, ApplyModifiers points the ref at the replacement before the caller unmounts the old control. With the old control now tagged, the unconditional clear had nulled the ref. The same line also affected built-in type swaps sharing one ElementRef; a throwaway probe showed cond ? Border(...).Ref(r) : TextBlock(...).Ref(r) leaving r.Current == null after the swap without the guard.
Both registered-unmount arms guard against re-entry, keyed on the control's ReactorState. An unmount callback that tears its children down by calling UnmountChild on its own control now walks the children once. Previously it recursed until the host died with 0xC00000FD.
Contract notes, documented on RegisterType and in docs/guide/extending-reactor-controls.md (template edited, that topic recompiled):
unmount replaces the child walk. When a registration supplies unmount, the reconciler calls it instead of walking the control's children. That was already the coded behavior, and XamlInterop relied on it, but it only took effect for tagged controls. In-tree registrations are unaffected: the docking host reconciles its own content to null, and the rest are leaves.
Author code that reads the tag still tags. The reconciler tags only where it reads the tag itself. Author code that reads GetElementTag still tags the control.
TControl declared as UIElement. It is always a FrameworkElement at runtime: that's UIElement's only subclass in WinUI 3. A fixture covers it.
Replaced controls under a single-content parent.unmount runs when the reconciler unmounts the control. A control that update replaced inside a single-content parent such as Border is swapped out by ReconcileV1Child without it. That gap predates this PR, and the docs now say so.
Hot path:_typeRegistry is written only by the public RegisterType. Built-in controls dispatch through _v1Handlers / ControlRegistry and never reach this code. Per registered-type mount or update, the added cost is one attached-DP read, plus a ReactorState allocation only where the tag is read or the registration has unmount.
Out of scope: reference modifiers held on a legacy ModifiedElement wrapper aren't cleared at teardown. Every arm has this gap, built-ins included: a probe with a wrapped built-in TextBlock shows the same result on main and on this branch. Nothing in src/ constructs ModifiedElement, and a fix belongs in the legacy unwrap or the ref machinery.
Tests
RegisterTypeElementTagFixtures.cs has 15 selftest fixtures and 84 checks:
delegated controls: a Button's tag and click survive, and a separately registered derived type keeps its tag and gets its own unmount;
a tag matrix covering the allocation gate across all three update outcomes.
Two existing fixtures were tightened, as described above.
Mutation checks, all against this final fixture set. Each mutation was rebuilt (host Reactor.dll newer than the edit), run with --filter RegisterTypeTag, and restored to a clean git status:
Mutation
Failing checks
Whole fix reverted (Reconciler.cs = origin/main)
28 (26 new, plus CustomReg_UnmountCallbackRan and Reliability_FloatOutlive_TrackerClearedByUnmount)
No tag after mount
17
No always-tag for registrations with unmount
14
No extras arm (tag only for keys, refs, unmount)
3: the exit-transition fixture
Always allocate
6: every NoReactorState check
No tag refresh on update
6
Overwrite another element's tag
7: Button tag/click ×4, derived tag/unmount ×3
Assignability instead of exact type for the owner
3: derived tag ×2, derived unmount ran 0 times, base unmount 1 times
No same-control normalization
2: unmount callback ran for a control that is still mounted: #0
Replacement from update not tagged
2
Identity probe allocates on the result
1: …UpdateReturnsNew_NoReactorState
No reference fast path in the probe
1: …UpdateReturnsSame_NoReactorState
Unconditional ref clear on unmount
1: RefFollowsReplacement
No re-entrancy guard
host dies: Stack overflow (0xC00000FD) in UnmountRecursive → UnmountChild
10 / 2: the identity checks (SurvivorsKeptTheirControl, StillTheSameControl, …)
Validation
dotnet test tests/Reactor.Tests: 14365 total, 0 failed (64 skipped). Last run at 7eeb391; later commits change only test fixtures and docs.
dotnet test tests/Reactor.SelfTests (x64): 1697 total, 0 failed, 1 skipped (the SelfTestVerdict_OnlySkips_PositiveControl positive control). Last run at 5f24647; the final commit changes only docs.
dotnet build Reactor.slnx --no-restore -c Release -p:CI=true: 0 errors locally, and CI's Release Build solution job passes on the head.
CI on 0b8a172: 43 passed, 2 skipped by path filters, none failed, all on the first attempt. An earlier head hit the known 0xC000027B selftest-host crash once; see the comment below.
Copilot review: seven rounds. Every finding was fixed with a test, or answered with evidence where it's pre-existing and out of scope (the ModifiedElement refs). The round on 0b8a172 reported no findings and no inline comments.
The reconciler records each control's element on the control (the element
tag), and three paths read it back: the keyed-middle child reconcile finds a
surviving child by the key on its tag, the unmount path finds a registration's
unmount callback through it, and .Ref(...) cleanup clears the ref through it.
The registered-type arm left tagging to the registration's own callbacks,
which only XamlInterop did. So a keyed registered-type child that survived a
grow or a reorder was neither moved nor patched, and a Grid of them showed
stale content at other children's cells; the unmount callback never ran; and a
.Ref(...) kept pointing at the removed control.
TypeRegistration now tags the control after mount and update: through
SetElementTagIfNeeded, so an unkeyed, extras-free leaf still allocates no
ReactorState, and always when the registration has an unmount callback, since
that lookup goes through the tag whatever the element carries. An update
callback that returns the control it was handed now counts as patching it in
place; the child reconcilers read any non-null result as a replacement and
would otherwise run the now-reachable unmount callback on a live control.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Review follow-ups on the RegisterType tagging change.
Unmounting a replaced control cleared the element's .Ref(...) through the
old control's tag, but ApplyModifiers has already pointed that ref at the
replacement by then. With registered-type controls now tagged, an update
that returns a new control left the ref null while the replacement was
mounted. CleanupReferenceStateForUnmount now clears the ref only while it
still names the control being unmounted.
A registration may return the control the reconciler mounted for another
element, such as a Button from Reconciler.Mount. That control's tag belongs
to the ButtonElement, whose click trampoline reads it; overwriting it with
the registered element silenced the click. The tag is now left alone when it
names an element of another type.
The docs no longer claim the callbacks never need SetElementTag (the
reconciler tags only where it reads the tag itself) or that the reconciler
always unmounts a control that update replaced.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Artifact sizes for 0b8a172 vs the base branch (6454d55).
Packages (compressed .nupkg)
Artifact
base
PR
Δ
Microsoft.UI.Reactor.nupkg
1.75 MB
1.75 MB
+1.13 KB (+0.06%)
⚠️
Microsoft.UI.Reactor.Advanced.nupkg
491.7 KB
491.7 KB
+14 B (0.00%)
≈
Microsoft.UI.Reactor.Devtools.nupkg
284.0 KB
284.0 KB
+16 B (+0.01%)
≈
Assemblies in Microsoft.UI.Reactor
Artifact
base
PR
Δ
Reactor.Analyzers.dll
373.0 KB
373.0 KB
+0 B (0.00%)
≈
Reactor.dll
2.47 MB
2.48 MB
+1.00 KB (+0.04%)
≈
Reactor.Localization.Generator.dll
16.0 KB
16.0 KB
+0 B (0.00%)
≈
Reactor.Wrappers.Abstractions.dll
10.5 KB
10.5 KB
+0 B (0.00%)
≈
Reactor.Wrappers.Generator.dll
99.5 KB
99.5 KB
+0 B (0.00%)
≈
Assemblies in Microsoft.UI.Reactor.Advanced
Artifact
base
PR
Δ
Reactor.Advanced.dll
1023.5 KB
1023.5 KB
+0 B (0.00%)
≈
Assemblies in Microsoft.UI.Reactor.Devtools
Artifact
base
PR
Δ
Microsoft.UI.Reactor.Devtools.dll
784.5 KB
784.5 KB
+0 B (0.00%)
≈
✅ smaller / ⚠️ larger / ≈ within noise. Sizes come from a Release dotnet pack on the CI runner: packages are the compressed .nupkg download size, assemblies the uncompressed DLL inside it. workflow run.
Coverage for 0b8a172 vs the base branch (885a5d8) — unit + selftest merged.
Metric
base
PR
Δ
Line
86.10%
86.16%
+0.06 pp
≈
Branch
77.40% (966/1248)
77.32% (965/1248)
-0.08 pp
≈
No coverage change beyond the noise floor. ✅
✅ higher / ⚠️ lower / ≈ within noise. Δ is in percentage points; coverage is unit + selftest merged (Debug x64) on the CI runner. Cobertura reports attached to the workflow run as artifacts.
CI note: the one red check, Selftests (1/2), is the known selftest-host crash. It isn't this change.
Failed job: the Host died 168.7 s into its 900 s budget with exit 0xC000027B STATUS_STOWED_EXCEPTION and no # Total failures: trailer. The last TAP lines are the OptionalEchoStrandRegression_* checks. The reported fixture, OptionalTriStateCheckBox, is only the one that happened to be running (positional).
The same exit code reproduces on main without this PR: the diagnostic branch azchohfi-diag-echo-strand-crash (ca0de23, a workflow-only change on top of main) reports iteration 3: exit -1073741189 (0xC000027B) trailer=False in run 36763638187. That workflow was written for exactly this crash (the Coverage-lane 0xC000027B after OptionalEchoStrandRegression_ComboBox), and its candidate fix is e6eded0 ("Keep an AutoSuggestBox alive until its deferred TextChanged has fired").
main's own CI at 6454d55 also lost its selftest host mid-run (Selftests (2/2), 0xC0000005).
None of those fixtures mounts anything through RegisterType. In this PR's run, the shard-1 corpus passed in Coverage (selftest-1), AOT Selftests (1/2) and Packaged Selftests (MSIX) (1/2). Locally, two full Reactor.SelfTests runs (1686 and 1693 fixtures) passed.
I'm re-running the failed job once to get a clean signal. That rerun isn't evidence either way.
Same refactor as the keyed-wrapper fixture got in #1296, answering the same
code-quality finding. No behavior change.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…tity
Copilot review follow-ups.
An unmount callback that tears its children down by unmounting its own control
through the reconciler (UnmountChild on the control it was handed) re-entered
the registered-type unmount arm and called itself without end, now that the
control is tagged. A registration that returned the control of an element it
mounted with Reconciler.Mount could do the same. Both unmount arms now skip the
callback for a control whose callback is already running, so the re-entrant
call walks the control's children once.
The producer-ref guard compared the ref's control with the unmounting control
by managed reference. Two wrappers can front one native element, so identity
now falls back to the ReactorState on the native object.
The RegisterType docs state that mount and update should return a control the
registration owns: a control that another element already tagged keeps that
tag, the single-slot collision #942 tracks for decorators.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Qualify release note about unresolved floating-window cleanup
CHANGELOG.md:177
This implies the tag fix restores floating-window closure, but the PR description's real-app validation says the Output window still survives because cleanup only visits NativeHostState.LastElement; floatings tracked under earlier DockManager instances remain open. Qualify this entry so release notes do not claim the separate docking lifetime bug is fixed.
…entity
Copilot review follow-ups.
The re-entrancy guard for RegisterType unmount callbacks keyed controls by
managed wrapper, so a second wrapper for the same native control, handed to
UnmountChild from the callback, would have slipped past it. It is keyed by the
ReactorState on the native control now, read once for both the registration
lookup and the guard.
An update callback that returns another managed wrapper for the control it was
handed now also counts as patching it in place, through the same
IsSameNativeElement check the ref cleanup uses.
The changelog no longer implies the docking floating-window cleanup is fully
fixed: it runs now, but only for the host's latest DockManager element.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot review follow-up. RegisterType allows TControl to be declared as
UIElement while the tag lives on FrameworkElement. In WinUI 3 FrameworkElement
is UIElement's only subclass (Microsoft.WinUI.dll metadata), so every control a
registration returns is one: the RegisterType docs say so, and a selftest
registers TControl as UIElement and checks the control is tagged and its unmount
callback runs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… prior state
Copilot review follow-ups.
TagControl kept a foreign tag only when its element was not assignable to the
registration's TElement. Registration is by exact type, so a base registration
that hands back the control it mounted for a separately registered derived
type overwrote the derived tag, and the base unmount ran in place of the
derived one. The owner check now compares runtime types exactly.
The update normalization recognized a second managed wrapper for the handed-in
control only through an existing ReactorState, which an unkeyed registration
without unmount never allocates. When update returns a different wrapper, the
handed-in control now gets a state if it has none and the result is checked
for that same state; every wrapper for a native object reads the one attached
value. The allocation happens only on that path and lands on the control being
replaced, so an untagged replacement stays untagged.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The unconditional “runs when the control leaves the tree” promise is not true for update replacements installed through ReconcileV1Child: that helper returns the replacement without unmounting the previous control. Since this PR leaves that existing gap in place, qualify the statement so RegisterType authors are not led to rely on cleanup that may be skipped, then regenerate the guide.
Narrow lifecycle guarantee for replacement paths
src/Reactor/Core/Reconciler.cs:949
This states a stronger lifecycle guarantee than the implementation provides. ReconcileV1Child returns an update replacement at lines 2982-2983 without unmounting the old control, and several single-content callers install that replacement directly; a registered control can therefore leave the tree without this callback running. Narrow this to “when the reconciler unmounts the control” or document the replacement-path exception that this PR explicitly leaves unresolved.
Copilot review follow-up. The RegisterType docs and the guide said unmount runs
whenever the control leaves the tree. ReconcileV1Child, used by single-content
parents such as Border, installs a control that update replaced without
unmounting the old one, a gap this PR leaves as it found it. Both now say unmount
runs when the reconciler unmounts the control and name that exception.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A target-wrapping flyout whose Target changes element type unmounts the
old Target itself before it returns the new one
(OverlayLifecycle.UpdateFlyoutElement and its MenuFlyout and
CommandBarFlyout twins). ReconcileV1Child then unmounted it again, which
would run the old subtree's handler and registered unmount callbacks a
second time. ReconcileV1Child now watches whether its update unmounted
the control it was handed, and skips its own unmount if so. The watch is
saved and restored around each update, because slot updates nest.
The RegisterType fixtures now give the registration an unmount callback
and tag their controls themselves, as XamlInterop does, so the callback
is reachable before #1301. They assert exact callback counts. A new
fixture covers the flyout Target type change in a Border.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
#1302 also inserts at the top of [Unreleased] / Fixed, and #1301/#1305
insert before the "Apps that reference only Microsoft.UI.Reactor" entry;
placing this entry after that one keeps all four merges clean.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Bind devtools HTTP listeners without a probe-then-bind race
DevtoolsMcpServer and PreviewCaptureServer probed a free loopback port
(bind a TcpListener to port 0, read the port, release it) and bound
HttpListener to it later. Any other process could take the port in
between; with several selftest hosts on one machine the Devtools_*
fixtures failed with HttpListenerException (32). PreviewCaptureServer's
TASK-026 placeholder socket did not close the window: HTTP.sys refuses
a port that any other socket owns, so it had to be released before
Start anyway.
LoopbackHttpListener now binds with bind-and-retry: when an unpinned
bind fails because the port is taken (ERROR_SHARING_VIOLATION 32 or
ERROR_ALREADY_EXISTS 183), it probes a new port and binds again
(bounded). A pinned port is tried exactly once and fails with
LoopbackPortUnavailableException. Both servers use it, and Port is
updated before the endpoint is announced or any request is served.
mur devtools hands its auto-picked port to a child that binds it only
after dotnet run builds (and again after each reload rebuild, during
which spec 024 requires the port to stay unbound), so the child now
exits 43 when its --mcp-port is taken. The supervisor picks a new port
for an auto-picked one and fails clearly for one the user pinned.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Make a repeated devtools server Start a no-op
Start now binds a fresh listener, so a second (or concurrent) Start
would bind another port and leak the first listener; HttpListener.Start
was idempotent before. A started flag, claimed under the same lock as
the listener hand-off, keeps a repeated Start a no-op. Also relax the
retry tests' exact attempt counts: a second, natural collision is a
legitimate extra retry, not a failure.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Spec 024: state the unpinned bind's retry bound
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Keep the child's port-conflict message neutral; add changelog entry
Under mur devtools the child's --mcp-port may be one the supervisor
picked, so "omit it" was wrong advice there; the supervisor prints the
guidance. Record the fix under [Unreleased] / Fixed (spec 024 §7).
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Serialize devtools server Start with Dispose
The started flag was claimed before the bind finished, so a concurrent
Start returned as a no-op while the first could still retry or fail,
and Dispose could return while an in-flight Start still announced the
endpoint (banners, CAPTURE_PORT/TOKEN) for a listener it then closed.
One lifecycle lock now covers the whole HTTP start (bind, publish,
announce) and Dispose: a concurrent Start waits for the first one's
result, and once Dispose returns nothing is bound or announced. The
console writers involved take only their own locks, so there is no
lock-order inversion.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Address code-quality findings in the port-race change
- Dispose the probe TcpListener with `using` (TcpListener.Dispose stops it).
- ExitDevtoolsHost: try/finally instead of catch-all, so the exit always
happens and nothing is swallowed.
- Server Dispose: Close() alone (HttpListener.Dispose already runs Stop
then CleanupV2Config), catching only HttpListenerException.
- ConfigureTimeouts: catch HttpListenerException (HTTP.sys rejected a
timeout property) and PlatformNotSupportedException instead of all.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Hold the give-up test's ports in one disposable
PortThief can now hold several sockets, so the MaxAttempts test disposes
them with a using declaration instead of a manual finally loop.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Hold the lifecycle gate through Dispose; document exit 43 for agents
Dispose released the gate right after setting _disposed, so a second
concurrent Dispose could return while the first still had the port
bound (and, for MCP, the lockfile present). Both servers now hold a
System.Threading.Lock scope for the whole Dispose, so every caller
returns only after cleanup is done. The agent-facing devtools skills
(skills/devtools.md and the plugin copy) now describe the supervisor's
exit-43 handling: pinned ports fail, auto-picked ports are replaced.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Log listener close failures; fix the supervisor's exit-code summary
Dispose no longer swallows an HttpListenerException from Close silently;
it reports it on stderr like the existing listener-loop failure line.
The Supervise summary and `mur devtools --help` no longer say every
non-42 exit code propagates: 43 is handled first.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Keep exit 43 when the dispatcher can't take the shutdown
If TryEnqueue fails because the dispatcher is already shutting down,
exit directly so the supervisor still sees 43. Spec 024's general
"any other code exits" rule now names 43 as the exception.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Move the changelog entry off the Fixed section's first slot
#1302 also inserts at the top of [Unreleased] / Fixed, and #1301/#1305
insert before the "Apps that reference only Microsoft.UI.Reactor" entry;
placing this entry after that one keeps all four merges clean.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reconciler.ReconcileV1Child reconciles the one child of a Border, a named
slot, a tab's content, a generated element slot and a RichTextBlock inline
UI container. When the child's update returned a new control, it handed the
new control back to the caller and never unmounted the old one. The caller
only swaps the slot, so the old subtree's effect cleanups, .OnUnmount
actions, ValidationRule messages, refs and RegisterType unmount callbacks
outlived it. A panel's ChildReconciler and the component path already
unmount the old control.
Unmount it here too, unless the update returned the control it was handed
(compared by native identity, the rule #1301 uses), which means it patched
it in place. The old control is unmounted after the update has pointed a
shared ref at the new one; #1301's guard in CleanupReferenceStateForUnmount
keeps that ref.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A target-wrapping flyout whose Target changes element type unmounts the
old Target itself before it returns the new one
(OverlayLifecycle.UpdateFlyoutElement and its MenuFlyout and
CommandBarFlyout twins). ReconcileV1Child then unmounted it again, which
would run the old subtree's handler and registered unmount callbacks a
second time. ReconcileV1Child now watches whether its update unmounted
the control it was handed, and skips its own unmount if so. The watch is
saved and restored around each update, because slot updates nest.
The RegisterType fixtures now give the registration an unmount callback
and tag their controls themselves, as XamlInterop does, so the callback
is reachable before #1301. They assert exact callback counts. A new
fixture covers the flyout Target type change in a Border.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
#1301 added TypeRegistration.IsSameControl to tell an update that patched
its control in place from one that replaced it, comparing by native
identity. ReconcileV1Child needs the same decision and had its own copy.
Keep one, at class level beside IsSameNativeElement, with #1301's body:
it reuses the state it creates instead of reading it back.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
#1301 documented that a control update replaced inside a single-content
parent such as Border was swapped out without unmount. Every slot
ReconcileV1Child reconciles now unmounts it, so the RegisterType XML doc
and the extending-reactor-controls guide (template edited, that topic
recompiled) name only the slots a control fills by hand, which still
skip it: CommandBar content, Expander content and header template,
ContentDialog, Flyout and Popup content, .WithFlyout, .WithContextFlyout
and .WithToolTip(element) content, and realized item content in ListView,
GridView, TreeView<T> and templated FlipView. The changelog entry now
lists them too, says RegisterType unmount callbacks were skipped, and
drops the ref sentence, which #1301's entry already covers.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The RegisterType registration in SlotReplacementFixtures tagged its
controls by hand so its unmount callback was reachable before #1301.
#1301 makes the reconciler tag registered controls, so drop the hand
tagging and exercise that path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reconciler.ReconcileV1Child reconciles the one child of a Border, a named
slot, a tab's content, a generated element slot and a RichTextBlock inline
UI container. When the child's update returned a new control, it handed the
new control back to the caller and never unmounted the old one. The caller
only swaps the slot, so the old subtree's effect cleanups, .OnUnmount
actions, ValidationRule messages, refs and RegisterType unmount callbacks
outlived it. A panel's ChildReconciler and the component path already
unmount the old control.
Unmount it here too, unless the update returned the control it was handed
(compared by native identity, the rule #1301 uses), which means it patched
it in place. The old control is unmounted after the update has pointed a
shared ref at the new one; #1301's guard in CleanupReferenceStateForUnmount
keeps that ref.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A target-wrapping flyout whose Target changes element type unmounts the
old Target itself before it returns the new one
(OverlayLifecycle.UpdateFlyoutElement and its MenuFlyout and
CommandBarFlyout twins). ReconcileV1Child then unmounted it again, which
would run the old subtree's handler and registered unmount callbacks a
second time. ReconcileV1Child now watches whether its update unmounted
the control it was handed, and skips its own unmount if so. The watch is
saved and restored around each update, because slot updates nest.
The RegisterType fixtures now give the registration an unmount callback
and tag their controls themselves, as XamlInterop does, so the callback
is reachable before #1301. They assert exact callback counts. A new
fixture covers the flyout Target type change in a Border.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
#1301 added TypeRegistration.IsSameControl to tell an update that patched
its control in place from one that replaced it, comparing by native
identity. ReconcileV1Child needs the same decision and had its own copy.
Keep one, at class level beside IsSameNativeElement, with #1301's body:
it reuses the state it creates instead of reading it back.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
#1301 documented that a control update replaced inside a single-content
parent such as Border was swapped out without unmount. Every slot
ReconcileV1Child reconciles now unmounts it, so the RegisterType XML doc
and the extending-reactor-controls guide (template edited, that topic
recompiled) name only the slots a control fills by hand, which still
skip it: CommandBar content, Expander content and header template,
ContentDialog, Flyout and Popup content, .WithFlyout, .WithContextFlyout
and .WithToolTip(element) content, and realized item content in ListView,
GridView, TreeView<T> and templated FlipView. The changelog entry now
lists them too, says RegisterType unmount callbacks were skipped, and
drops the ref sentence, which #1301's entry already covers.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The RegisterType registration in SlotReplacementFixtures tagged its
controls by hand so its unmount callback was reachable before #1301.
#1301 makes the reconciler tag registered controls, so drop the hand
tagging and exercise that path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ag Reconciler.UpdateChild (#1307)
* Unmount the control an update replaced in a single-child slot
Reconciler.ReconcileV1Child reconciles the one child of a Border, a named
slot, a tab's content, a generated element slot and a RichTextBlock inline
UI container. When the child's update returned a new control, it handed the
new control back to the caller and never unmounted the old one. The caller
only swaps the slot, so the old subtree's effect cleanups, .OnUnmount
actions, ValidationRule messages, refs and RegisterType unmount callbacks
outlived it. A panel's ChildReconciler and the component path already
unmount the old control.
Unmount it here too, unless the update returned the control it was handed
(compared by native identity, the rule #1301 uses), which means it patched
it in place. The old control is unmounted after the update has pointed a
shared ref at the new one; #1301's guard in CleanupReferenceStateForUnmount
keeps that ref.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Note the single-child slot unmount fix in the changelog
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Reference PR #1307 in the changelog entry
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Don't unmount a slot child twice when its own update already did
A target-wrapping flyout whose Target changes element type unmounts the
old Target itself before it returns the new one
(OverlayLifecycle.UpdateFlyoutElement and its MenuFlyout and
CommandBarFlyout twins). ReconcileV1Child then unmounted it again, which
would run the old subtree's handler and registered unmount callbacks a
second time. ReconcileV1Child now watches whether its update unmounted
the control it was handed, and skips its own unmount if so. The watch is
saved and restored around each update, because slot updates nest.
The RegisterType fixtures now give the registration an unmount callback
and tag their controls themselves, as XamlInterop does, so the callback
is reachable before #1301. They assert exact callback counts. A new
fixture covers the flyout Target type change in a Border.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Route RegisterType's same-control check through Reconciler.IsSameControl
#1301 added TypeRegistration.IsSameControl to tell an update that patched
its control in place from one that replaced it, comparing by native
identity. ReconcileV1Child needs the same decision and had its own copy.
Keep one, at class level beside IsSameNativeElement, with #1301's body:
it reuses the state it creates instead of reading it back.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Narrow the replaced-control note to the slots that still skip unmount
#1301 documented that a control update replaced inside a single-content
parent such as Border was swapped out without unmount. Every slot
ReconcileV1Child reconciles now unmounts it, so the RegisterType XML doc
and the extending-reactor-controls guide (template edited, that topic
recompiled) name only the slots a control fills by hand, which still
skip it: CommandBar content, Expander content and header template,
ContentDialog, Flyout and Popup content, .WithFlyout, .WithContextFlyout
and .WithToolTip(element) content, and realized item content in ListView,
GridView, TreeView<T> and templated FlipView. The changelog entry now
lists them too, says RegisterType unmount callbacks were skipped, and
drops the ref sentence, which #1301's entry already covers.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Let the reconciler tag the slot fixtures' registered controls
The RegisterType registration in SlotReplacementFixtures tagged its
controls by hand so its unmount callback was reachable before #1301.
#1301 makes the reconciler tag registered controls, so drop the hand
tagging and exercise that path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Cover a slot update that nests a slot reconcile and unmounts its control
Copilot's review of #1307 asked for coverage of the watch ReconcileV1Child
saves and restores around each update. Two fixtures run a RegisterType
update that unmounts the control it was handed and returns a new one, and
also updates a Border it mounted through the reconciler, which reconciles
that Border's child through a nested ReconcileV1Child. One runs the nested
reconcile first, so the restore has to hand back the outer control; the
other unmounts first, so the restore has to keep the record that it was
unmounted. Both assert the registration's unmount callback runs once.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Track every active slot update, not just the innermost
Copilot's review of #1307 found that the slot-update watch only followed
the innermost ReconcileV1Child frame. When a handler inside a nested slot
update unmounted the control an outer slot was updating, the outer frame
never recorded it, and the outer slot unmounted that control again, so
its unmount callback ran twice. Keep a stack of the active frames,
allocation-free once grown, and mark every frame watching the control
being unmounted.
NestedHandlerUnmountsOuter reproduces the double unmount through a
registered child's update. FrameReusedAfterSelfUnmount checks that a
frame reused by a later sibling slot starts without the previous
update's record.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Update hosted children with Reconcile in ResizeGrip and the regedit sample
The data grid's ResizeGrip handler and the regedit sample's CursorBorder
registration updated their child with Reconciler.UpdateChild. That call
doesn't check that the new element can update the old control, and it
leaves a control it replaced mounted for the caller to unmount; neither
caller did. A child that changed element type threw, a replaced child's
effect cleanups and unmount callbacks never ran, and ResizeGrip dropped a
removed child from the panel without unmounting it. Neither path is hit
today (the data grid mounts its grip without a child, and the regedit
splitter's child is Empty()), but the sample is code people copy.
ResizeGrip now uses ctx.ReconcileChild and the sample r.Reconcile. Both
patch the child in place or unmount it and mount the new element, and
return the control to install. Two selftests take a hosted child through
a replacing update, an element-type change and removal: one through
ResizeGrip, one through a RegisterType host that reconciles its child the
way the guide will teach.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Point code that hosts a child at Reconcile, not UpdateChild
Reconciler.UpdateChild's summary called it the way registered types
reconcile their children, but it neither checks that the new element can
update the old control (a changed type throws InvalidCastException for a
built-in control) nor unmounts a control it replaces. Its XML doc now
says so and points to Reconcile. Reconcile, the public method that does
both, had no XML doc at all; it now describes what it returns and when
it unmounts.
The extending-controls guide (template edited, that topic recompiled)
shows a RegisterType host updating its child with Reconcile, as a
snippet from the compiled doc app, and says why UpdateChild is the wrong
call there.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Add REACTOR_LIFECYCLE_003 for Reconciler.UpdateChild, with a code fix
Reconciler.UpdateChild only works after the internal CanUpdate check, and
its caller has to unmount a control it replaces. Code built on Reactor
can't make the check, and the two call sites the repository had did
neither: a child that changed element type threw InvalidCastException,
and a replaced child's cleanups never ran. Reconcile takes the same
arguments and does both.
The analyzer flags a call to Reconciler.UpdateChild, binding to the
method symbol so a same-named method never trips it, and stays quiet in
the assembly that declares Reconciler, whose slot owners check CanUpdate
first. The code fix rewrites the common shape:
var x = r.UpdateChild(o, n, existing, rerender);
if (x is not null) slot = x;
into
var x = r.Reconcile(o, n, existing, rerender);
if (x is not null && !ReferenceEquals(x, existing)) slot = x;
and removes a manual UnmountChild(existing) from the body, since
Reconcile now does it. It is offered only where that provably keeps the
meaning: the result is read nowhere but that if, the existing control is
a plain local or parameter, the arguments are positional, and every
UnmountChild(existing) in the block is a statement of its own in the
body. It qualifies ReferenceEquals when a member hides it.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Cover the analyzer's type check and the code fix's remaining guards
The unrelated UpdateChild decoy was declared in the code under test, so
the declaring-assembly skip hid it and deleting the Reconciler type check
failed nothing. The decoys now live in the referenced stub, one per half
of the check. New tests also reach the field and property guard, which
the member-access test stopped short of, keep an UnmountChild of another
control or on another Reconciler, and decline a body that only unmounts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Document REACTOR_LIFECYCLE_003
Adds the rule to the analyzer table in the architecture guide (template
and the compiled topic) and to the build-and-check skill's cheat table,
and a CHANGELOG entry that also covers the two call sites moved to
Reconcile. The analyzer's description said a replaced child's refs never
"run"; they are never cleared.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Keep the UpdateChild fix from dropping comments and directives
Removing a manual UnmountChild(existing) took the trivia in and around
the statement with it: a comment on it was lost, and an #endif in its
leading trivia left the file with an unbalanced #if. The fix is now
offered only when that trivia is whitespace and line breaks.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Reconcile the nested slot in the fixtures, and compile the stub once
The nested-slot fixtures updated their inner Border with UpdateChild
and dropped the result. They now call Reconcile and install what it
returns when that differs, the pattern this PR teaches. A Border's
update patches it in place, so the fixtures run the same nested slot
update as before.
The analyzer tests' stub was cached with ??=, which two tests running
in parallel could both miss. It is a Lazy now.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Offer the UpdateChild fix on a conditional access, and say why slot frames match by reference
The analyzer reports r?.UpdateChild(...), but the fix only recognized a
plain member access. It now rewrites the conditional form the same way
and keeps the ?.: a null receiver yields null from either call.
NoteUnmountDuringSlotUpdate gets a comment on why it compares by
reference rather than IsSameControl.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Swap a replaced child with one collection write, and build the fix's condition as syntax
ResizeGrip and the regedit splitter removed and re-inserted their child
when Reconcile returned a different control. A swap is now one indexer
write, and adding or removing a child stays an Insert or a RemoveAt. The
hosted-child fixtures add a child back after removing it, so that
branch is covered too.
The code fix built its new condition by parsing an interpolated string.
It is now built with SyntaxFactory, and the text it produces is
unchanged. The analyzer tests' stub declares Reconciler's members with
Reactor's nullable signatures.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Filter the code fix's result reads and unmounts with Where
Two loops in the UpdateChild code fix skipped elements with an early
continue; they now filter with Where, as code quality suggested.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Swap a hosted child with RemoveAt and Insert again
The previous commit swapped ResizeGrip's and the regedit splitter's
child with the panel's indexer. PanelChildCollection.Replace and
CompositeLifecycle.UpdateCommandHost avoid that on purpose: WinUI's
Children[i] = x doesn't always fully disconnect the old element, which
then throws a COMException when it is reused from the pool. A swap is
RemoveAt and Insert again; adding and removing a child stay one write.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Don't unmount a flyout's old Target twice through Reconcile
A target-wrapping flyout whose Target changes element type unmounts the
old Target itself before it returns the new one. ReconcileImperative,
behind the public Reconcile, then unmounted it again, running its
registered unmount callbacks a second time. Reconcile is what this PR
now points code built on Reactor at, and component roots, ErrorBoundary
and the app root reach the same path.
ReconcileImperative now runs its update in the watch frame
ReconcileV1Child uses and skips its own unmount when the update already
did it. Panels still unmount such a Target twice through ChildReconciler.
The flyout fixture now takes its host as a parameter. A second variant
hosts the flyout in a RegisterType host that reconciles its child
through Reconcile.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Note the Reconcile flyout fix in the CHANGELOG
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Say in the guide that Reconcile also replaces a child its update rebuilt
The paragraph after the per-host-child-reconcile snippet said Reconcile
patches a child of the same type and key in place. An update of the
same type can build a new control too, as ValidationVisualizer and a
RegisterType update can, and Reconcile then unmounts the old control
and returns the new one. Template edited and only that topic compiled.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Offer the UpdateChild fix only where Reconcile's result can be installed as is
Two holes in the code fix, from review:
- A child that became Empty(): Reconcile unmounts the old control and
returns null, and the rewritten "x is not null && ..." skipped the
body, so the slot kept showing an unmounted control. The rewrite is now
"if (!ReferenceEquals(x, existing)) target = x;", which empties the slot
by assigning null, the idiom the guide teaches. So the fix is offered
only where the body, apart from manual unmounts, is that one assignment
to a target that can hold null, and the if has no else. The ?. form is
declined: with no null check, a null receiver would empty the slot.
- An UnmountChild(existing) through another Reconciler was removed too,
though Reconcile unmounts through the reconciler the call used. A manual
unmount is now removed only when it goes through the same local or
parameter, or the same handler context's Reconciler, and the fix
declines when the call's arguments write the reconciler or the existing
control, or when the result replaces the existing control's variable
before the unmount.
The test stub's handler context now matches Reactor's: a readonly ref
struct in Microsoft.UI.Reactor.Core.V1Protocol.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Describe the UpdateChild fix's new rewrite in the CHANGELOG and the skill
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Offer the UpdateChild fix only when it installs into the existing control's slot
The fix checked that the assignment's target can hold null, but not
that it is the slot the existing control came from. Reading slot A and
installing into slot B, an emptied child would make Reconcile unmount
A's control and the rewrite clear B.
The target now has to be the existing control's own variable, or the
place it was read from by "var existing = <slot>;" in the statement right
before the call. The two must be written with the same names and member
accesses, and the call must not reassign a local or parameter the slot
is reached through. Nullable code reading a nullable slot passes the
control as existing!, so the argument may carry a ! too.
Every code-fix test now reads the existing control that way, unless it
is about where the control comes from, so each is declined only for the
reason it names. The check that the target isn't reached through the
result is gone: the storage rule covers it.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Say the UpdateChild fix needs the existing control read from its slot
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Say UpdateChild's caller unmounts the replaced control before swapping it
The remarks told the caller to install the new control before unmounting
the old one. The framework does the reverse: ChildReconciler unmounts and
then replaces, and Reconcile unmounts before it returns. Unmounting reads
state from the control while it is still in the tree, such as a
connected-animation snapshot.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Resolve Reconciler.UpdateChild once per compilation in REACTOR_LIFECYCLE_003
The analyzer compared each candidate call's symbol by name, type and
namespace. It now resolves Reconciler.UpdateChild once per compilation,
registers no node action when Reactor isn't referenced or when the
compilation declares Reconciler itself, and compares the bound symbol
with the resolved one.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Assert that the resize grip hosts at most one child
The grip's Update reads its hosted child at index 0 and removes it with
RemoveAt(0), where the code before this PR cleared the panel. The two
agree while the grip holds nothing but that child, which Mount and Update
guarantee. The assertion documents that and catches a later change that
breaks it.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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
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.
Summary
Controls mounted through the per-host
Reconciler.RegisterType<TElement, TControl>(mount, update, unmount)were never given their element tag (ReactorAttached.StateProperty→ReactorState.Element). The V1 arm tags inV1HandlerAdapter, and the composition wrappers tag since #1147, but the registered-type arm just returned whatever the author'smountreturned. OnlyXamlInteroptagged by hand. Every reader of the tag therefore skipped these controls:ChildReconciler.ReconcileKeyedMiddlefinds a surviving keyed child by the key on its tag. An untagged survivor hitsif (cur < 0) continue;, so it is neither moved nor patched, and the positional attached-property pass then gives it another child'sGrid.Row/Grid.Column. Same mechanism as Per-element source mapping via Roslyn interceptors (spec 010) #1147 and Fix keyed Memo(key, …) children losing their place in keyed lists; lock in keyed wrapper reconcile #1296.unmountcallback.UnmountRecursiveandUnmountAndCollectfind the registration through the tag, so the callback never ran, keyed or not..Ref(...)cleanup.CleanupReferenceStateForUnmountclears the ref through the tag, soElementRef.Currentkept pointing at the removed control, which the pool may already have recycled.RemoveChildWithExitTransitionreads.Transition(...)from the tag, so the control was removed without its exit animation.Repro (on
main)The selftests in
RegisterTypeElementTagFixtures.csnever tag by hand. WithReconciler.csreverted toorigin/main, 26 of their checks fail, plus the two tightened fixtures below. A sample:A (keyed misplacement) and B (unmount never runs) both reproduce. B fails for unkeyed and keyed elements, and through both teardown paths: removal from a panel (
UnmountAndCollect), and replacement by another type or a root swap (UnmountRecursive). The''in the ref failure isElementPool.CleanElementclearing the TextBlock: the ref points at a control that is already back in the pool.Two existing selftests had been written around this bug. This PR makes both assert:
NativeDocking_Reliability_FloatingWindowClosesOnHostUnmountreportedok Reliability_FloatOutlive_TrackerClearedByUnmount # SKIP Host swap did not drain the docking unmount lambda in the headless harness. The lambda never ran at all. It was not a harness quirk.RBC_CustomTypeRegisterhad_ = unmountCount; // the variable may not increment — keep the test greenand aH.Check(..., true).Docking impact in a real app
DockingNativeInterop(RegisterType<DockManager, Border>) and the splitter/overlay registrations haveunmountcallbacks and never tag. I drove the Reactor IDE sample (samples/apps/reactor-ide, Debug x64,--devtools run) without the mouse: I floated the Output tool window through the devtools MCPdocking.docktool, then invoked View ▸ Reset Layout over UI Automation. Reset Layout remounts the dock host under a new key. The host registry comes fromdocking.list:DockHostRegistryafter Reset LayoutmainPreview — IdeApp,OutputPreview — IdeApp,OutputOn
mainthe docking unmount callback never runs. With this PR it runs, and it unregisters dh:3. The floating window still survives in the IDE, though, because of a separate docking bug that this fix exposes and does not fix: the callback cleans up onlyNativeHostState.LastElement.DockFloatingTracker,DockHostRegistryandDockChordBridgeare keyed byDockManagerelement instance, and the IDE (like any app following the docs) builds a newDockManagerevery render, so a floating window opened under an earlier instance is never closed. A throwaway selftest, not committed, confirmed it. When the element instance is stable,FloatingWindowClosesOnHostUnmountnow closes the window deterministically. The CHANGELOG entry says the docking cleanup is only partly restored.Fix (all in
Reconciler.cs)TypeRegistrationtags the control aftermountand afterupdate:SetElementTagIfNeeded/ the V1 adapter (keyed, callbacks, extras or reference modifiers), so an unkeyed, extras-free leaf still allocates noReactorState(perf(reconciler): gate V1 ReactorState tagging on HasCallbacks (spec 047 §4.4 follow-up) #468);unmountcallback, because that lookup goes through the tag whatever the element carries;updatereturns when it replaces the control (the callback built that control, notmount), and on the patched control otherwise;r.Mount(Button(...))); that element's click trampoline and its own unmount read the tag, so it keeps it. TheRegisterTypedocs now say thatmount/updateshould return a control the registration owns. This is the single-slot collision Flyout / MenuFlyout / CommandBarFlyout silently disable their target's own callbacks #942 tracks for decorators.Coupled to making the tag and the
unmountcallback reachable:updatecallback that returns the control it was handed is treated as patched in place (null), as the V1 arm already does, including a second managed wrapper for the same native control. The child reconcilers read any non-null result as a replacement andUnmountChildthe control they hold, which would have rununmount(for exampleeditor.Dispose()) on a control that stays mounted. Native identity is established through theReactorStateon the native object, which every wrapper reads. When the result is a different wrapper, the handed-in control gets a state if it has none. That allocation lands on the control being replaced, so an untagged replacement stays untagged.CleanupReferenceStateForUnmountclears the producer ref only while it still names the control being unmounted, compared by native identity. Whenupdatereturns a replacement,ApplyModifierspoints the ref at the replacement before the caller unmounts the old control. With the old control now tagged, the unconditional clear had nulled the ref. The same line also affected built-in type swaps sharing oneElementRef; a throwaway probe showedcond ? Border(...).Ref(r) : TextBlock(...).Ref(r)leavingr.Current == nullafter the swap without the guard.ReactorState. Anunmountcallback that tears its children down by callingUnmountChildon its own control now walks the children once. Previously it recursed until the host died with0xC00000FD.Contract notes, documented on
RegisterTypeand indocs/guide/extending-reactor-controls.md(template edited, that topic recompiled):unmountreplaces the child walk. When a registration suppliesunmount, the reconciler calls it instead of walking the control's children. That was already the coded behavior, andXamlInteroprelied on it, but it only took effect for tagged controls. In-tree registrations are unaffected: the docking host reconciles its own content to null, and the rest are leaves.GetElementTagstill tags the control.TControldeclared asUIElement. It is always aFrameworkElementat runtime: that'sUIElement's only subclass in WinUI 3. A fixture covers it.unmountruns when the reconciler unmounts the control. A control thatupdatereplaced inside a single-content parent such asBorderis swapped out byReconcileV1Childwithout it. That gap predates this PR, and the docs now say so.Hot path:
_typeRegistryis written only by the publicRegisterType. Built-in controls dispatch through_v1Handlers/ControlRegistryand never reach this code. Per registered-type mount or update, the added cost is one attached-DP read, plus aReactorStateallocation only where the tag is read or the registration hasunmount.Out of scope: reference modifiers held on a legacy
ModifiedElementwrapper aren't cleared at teardown. Every arm has this gap, built-ins included: a probe with a wrapped built-inTextBlockshows the same result onmainand on this branch. Nothing insrc/constructsModifiedElement, and a fix belongs in the legacy unwrap or the ref machinery.Tests
RegisterTypeElementTagFixtures.cshas 15 selftest fixtures and 84 checks:unmounton unkeyed removal, keyed removal, replacement by another type, and root replacement;unmountthat unmounts its own control;TControldeclared asUIElement;updatereturning the same control and returning a new one;.Ref(...)cleared on unmount, and a ref that follows a replacement;.Transition(...), tagged through the extras arm, whose removal plays the exit animation (oracle: compositor taint, which doesn't wait on the animation completing, Flaky:ExitTr_Removed+ 3 sibling exit-transition fixtures fail intermittently in the AOT Selftests leg (reproduces onmain) #1037);Button's tag and click survive, and a separately registered derived type keeps its tag and gets its ownunmount;updateoutcomes.Two existing fixtures were tightened, as described above.
Mutation checks, all against this final fixture set. Each mutation was rebuilt (host
Reactor.dllnewer than the edit), run with--filter RegisterTypeTag, and restored to a cleangit status:Reconciler.cs=origin/main)CustomReg_UnmountCallbackRanandReliability_FloatOutlive_TrackerClearedByUnmount)mountunmountunmount)NoReactorStatecheckupdateButtontag/click ×4, derived tag/unmount ×3derived unmount ran 0 times, base unmount 1 timesunmount callback ran for a control that is still mounted: #0updatenot tagged…UpdateReturnsNew_NoReactorState…UpdateReturnsSame_NoReactorStateRefFollowsReplacementStack overflow(0xC00000FD) inUnmountRecursive → UnmountChildupdatealways remounts / keyed survivors remountedSurvivorsKeptTheirControl,StillTheSameControl, …)Validation
dotnet test tests/Reactor.Tests: 14365 total, 0 failed (64 skipped). Last run at 7eeb391; later commits change only test fixtures and docs.dotnet test tests/Reactor.SelfTests(x64): 1697 total, 0 failed, 1 skipped (theSelfTestVerdict_OnlySkips_PositiveControlpositive control). Last run at 5f24647; the final commit changes only docs.dotnet build Reactor.slnx --no-restore -c Release -p:CI=true: 0 errors locally, and CI's ReleaseBuild solutionjob passes on the head.0xC000027Bselftest-host crash once; see the comment below.ModifiedElementrefs). The round on 0b8a172 reported no findings and no inline comments.git merge-treewas clean against each and against both together before they merged. The branch is now rebased ontomain(6454d55), which contains them, and their fixtures pass on it. This PR doesn't touchReconciler.Mount.cs.