Skip to content

fix(reconciler): resolve ThemeRef overrides against a host-inherited RequestedTheme - #1417

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 7 commits into
microsoft:mainfrom
bkudiess:bkudiess/host-inherited-theme-resource-overrides
Oct 28, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 7 commits into
microsoft:mainfrom
bkudiess:bkudiess/host-inherited-theme-resource-overrides

Conversation

@bkudiess

@bkudiess Barbara Kudiess (bkudiess) commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ThemeRef-backed resource overrides now inherit a native ancestor's RequestedTheme across both ReactorHostControl and ReactorHost.ContentTarget, including custom error fallbacks and virtualized rows. Previously, controls mounted before parenting could receive app-theme brushes, and unchanged pooled subtrees could retain brushes from their previous theme.

Original repro: a Light app places a host under a native Dark ancestor. Cards using .Resources(r => r.Set("ButtonBackground", Theme.Ref("CardBackgroundFillColorDefaultBrush"))) receive light brushes on a dark page.

Both hosts provide a native theme anchor to shared reconciliation. The reconciler seeds normal and fallback root passes from that anchor, bypasses structural skips when the inherited theme changes, and records the theme only after successful reconciliation. Layout-time realization uses its container's theme for ItemsView/ItemsRepeater, typed and untyped ListView/GridView, and typed TreeView. Pooled rows track the applied theme and refresh stale descendants on reuse without consuming a pending host refresh. Generated guide snippets and the changelog are synchronized.

Linked issue / spec

Follow-up to #771 (ancestor-themed resource overrides inside the Reactor tree); extends the fix across native host boundaries. No separate issue. Merged main at 16062a12, preserving both changelog sections and the new container-lifecycle changes.

Test plan

  • Regression fixtures cover parented/detached hosts, identical nested trees, ancestor/Default transitions, both hosts' custom fallbacks, five additional list/tree realization shapes, and actual same-container recycle/reuse with fresh descendants.
  • Before the shared fixes, the new scenarios produced 8 failing assertions. Afterward they pass. Temporarily disabling the host and pooled-reconcile theme seeds produced 7 failures, including fallback brushes captured at mount and the new descendant inside a reused container; the mutations were restored before final validation.
  • Added Realization_DoesNotConsumeAnArmedHostRefresh to protect root-refresh ownership.
  • Head 146068f6: 40 checks passed, 2 intentional path-filter skips. CI run 40630366226 passed full Release build, units, selftests, MSIX, E2E, both AOT shards, trim proofs, Docs build and snippet analyzer gate. Coverage, packaging, bootstrap, Node projects and build metrics also passed. Audit ledger and Docs tier-drift were intentionally skipped.

Local ARM64 commands and results:

Command Result
dotnet build tests\Reactor.AppTests.Host --no-restore -c Release -p:Platform=ARM64 -p:SkipSignaturesGen=true -p:UseSharedCompilation=false -m:1 -nodereuse:false -v:minimal Passed, 0 warnings/errors.
dotnet test tests\Reactor.Tests -p:Platform=ARM64 -p:SkipSignaturesGen=true -p:UseSharedCompilation=false 15,123 passed, 64 skipped, 0 failed. Used a temporary short-path alias of this checkout, removed afterward. Existing PKCS advisory warnings remain.
dotnet run --project tests\Reactor.AppTests.Host --no-build -c Release -p:Platform=ARM64 -- --self-test --filter Item1Mount 8 fixtures passed.
dotnet run --project tests\Reactor.AppTests.Host --no-build -c Release -p:Platform=ARM64 -- --self-test --filter ItemsView Final grouped run: 12 fixtures passed.
dotnet run --project tests\Reactor.AppTests.Host --no-build -c Release -p:Platform=ARM64 -- --self-test --filter Lazy 13 fixtures passed.
dotnet run --project tests\Reactor.AppTests.Host --no-build -c Release -p:Platform=ARM64 -- --self-test --filter Theme 38 fixtures passed.
dotnet run --project tests\Reactor.AppTests.Host --no-build -c Release -p:Platform=ARM64 -- --self-test --filter EFR_ 22 fixtures passed.
dotnet run --project tests\Reactor.AppTests.Host --no-build -c Release -p:Platform=ARM64 -- --self-test --filter RenderErrorHandler 39 fixtures passed.
dotnet run --project tests\Reactor.AppTests.Host --no-build -c Release -p:Platform=ARM64 -- --self-test --filter TTV_ 17 fixtures passed.
dotnet run --project tests\Reactor.AppTests.Host --no-build -c Release -p:Platform=ARM64 -- --self-test --filter TemplatedList Final grouped run: 14 fixtures passed.
dotnet run --project tools\Reactor.DocPipeline --no-build -- compile --topic architecture-overview --no-screenshots --no-build Passed.
dotnet run --project tools\Reactor.DocPipeline --no-build -- compile --topic reconciliation --no-screenshots --no-build Passed.

Local caveats: the first grouped ItemsView run exceeded the parking fixture's 30-second budget, and the first TemplatedList run observed one unlinked row. Both failed fixtures passed in isolation and both complete grouped reruns passed; current-head CI's full suites also passed. No timeouts, assertions, warnings or CI gates were weakened. A stalled local build was stopped and retried without shared compilation. Full-solution Release was not repeated locally in this pass: the earlier local attempt encountered sample SDK extraction/MAX_PATH/apphost errors; the current-head full Release result is from CI. Packaged, E2E and AOT results are also CI runs, not local claims.

The original author reported verifying the initial fix in the downstream native dashboards app after a local v0.1.0-preview.12 port; that downstream check was not repeated for this revision.

Risk / breaking changes

No new public API. Explicit element theme modifiers retain precedence over inherited themes. Returning an ancestor to Default refreshes affected overrides. Host-theme changes and stale pooled reuse intentionally bypass structural skips; normal same-theme reuse retains the skip path. Native ancestor walks occur at root reconciliation and out-of-pass realization. No broader performance benchmark was run.

…RequestedTheme

A RequestedTheme set on a native ancestor of a ReactorHostControl (for example
the window root) was invisible to ThemeRef-backed resource overrides: at mount
the control is unparented, so resolution fell back to the app theme, and no
theme change follows to correct it. ItemsView rows realized during layout had
the same problem because they mount outside any root pass.

- Seed the reconciler's ambient theme from the host's inherited RequestedTheme
  for each root pass.
- Seed it from the repeater for layout-time row realization.
- Force a resource refresh when a host loads under a different inherited theme
  than it rendered with.

Adds Item1Mount_HostInheritedThemeResolvesAtMount (parented, detached-then-
parented, and ItemsView row arms).

Co-authored-by: Copilot App <[email protected]>
Refresh before arming each root pass when its inherited theme changed; cover detached parenting and live ancestor toggles for nested overrides and realized rows. Regenerate affected guide snippets.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Recycled rows can retain stale theme brushes after an ancestor theme change, and custom error fallbacks can mount with app-theme brushes instead of the inherited theme.

2 open issues
What changed in this PR

This PR extends ancestor-theme resolution across the native host boundary so ThemeRef resource overrides can follow a RequestedTheme set outside the Reactor tree.

Changes:

  • Seeds root reconciliation and layout-time row realization with the inherited native theme.
  • Requests a skip-bypassing resource refresh when the host’s inherited theme changes.
  • Adds live regression coverage and updates generated guide snippets and the changelog.
File Description
tests/​Reactor.AppTests.Host/​SelfTest/​SelfTestFixtureRegistry.cs Registers the host-inherited theme fixture.
tests/​Reactor.AppTests.Host/​SelfTest/​Fixtures/​ResourceOverrideMountThemeFixtures.cs Tests parented and detached hosts, realized rows, and theme transitions.
src/​Reactor/​Hosting/​ReactorHostControl.cs Seeds root-pass themes and requests refreshes on inherited-theme changes.
src/​Reactor/​Core/​Reconciler.cs Adds native ancestor lookup and scoped realization themes.
src/​Reactor/​Core/​ElementFactory.cs Applies inherited theme context during row realization.
docs/​guide/​reconciliation.md Updates the generated reconciliation snippet.
docs/​guide/​architecture-overview.md Updates generated reconciliation and row-realization snippets.
CHANGELOG.md Documents the host-inherited theme fix.

Review effort: Balanced

Comment thread src/Reactor/Core/ElementFactory.cs Resolved
Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
Preserve both changelog sections and integrate the latest conditional-slot and templated-container lifecycle changes.

Co-authored-by: Copilot App <[email protected]>
Resolve themes from a native host anchor for normal and fallback reconciliation. Refresh stale pooled row subtrees and cover every list/grid/tree realization path. Add red-to-green and mutation-checked regressions.

Co-authored-by: Copilot App <[email protected]>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All four findings are addressed in 146068f. CI is green, and the Item1Mount_ selftests pass locally (50/50). I also broke the ListView and pooled-row fixes on purpose, and each time the matching new check failed. One optional cleanup: the OnLoaded refresh is now redundant, because BeginRootPass already re-arms on HostThemeChanged.

Resolve CHANGELOG.md conflict: keep both Fixed entries.

Co-authored-by: Copilot App <[email protected]>
Resolve CHANGELOG.md conflict: keep both Fixed entries.

Co-authored-by: Copilot App <[email protected]>
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit db02633 into microsoft:main Oct 28, 2026
61 of 62 checks passed
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Oct 28, 2026
Resolve conflicts with #1417 (realization theme scope) and #1424 (keyed
item views): open the context RealizationFrame before EnterRealizationTheme
at every row-realization site, and read the frame's live theme with the same
InheritedRequestedTheme rule #1417 uses.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: d6963d93-8fc8-4956-8c83-88b394debeee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants