Repository navigation
feat(hosting): opt-in ReactorApp.RegisterAllBuiltIns() for direct-record construction (#486) - #641
Merged
Alexandre Zollinger Chohfi (azchohfi) merged 8 commits intoJun 24, 2026
Conversation
…ecord construction (#486) Spec-048 §3.4 deleted the eager RegisterV1BuiltInHandlers so the trimmer can drop unused built-in controls. That broke the documented direct-record-initializer hot idiom (new TextBlockElement(...){ ... }) which bypasses the factory's lazy handler registration, causing a silent mount failure. Resolves issue #486 with option A: a public, opt-in ReactorApp.RegisterAllBuiltIns() that registers the whole built-in catalog. It is trim-safe (an ordinary method NativeAOT removes when uncalled, unlike a [ModuleInitializer] root), preserves the perf idiom, and keeps the trim story alive for apps that don't call it. - Add src/Reactor/Hosting/ReactorApp.BuiltIns.cs (public RegisterAllBuiltIns). - Test bootstrap now delegates to it (single catalog source of truth). - StressPerf.ReactorOptimized uses it as its one-line startup prelude. - Reconciler throw message now lists RegisterAllBuiltIns as a remediation path. - docs/guide advanced.md 'Hot loops': document the registration contract. - Record the A/B/C decision + rationale in spec 048 task §3.4. - Unit tests: throw on unregistered element; RegisterAllBuiltIns registers built-ins. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
requested a review
from Chris Anderson (codemonkeychris)
as a code owner
June 23, 2026 05:34
- M1 (test-coverage): replace 3-type sample with a data-driven catalog drift guard. ExpectedBuiltInCatalog mirrors all 95 RegisterAllBuiltIns entries; a count guard forces a deliberate test edit on any catalog change, and a [Theory] asserts every entry resolves a handler through some dispatch arm after RegisterAllBuiltIns() so a dropped/renamed registration fails loudly. - L1 (api): exception remediation message now cites the generated guide docs/guide/extending-reactor-controls.md instead of the .md.dt template. - M2 (docs): ran the ARM64-safe regen (UPDATE_API_INDEX=1); reactor.api.txt is byte-identical because ReactorApp is a static class, which the api index generator excludes by design (IsIndexablePublicType). No edit needed; Index_IsUpToDate confirms the index is not stale. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR resolves the spec-048 §3.4 regression where direct element-record construction (e.g., new TextBlockElement(...) { ... }) bypasses factory-triggered lazy handler registration and can fail to mount. It introduces an explicit opt-in bulk registration API and improves the failure mode and documentation around the registration contract.
Changes:
- Adds a public, opt-in
ReactorApp.RegisterAllBuiltIns()that bulk-registers the built-in handler catalog for apps using direct-record construction. - Improves
Reconciler.ThrowNoHandlerRegisteredto include the concrete element type and actionable remediation options (including the new bulk registrar). - Updates tests, stress-perf startup, and docs/templates to reflect the registration contract and new API.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/stress_perf/StressPerf.ReactorOptimized/Program.cs | Switches the perf harness startup prelude to call ReactorApp.RegisterAllBuiltIns() so direct-record hot loops mount reliably. |
| tests/Reactor.Tests/Spec048/UnregisteredHandlerAndRegisterAllBuiltInsTests.cs | Adds spec-048 tests for the actionable exception + idempotent built-in bulk registration coverage. |
| tests/_shared/BuiltInHandlerBootstrap.cs | Simplifies the test module initializer to delegate to ReactorApp.RegisterAllBuiltIns() as the single catalog source of truth. |
| src/Reactor/Hosting/ReactorApp.cs | Makes ReactorApp partial to allow splitting built-in catalog logic into a separate file. |
| src/Reactor/Hosting/ReactorApp.BuiltIns.cs | Introduces the public RegisterAllBuiltIns() implementation containing the built-in registration catalog. |
| src/Reactor/Core/Reconciler.Mount.cs | Expands the “no handler registered” exception message to include RegisterAllBuiltIns() and updates doc links. |
| docs/specs/tasks/048-control-registration-and-trimming-implementation.md | Records the option A decision and rationale for the long-term resolution of issue #486. |
| docs/guide/advanced.md | Documents the registration contract for direct-record construction and the available remediation paths. |
| docs/_pipeline/templates/advanced.md.dt | Updates the generated-doc template to keep the user guide in sync with the new registration guidance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…iation Copilot reviewer comments on PR #641: - Comments 1 & 2 (test overstated coverage): the old count check (ExpectedCatalogSize vs ExpectedBuiltInCatalog.Length) was self- referential — it only validated the test mirror's internal consistency, not drift against the production RegisterAllBuiltIns() catalog. Replaced it with a genuine production-drift guard: RegisterAllBuiltIns_Registers_Exactly_The_Mirror_Catalog now asks ControlRegistry which element types RegisterAllBuiltIns() actually registered (new internal RegisteredElementTypes / RegisteredBaseElementTypes snapshots), restricts to the Reactor assembly, and asserts that set equals the mirror — reporting the exact symmetric difference. Robust because component-style built-ins (DataGrid/PropertyGrid/MaskedTextBox/ VirtualList) render via Component and never register, so the registry holds only handler-backed built-ins. Validated under the full suite (9616 passed) so cross-test registration can't mask drift. - Comment 3 (exception not actionable for decorators): the remediation text only suggested ControlRegistry.Register<TElement,TControl>, which doesn't apply to decorator-backed elements. Fix (3) now also points at ControlRegistry.RegisterDecorator<TElement>(...) for elements that wrap/forward to a child rather than owning a leaf control. Co-authored-by: Copilot <[email protected]>
…ngelog Resolves the three meaningful findings from the latest pr-review pass on issue #486 / spec-048 section 3.4. M1 (correctness/test-coverage) -- make the catalog-drift guard sound. The guard previously read the live, process-wide ControlRegistry at test-run time, so a built-in dropped from RegisterAllBuiltIns() could be masked by an unrelated test having lazily registered the same built-in via its factory. The test bootstrap now snapshots exactly what RegisterAllBuiltIns() registered at module-init time -- before any test runs -- and the guard compares the mirror against that snapshot, so a dropped built-in can no longer be backfilled and hidden. L2 (api-ergonomics) -- the RegisterAllBuiltIns() XML remarks only cited ControlRegistry.Register<TElement,TControl>; it now also cites RegisterDecorator<TElement> for decorator-backed elements, matching the reconciler's exception text. L1 (docs) -- add a CHANGELOG Added entry for ReactorApp.RegisterAllBuiltIns() and the new reconciler throw. Verified: Spec048 99/99, full Reactor.Tests 9616 passed/0 failed/64 skipped, Reactor.AppTests.Host + StressPerf.ReactorOptimized build clean (0W/0E). Co-authored-by: Copilot <[email protected]>
Resolve CHANGELOG.md Unreleased/Added conflict by keeping both entries: the Command.DebounceMs (#136) entry from main and the RegisterAllBuiltIns (#486) entry from this branch. Reconciler.Mount.cs auto-merged (main's LayoutFootgunDetector hook and this branch's ThrowNoHandlerRegistered arm are in independent regions). Co-authored-by: Copilot <[email protected]>
…486) Add a reflection sweep that asserts every built-in element record carrying [GenerateReactorDescriptor] or [GenerateReactorWrapper] is registered by ReactorApp.RegisterAllBuiltIns(), checked against the module-init snapshot (masking-proof) with a base-chain walk mirroring ControlRegistry.ContainsForType. Closes the one blind spot the ExpectedBuiltInCatalog equality guard shares with the production catalog: a brand-new generated control given a Dsl factory but forgotten in BOTH RegisterAllBuiltIns() and the mirror passes the equality guard (both lists agree it does not exist), yet `new FooElement()` direct-record construction would throw at first mount. The exclusion allow-list (KnownGeneratorBackedNotInBulkCatalog) is empty -- every shipped generated built-in is in the catalog today -- so the guard adds no new drift surface, and a stale exclusion fails the guard so the list cannot rot. A >=50 vacuity floor guards against the attributes being renamed/moved. Sweeps both generator families: the first draft swept only the descriptor attribute and missed the [GenerateReactorWrapper] shapes (Rectangle, Ellipse); verified load-bearing by temporarily dropping EllipseElement from the catalog -- the new guard failed naming it while the mirror-equality guard stayed green. Co-authored-by: Copilot <[email protected]>
M1: skills/perf-tips.md §3 now states the registration prerequisite for the direct-record hot-loop idiom (RegisterAllBuiltIns / factory once / ControlRegistry.Register), so agent-kit guidance can't lead authors into the unregistered-handler throw. M2: add selftest fixture RegisterAllBuiltInsEnablesDirectRecordMount — positive end-to-end proof that after ReactorApp.RegisterAllBuiltIns() a directly-constructed TextBlockElement (descriptor-backed) and ButtonElement (decorator-backed) mount to real WinUI controls. The xunit drift guards only assert registry presence; this asserts the actual mount. L1: docs/guide/advanced.md + advanced.md.dt "Registration contract" now lists the decorator-backed path (ControlRegistry.RegisterDecorator<TElement>) alongside the control-backed Register<TElement,TControl>. L2: reconciler throw message says "control-backed element" (not "value control") and fully-qualifies ControlRegistry.RegisterDecorator. Co-authored-by: Copilot <[email protected]>
Address PR #641 review (discussion_r3469242786): the prelude comment said RegisterAllBuiltIns gives "every element record" a handler, which could imply custom elements are covered. Scope it to built-in element records and note that custom records still register via their own factory or ControlRegistry.Register. Comment-only change. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
deleted the
azchohfi-reconciler-throw-unregistered-handler
branch
June 24, 2026 18:22
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.
Closes #486.
Problem
Spec-048 §3.4 deleted the eager
Reconciler.RegisterV1BuiltInHandlersso the trimmer can drop unreferenced built-in controls. Handler registration is now co-located in factory method bodies (e.g.Factories.TextBlocktouches its handler registration on first invocation). But the documented direct-record perf idiom (new TextBlockElement(text){ FontSize=8, ... }— see StressPerf.ReactorOptimized / spec-034 §B / docs/guide/advanced.md "Hot loops") bypasses the factory, so the dispatcher found no handler and the element silently failed to mount.What this does
Clear failure mode (acceptance 1) — the reconciler already throws
InvalidOperationExceptioninstead of silently no-op-mounting when an element-record type has no registered handler. This PR expandsThrowNoHandlerRegistered's message to name the concrete type and point at all remediation paths, including the new bulk registrar.Long-term decision: Option A (acceptance 2) — adds a public, opt-in
ReactorApp.RegisterAllBuiltIns()that bulk-registers the full built-in control catalog. This:[ModuleInitializer](unconditional trimmer root) and the rejected static-cctor-on-record (couples element to handler + precise-cctor barrier on the hot path),Options B (drop §3.4 scope) and C (source-gen per-record initializer) were evaluated and rejected; rationale recorded in
docs/specs/tasks/048-control-registration-and-trimming-implementation.md§3.4.Docs (acceptance 3) —
docs/guide/advanced.md"Hot loops" (and its template) now state the registration contract: direct-record construction is allowed, but the caller must ensure the handler is registered before first mount (call the factory once, orRegisterAllBuiltIns()/ControlRegistry.Register).Supporting changes
ReactorAppis nowpartial; newReactorApp.BuiltIns.csholds the catalog.[ModuleInitializer]bootstrap (tests/_shared/BuiltInHandlerBootstrap.cs) now delegates toReactorApp.RegisterAllBuiltIns()— single source of truth.StressPerf.ReactorOptimizedstartup prelude now callsRegisterAllBuiltIns()so the direct-record idiom keeps working.Tests
tests/Reactor.Tests/Spec048/: reconciler throwsInvalidOperationExceptionwith an actionable message for an unregistered element-record type;EmptyElement/composition primitives do not throw;RegisterAllBuiltIns()registers representative built-ins and is idempotent.Co-authored-by: Copilot [email protected]