Skip to content

ThemeResource resolution returns Light-theme values after switching to Dark in 6.6 (regression from element-level theming) #23177

Closed

Description

@agneszitte

Bug Report

Summary

After upgrading from Uno.WinUI 6.5.x to 6.6.x, ThemeResource lookups return Light-theme values even after the application theme has been explicitly set to Dark. This is a regression introduced by the element-level theming and lazy theme resource evaluation features in 6.6.

Regression Introduced By

Both are present on release/stable/6.6.

Reproduction Evidence

Failing build: uno.csharpmarkup build 210415 — PR unoplatform/uno.csharpmarkup#879 (bumps Uno.WinUI from 6.5.153 → 6.6.5).

7 Failing Tests (all ThemeResourceTests, WASM)

Test Expected (Dark) Actual (Light)
When_ColorResource_Dark #4C33FF #30E7E8
When_StaticColorResource_Dark #4C33FF #30E7E8
When_BrushResource_Dark #4C33FF #30E7E8
When_StaticBrushResource_Dark #4C33FF #30E7E8
When_ThicknessResource_Dark 4,4,4,4 2,2,2,2
When_StaticThicknessResource_Dark 4,4,4,4 2,2,2,2
When_CornerRadiusResource_Dark 8,8,8,8 4,4,4,4

All tests follow the same pattern:

  1. Set Application.Current.RequestedTheme = ApplicationTheme.Dark (via Uno.Extensions ThemeService.SetThemeAsync)
  2. Resolve a ThemeResource
  3. Assert it returns the Dark dictionary value

Light tests pass. Only Dark tests fail, always returning the Light-theme value.

Root Cause Analysis

The behavioral change

In 6.5.x:

internal static ResourceKey GetActiveTheme() => Themes.Active;

In 6.6.x (post PR #22803):

internal static ResourceKey GetActiveTheme() => Themes.RequestedThemeForSubTree;

Where RequestedThemeForSubTree uses a static Stack<ResourceKey>:

public static ResourceKey RequestedThemeForSubTree =>
    _requestedThemeForSubTree.Count > 0 ? _requestedThemeForSubTree.Peek() : Active;

The mechanism

  1. ThemeService.SetThemeAsync(Dark) correctly sets Themes.Active = "Dark" via Application.RequestedThemeForResources → ResourceDictionary.SetActiveTheme()
  2. NotifyThemeChangedCore does push/pop correctly in try/finally during the theme walk
  3. ThemeResourceReference.RefreshValue() (from PR feat: Lazy theme resource evaluation #22887) calls dict.TryGetValue() which internally uses GetActiveTheme() → RequestedThemeForSubTree

Likely failure scenario

When the stack is empty, RequestedThemeForSubTree falls back to Active — so in theory it should work. However:

  • The NotifyThemeChangedCore code has a fallback: Application.Current?.ActualElementTheme ?? ElementTheme.Light — this ?? ElementTheme.Light default could cause incorrect behavior if Application.Current is null or hasn't propagated the theme yet
  • The needsPush decision compares the element's requested theme against GetActiveTheme() — if the stack has a stale entry from a prior walk, subsequent elements might not push correctly
  • The static Stack<ResourceKey> has no thread-safety guarantees, though on WASM this is less relevant (single-threaded)

Affected platforms

  • WASM: Confirmed failing (build 210415)
  • Skia: Likely affected (same UNO_HAS_ENHANCED_LIFECYCLE define, same code path)
  • Others: Sanity checks needs to be done

Key Code Locations (release/stable/6.6)

File Key Code
src/Uno.UI/UI/Xaml/ResourceDictionary.cs GetActiveTheme(), Themes class with RequestedThemeForSubTree, Push/Pop
src/Uno.UI/UI/Xaml/FrameworkElement.Theming.cs NotifyThemeChangedCore — push/pop lifecycle, ?? ElementTheme.Light fallback
src/Uno.UI/UI/Xaml/Application.cs RequestedThemeForResources setter → SetActiveTheme()
src/Uno.UI/UI/Xaml/Data/ThemeResourceReference.cs RefreshValue() — pinned dict re-resolution using GetActiveTheme()
src/Uno.UI/UI/Xaml/DependencyObjectStore.Theming.cs UpdateAllThemeReferences / UpdateThemeReference — calls RefreshValue()

Expected Behavior

After Application.Current.RequestedTheme = ApplicationTheme.Dark, all ThemeResource lookups should resolve against the Dark theme dictionary — identical to 6.5.x behavior.

Impact

Activity

  1. added
    kind/bug
    triage/untriaged
    on May 1, 2026
  2. changed the title [-]fix: ThemeResource resolution returns Light-theme values after switching to Dark in 6.6 (regression from element-level theming)[/-] [+]ThemeResource resolution returns Light-theme values after switching to Dark in 6.6 (regression from element-level theming)[/+] on May 1, 2026
  3. added theissue type on May 1, 2026
  4. added a commit that references this issue on May 2, 2026
    625ee04
  5. self-assigned this
    on May 12, 2026
  6. khaskoul commented on May 12, 2026

    @khaskoul

    The issue still occurs on
    Templates/SDK: 6.6.10
    Platform(s): Desktop
    VS VSIX: 6.6.7.7
    IDE: VS 18.4.6
    OS: Windows

    App used to test:

    UnoApp5.zip

    Recording.2026-05-12.104004.mp4

    • Current theme: "Dark" (label updated correctly)
    • Box color: Still cyan (#30E7E8) — the Light value
    • Border: Still 2px — the Light value
    • Corner radius: Still 4px — the Light value

    This proves the regression: {ThemeResource} lookups are not re-resolving against the Dark dictionary after ThemeService.SetThemeAsync(Dark) is called.
    The Themes.Active is being set (the app knows it's Dark), but GetActiveTheme() via RequestedThemeForSubTree is still returning the Light-theme key during resource resolution.
    The overall page background also did not switch to a dark color, further confirming that all {ThemeResource} bindings are stuck on Light values — exactly matching the 7 failing tests in the CI build.

  7. 55 remaining items

  8. agneszitte commented on Jul 2, 2026

    @agneszitte
    MemberAuthor

    The issue still occurs on Templates/SDK: 6.6.10 Platform(s): Desktop VS VSIX: 6.6.7.7 IDE: VS 18.4.6 OS: Windows

    App used to test:

    UnoApp5.zip

    Recording.2026-05-12.104004.mp4
    • Current theme: "Dark" (label updated correctly) • Box color: Still cyan (#30E7E8) — the Light value • Border: Still 2px — the Light value • Corner radius: Still 4px — the Light value

    This proves the regression: {ThemeResource} lookups are not re-resolving against the Dark dictionary after ThemeService.SetThemeAsync(Dark) is called. The Themes.Active is being set (the app knows it's Dark), but GetActiveTheme() via RequestedThemeForSubTree is still returning the Light-theme key during resource resolution. The overall page background also did not switch to a dark color, further confirming that all {ThemeResource} bindings are stuck on Light values — exactly matching the 7 failing tests in the CI build.


    @khaskoul I am closing this issue as normally fixed with latest Uno.Sdk 6.6.14. I will let you confirm on your side and with HD as well, but with a quick test on my side:

    Image
  9. jhanvi03 commented on Jul 3, 2026

    @jhanvi03

    Reopening the issue, as it still appears to be reproducible with Hot Design.

    Tested with:
    Sdk/template: 6.6.14
    Rider Plugin: 1.10.43
    OS: Mac
    TFM: Desktop

    Screen.Recording.2026-07-03.at.11.50.04.AM.mov
  10. MartinZikmund commented on Jul 6, 2026

    @MartinZikmund
    Member

    This is hot design specific problem. When you initially enter HD, it will put itself as the root element. This means that clicking the theme switch buttons changes the theme of HD, not the app inside. The behavior is in fact correct, although not what the user would expect. However, as long as the app is implemented in a way that is HD aware (eg. switching theme changes theme of the app's root element instead of HD root, it will behave correctly.

  11. nickrandolph commented on Jul 6, 2026

    @nickrandolph
    Contributor

    @MartinZikmund I concur, this is an issue that hasn't been resolved. It's actually an issue with extensions or toolkit themeservice that hasn't been updated to be ALC aware
    cc @kazo0 @Kunal22shah

  12. jhanvi03 commented on Jul 6, 2026

    @jhanvi03

    Closing this issue as the underlying Uno core issue has been resolved.

    The remaining behavior is specific to Hot Design and is being tracked separately in https://github.com/unoplatform/uno.hotdesign/issues/7104, where it will be addressed as part of the 6.7 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/bugtriage/untriaged

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions