Repository navigation
refactor(monaco): move Monaco editor into sample, remove from core - #44
Merged
Merged
Conversation
Monaco was a WebView2-backed code editor baked into Reactor core, with hardcoded MonacoEditorElement / MountMonacoEditor / UpdateMonacoEditor cases in the reconciler and ~5 MB of vendored JS assets copied to every Reactor app's output. It's now a sample that demonstrates how to extend Reactor with a custom element type via Reconciler.RegisterType<TElement, TControl>(mount, update, unmount) — the same mechanism XamlInterop uses. Core changes: - Drop MonacoEditorElement, its DSL factory, modifier extensions, and reconciler Mount/Update/Pool entries from src/Reactor/. - Remove Monaco content-copy block from Reactor.csproj. Sample changes (samples/apps/monaco-editor): - Move the MonacoEditor UserControl, HTML shell, vendored JS, and MonacoJsonContext from src/Reactor/Monaco/ to samples/apps/monaco-editor/Monaco/. - Add MonacoEditorElement.cs — a Reactor Element record, a MonacoEditorRegistration.Register(Reconciler) helper, and a MonacoDsl factory. Program.Main calls Register once, and App.cs uses the DSL naturally like any built-in element. - Content-copy block (HTML + Assets) moves to the sample's csproj. Cleanup: - Delete Monaco self-test fixtures and registry entries. - Remove the webview2-test standalone sample (existed only as a Monaco UserControl smoke test). - Swap the Gallery's Monaco source-code viewer for a monospace TextBlock. - Strip Monaco from DSL reference skill, README feature table, pitch, packaging spec, gap-analysis spec, and reviewer manifest/README; update stale Reactor/Monaco/ paths in reviewer/reports/fix-list.md to samples/apps/monaco-editor/Monaco/. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Jun 25, 2026
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 25, 2026
… (DIFF skip-path) The Element-layer diff skip-path (PR #665) skips a cell's update only when its event-handler delegates are reference-stable across renders, so the cached UseState/UseReducer setters (#43/#44) and UseCallback's deps-unchanged return (#46) are load-bearing for DIFF correctness, not just allocation. Add a consolidated regression guard that drives a realistic combined hook set (UseState + UseReducer + Redux dispatch + UseCallback) through 50 steady-state renders — passing a fresh handler lambda each render, as a real component does — and asserts every returned delegate is the same instance captured on render 0. Includes a precision check that a changed callback dep DOES yield a new instance so the skip-path correctly re-applies the handler. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 26, 2026
…ire (Copilot review) #44 cached the redux-style UseReducer<TState,TAction> dispatch and moved the per-render reducer onto a shared `hook.Reducer` field that the cached dispatch reads back. On the threadSafe path a dispatch may run on a background thread, so the render-thread write and the dispatch-thread read of `hook.Reducer` were an unsynchronized cross-thread field access. References never tear, but on a weak memory model (ARM64, a shipping target) a cross-thread dispatch could observe a stale reducer, violating the "dispatch runs the latest reducer" contract. Fix: gate the field access to release/acquire on the threadSafe path - Volatile.Write when publishing the reducer at render time, Volatile.Read when the cached dispatch consumes it. The non-threadSafe path marshals dispatch onto the UI render thread, so it keeps a plain store/load and pays no barrier on the common hot path (zero new per-render overhead there). No observable semantic change; the dispatch still runs the latest reducer and stays reference-stable across renders. Added UseReducer_Redux_ThreadSafe_Cached_Dispatch_Runs_Latest_Reducer asserting the threadSafe arm runs the swapped reducer through the cached dispatch. Validated: core lib -c Release 0W/0E; tests/Reactor.Tests 9719 passed / 0 failed / 64 skipped (HookAllocationPerfTests 49). Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 26, 2026
Every component re-render re-runs every hook, so per-render hook allocations multiply by cells x hooks on data-grid workloads (StocksGrid). This eliminates the hot-path allocations in the hooks bookkeeping layer while preserving the rules of hooks (same call order/count/types every render) and observable semantics. RenderContext.cs: - #42 ValueHookState Lock is now lazy/nullable (allocated only when threadSafe:true); saves N rows x M hooks of unused Lock objects. - #43 UseState setter cached on the hook slot (built once, not a new display-class + Action<T> every render). - #44 UseReducer<T> updater and UseReducer<TState,TAction> dispatch delegates cached on the hook; dispatch reads the latest reducer from state (matches React semantics). - #45/#46/#48 UseEffect/UseMemo/UseCallback gain arity 1-3 deps overloads that compare deps without boxing and allocate the deps array only when deps actually change; params overloads kept as fallback and now assign Dependencies directly (no extra ToArray). UseCallback no longer allocates a ()=>callback wrapper. - #50 _hooks list pre-sized to new(8) to avoid mount realloc churn. - #51 ContextHooks uses a struct enumerator (no heap enumerator per render); still implements IEnumerable for existing .ToList() callers. - #52 UseCommand/UseCommand<T> use an inline memo slot instead of a per-render factory closure capturing 7 vars. - #53 UsePersisted setter cached on the hook slot. - #56 new internal UseDisposableEffect(IDisposable) mount-once helper with a stable teardown (no 2 lambdas per render). Hooks/: - #47 UseMemoCells/ByKey/ByIndex early full-reuse: return the prior children array and skip snapshot/dict allocation on a full cache hit. - #59 UseMemoCellsByKey computes each key once per item into a buffer instead of invoking the key selector twice. - #55 UseElementFocus caches the requestFocus closure and DispatcherQueue in refs instead of allocating + a COM call every render. - #57 UseResource uses an Interlocked counter id (not Guid.NewGuid) and skips the deps-hash rebuild when deps are unchanged; #56 disposes via UseDisposableEffect. - #56 UseMutation/UseInfiniteResource dispose via UseDisposableEffect. PanelAttachedHooks.cs: - #60 ApplyRelativePanelAttachedProps reuses a thread-static name-map dictionary (with a reentrancy guard for nested RelativePanels) instead of allocating one per reconcile. Tests: tests/Reactor.Tests/HookAllocationPerfTests.cs (25 tests) cover cached-delegate identity across renders, deps short-circuit (params + arity), threadSafe Lock still allocated + correct under concurrent writes (null when not requested), and UseMemoCells/ByKey/ByIndex cache-hit returning the same prior children array. The two committed skills/reactor.api.txt copies are regenerated to add the new public arity overloads (UseDisposableEffect stays internal). Closes #659 Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 26, 2026
… (DIFF skip-path) The Element-layer diff skip-path (PR #665) skips a cell's update only when its event-handler delegates are reference-stable across renders, so the cached UseState/UseReducer setters (#43/#44) and UseCallback's deps-unchanged return (#46) are load-bearing for DIFF correctness, not just allocation. Add a consolidated regression guard that drives a realistic combined hook set (UseState + UseReducer + Redux dispatch + UseCallback) through 50 steady-state renders — passing a fresh handler lambda each render, as a real component does — and asserts every returned delegate is the same instance captured on render 0. Includes a precision check that a changed callback dep DOES yield a new instance so the skip-path correctly re-applies the handler. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 26, 2026
…ire (Copilot review) #44 cached the redux-style UseReducer<TState,TAction> dispatch and moved the per-render reducer onto a shared `hook.Reducer` field that the cached dispatch reads back. On the threadSafe path a dispatch may run on a background thread, so the render-thread write and the dispatch-thread read of `hook.Reducer` were an unsynchronized cross-thread field access. References never tear, but on a weak memory model (ARM64, a shipping target) a cross-thread dispatch could observe a stale reducer, violating the "dispatch runs the latest reducer" contract. Fix: gate the field access to release/acquire on the threadSafe path - Volatile.Write when publishing the reducer at render time, Volatile.Read when the cached dispatch consumes it. The non-threadSafe path marshals dispatch onto the UI render thread, so it keeps a plain store/load and pays no barrier on the common hot path (zero new per-render overhead there). No observable semantic change; the dispatch still runs the latest reducer and stays reference-stable across renders. Added UseReducer_Redux_ThreadSafe_Cached_Dispatch_Runs_Latest_Reducer asserting the threadSafe arm runs the swapped reducer through the cached dispatch. Validated: core lib -c Release 0W/0E; tests/Reactor.Tests 9719 passed / 0 failed / 64 skipped (HookAllocationPerfTests 49). Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 29, 2026
…659) Cache ref-stable hook delegates on the (identity-stable) hook cell and add a full-reuse early-out to UseMemoCells, eliminating per-render allocations on the component render hot path. Measured via a headless GC-alloc harness (tests/Reactor.Tests/HookAllocBench.cs, env-gated REACTOR_ALLOC_BENCH): UseState x1/x4 96/384 -> 0 (#43 cached setter) UseReducer<T>/<S,A> 96/104 -> 0 (#44 cached updater/dispatch + latest-reducer cell) UsePersisted 96 -> 0 (#53 cached setter) UseCallback 152 -> 64 (#46 inlined, dropped () => callback wrapper) UseMemoCells cache-hit 632 -> 32 (#47 full-reuse early-out; residual is caller params array) Also: #42 lazy lock (no Lock unless threadSafe), #48 drop redundant deps .ToArray(), #50 _hooks initial capacity 8, #51 ContextHooks struct enumerator (no per-render heap iterator on the reconciler's per-component loop). Hook semantics preserved: call-order stable; cached delegates read live cell value and the current re-render callback; threadSafe path keeps its lock; two-arg reducer dispatch honors the latest render's reducer. UseMemoCells full cache-hit returns the prior children array (no rebuild). New regression tests in HookDelegateCachingTests. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 29, 2026
…659) Cache ref-stable hook delegates on the (identity-stable) hook cell and add a full-reuse early-out to UseMemoCells, eliminating per-render allocations on the component render hot path. Measured via a headless GC-alloc harness (tests/Reactor.Tests/HookAllocBench.cs, env-gated REACTOR_ALLOC_BENCH): UseState x1/x4 96/384 -> 0 (#43 cached setter) UseReducer<T>/<S,A> 96/104 -> 0 (#44 cached updater/dispatch + latest-reducer cell) UsePersisted 96 -> 0 (#53 cached setter) UseCallback 152 -> 64 (#46 inlined, dropped () => callback wrapper) UseMemoCells cache-hit 632 -> 32 (#47 full-reuse early-out; residual is caller params array) Also: #42 lazy lock (no Lock unless threadSafe), #48 drop redundant deps .ToArray(), #50 _hooks initial capacity 8, #51 ContextHooks struct enumerator (no per-render heap iterator on the reconciler's per-component loop). Hook semantics preserved: call-order stable; cached delegates read live cell value and the current re-render callback; threadSafe path keeps its lock; two-arg reducer dispatch honors the latest render's reducer. UseMemoCells full cache-hit returns the prior children array (no rebuild). New regression tests in HookDelegateCachingTests. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 30, 2026
…659) Cache ref-stable hook delegates on the (identity-stable) hook cell and add a full-reuse early-out to UseMemoCells, eliminating per-render allocations on the component render hot path. Measured via a headless GC-alloc harness (tests/Reactor.Tests/HookAllocBench.cs, env-gated REACTOR_ALLOC_BENCH): UseState x1/x4 96/384 -> 0 (#43 cached setter) UseReducer<T>/<S,A> 96/104 -> 0 (#44 cached updater/dispatch + latest-reducer cell) UsePersisted 96 -> 0 (#53 cached setter) UseCallback 152 -> 64 (#46 inlined, dropped () => callback wrapper) UseMemoCells cache-hit 632 -> 32 (#47 full-reuse early-out; residual is caller params array) Also: #42 lazy lock (no Lock unless threadSafe), #48 drop redundant deps .ToArray(), #50 _hooks initial capacity 8, #51 ContextHooks struct enumerator (no per-render heap iterator on the reconciler's per-component loop). Hook semantics preserved: call-order stable; cached delegates read live cell value and the current re-render callback; threadSafe path keeps its lock; two-arg reducer dispatch honors the latest render's reducer. UseMemoCells full cache-hit returns the prior children array (no rebuild). New regression tests in HookDelegateCachingTests. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
added a commit
that referenced
this pull request
Jun 30, 2026
…659) (#750) * perf(hooks): cache hook delegates + drop per-render hook allocations (#659) Cache ref-stable hook delegates on the (identity-stable) hook cell and add a full-reuse early-out to UseMemoCells, eliminating per-render allocations on the component render hot path. Measured via a headless GC-alloc harness (tests/Reactor.Tests/HookAllocBench.cs, env-gated REACTOR_ALLOC_BENCH): UseState x1/x4 96/384 -> 0 (#43 cached setter) UseReducer<T>/<S,A> 96/104 -> 0 (#44 cached updater/dispatch + latest-reducer cell) UsePersisted 96 -> 0 (#53 cached setter) UseCallback 152 -> 64 (#46 inlined, dropped () => callback wrapper) UseMemoCells cache-hit 632 -> 32 (#47 full-reuse early-out; residual is caller params array) Also: #42 lazy lock (no Lock unless threadSafe), #48 drop redundant deps .ToArray(), #50 _hooks initial capacity 8, #51 ContextHooks struct enumerator (no per-render heap iterator on the reconciler's per-component loop). Hook semantics preserved: call-order stable; cached delegates read live cell value and the current re-render callback; threadSafe path keeps its lock; two-arg reducer dispatch honors the latest render's reducer. UseMemoCells full cache-hit returns the prior children array (no rebuild). New regression tests in HookDelegateCachingTests. Co-authored-by: Copilot <[email protected]> * fix(hooks): harden UseMemoCells early-out + hook-cache per #659 review Addresses the dual-review findings on PR #750: #1 (BLOCKING, confirmed by RED test) theme propagation: the full-cache-hit early-out returned a reference-equal Children array, which makes the container ShallowEquals-skip its subtree (Element.cs ~622-699) so theme-sensitive descendants never re-apply their brush on a theme change. Gate the same-array early-out on the prior render having NO theme-sensitive cell (tracked as MemoCellsState.AnyThemeSensitive via ChildDiffHints.IsThemeSensitive). Theme- sensitive lists fall through to the fresh-array path (container recurses, theme re-applies); non-theme-sensitive lists keep the 632->32B win. New adjudicating tests in UseMemoCellsThemeSafetyTests. #2 (HIGH) predicate consistency: AllItemsEqual now uses object.Equals (exact match to the per-cell reuse loop) instead of EqualityComparer<T>.Default, so the early-out can't diverge for IEquatable<T> types. Dropped the UseMemoCellsByKey early-out entirely (its 'equal items imply identical keys' assumption + reused KeyToIndex was unsafe for impure key selectors); ByKey still reuses elements. #3 (MEDIUM) deps snapshot: restored deps.ToArray() on the deps-CHANGED store path (UseEffect/UseMemo/UseCallback) so an explicit mutable object[] a caller mutates can't corrupt the stored previous-deps. Runs only on deps-change, never the steady-state hot path, so the per-render win (call-site array) is unchanged. LOW delegate-kind guard: ValueHookState.SetterKind discriminates UseState vs UseReducer vs two-arg dispatch so an invalid same-slot swap producing a coincidentally same-typed delegate (Action<int>) re-materializes instead of reusing the wrong one. Measured (bytes/render): UseState/UseReducer/UsePersisted still 0; UseMemoCells cache-hit non-theme-sensitive ref still 32; theme-sensitive now 640 (correctly falls through). Full suite 9929 green; build 0/0. Co-authored-by: Copilot <[email protected]> * test(hooks): end-to-end theme-propagation guard for UseMemoCells early-out (#659) Adds UseMemoCells_BaseReThemeOnAncestorToggle selftest: a base UseMemoCells list of theme-sensitive cells under an ancestor RequestedTheme toggle, driven through a full value-equal cache hit, asserts the cell's themed Foreground re-resolves on the toggle (000000 Light -> FFFFFF Dark). Empirical result (verified by running this WITH and WITHOUT the AnyThemeSensitive gate): the themed Foreground re-resolves IDENTICALLY in both cases. A .Foreground(Theme.X) binding compiles to a {ThemeResource} Style setter that WinUI re-resolves natively on the cell's effective-theme change, independent of whether Reactor recurses or the container ShallowEquals-skips it — so the early-out's container skip does not strand a themed-Foreground descendant. The AnyThemeSensitive gate (5ead003) is retained as conservative insurance matching ChildDiffHints.IsThemeSensitive. (A ResourceOverride ThemeRef->concrete-brush does not re-resolve on this toggle, but it is wrong already at mount — a pre-existing GetEffectiveThemeName-during-reconcile issue unrelated to this PR — so it is not asserted here.) Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
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.
Summary
MonacoEditorElement, its DSL factory, modifier extensions, and hardcodedMount/Update/Poolentries from the reconciler; removes the ~5 MB vendored JS content-copy fromReactor.csproj.samples/apps/monaco-editor/as an example of extending Reactor with a custom element type via the existingReconciler.RegisterType<TElement, TControl>(mount, update, unmount)API (same patternXamlInterop.Registeruses).MonacoEditorElement.csin the sample — a ReactorElementrecord, aMonacoEditorRegistration.Register(Reconciler)helper, and aMonacoDsl.MonacoEditor(...)factory.Program.MaincallsRegisteronce, andApp.csuses the DSL naturally like any built-in element.Notes
MonacoFixtures.cs× 2) and their registry entries are removed.samples/apps/webview2-test/sample is removed — it existed only as a Monaco UserControl smoke test.TextBlock.README.mdanddocs/pitch/reactor-pitch.md; updateddocs/specs/002-winui3-gap-analysis.mdanddocs/specs/022-packaging-and-distribution.md; removed Monaco entries fromskills/dsl-reference.md,reviewer/manifest.json, andreviewer/README.md; updated staleReactor/Monaco/paths inreviewer/reports/fix-list.mdtosamples/apps/monaco-editor/Monaco/.Test plan
dotnet build Reactor.sln -c Debug— 0 errors, unrelated warnings onlydotnet test tests/Reactor.Tests— 3859 passed, 46 skippeddotnet test tests/Reactor.SelfTests— 423 passed (one flake onDataGrid_ScrollPerfRelative— timing-sensitive perf test unrelated to this change; passed on retry)dotnet test tests/Reactor.AppTests— 43 passed🤖 Generated with Claude Code