Skip to content

fix: preserve mode-dependent overrides in dark mode rules#164

Open
SpyZzey wants to merge 1 commit into
mainfrom
fix/dark-theme-optimization-issue
Open

fix: preserve mode-dependent overrides in dark mode rules#164
SpyZzey wants to merge 1 commit into
mainfrom
fix/dark-theme-optimization-issue

Conversation

@SpyZzey
Copy link
Copy Markdown
Member

@SpyZzey SpyZzey commented Apr 15, 2026

Fixes AWSUI-61881: The dark mode gets overridden when light and dark mode uses the same value in themes due to some optimizations.

Issue #, if available: AWSUI-61881

How to test it locally:

  • Create a simple react project that consumes cloudscape-design from npm
  • Create a custom theme where a token has the same light as dark value (see appendix below)
  • Checkout theming-core and build the theming-core project, copy the lib/browser/browser and lib/browser/shared folder and replace the corresponding ones in the node_modules/@cloudscape-design/theming-runtime package or use npm link.
  • Run npm run dev and check how it looks like (and compare it with the current live theming-runtime from @cloudscape-design/theming-runtime)

Appendix:

applyMode(Mode.Dark);
applyTheme({
  theme: {
    tokens: {
      colorBorderButtonNormalDefault: {
        light: "pink",
        dark: "pink",
      },
    },
  },
});

export default function App() {
  return (
    <div style={{ padding: "20px" }}>
      <Button>Test</Button>
    </div>
  );
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@SpyZzey SpyZzey force-pushed the fix/dark-theme-optimization-issue branch from 5839895 to c144f81 Compare April 15, 2026 13:55
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.59%. Comparing base (43861b7) to head (8d85739).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #164      +/-   ##
==========================================
+ Coverage   97.57%   97.59%   +0.01%     
==========================================
  Files          48       48              
  Lines        2641     2657      +16     
  Branches      549      558       +9     
==========================================
+ Hits         2577     2593      +16     
  Misses         64       64              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SpyZzey SpyZzey marked this pull request as ready for review April 15, 2026 14:35
@SpyZzey SpyZzey requested a review from a team as a code owner April 15, 2026 14:35
@SpyZzey SpyZzey requested review from pan-kot and removed request for a team and pan-kot April 15, 2026 14:35
@SpyZzey SpyZzey marked this pull request as draft April 15, 2026 14:40
@SpyZzey SpyZzey changed the title fix: preserve mode-dependent overrides in dark mode rules fix: preserve mode-dependent overrides in dark mode rules WIP Apr 15, 2026
@SpyZzey SpyZzey requested a review from gethinwebster April 15, 2026 14:56
@SpyZzey SpyZzey marked this pull request as ready for review April 15, 2026 14:56
@SpyZzey SpyZzey changed the title fix: preserve mode-dependent overrides in dark mode rules WIP fix: preserve mode-dependent overrides in dark mode rules Apr 15, 2026
gethinwebster
gethinwebster previously approved these changes Apr 20, 2026
expect(result.findRule('.child')).toBeUndefined();
});

test('preserves overridden properties in mode rules even when values match root', () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is it necessary to preserve mode rules in this case?

E.g.:

body {
  color-badge-status-critical: red;
}
.dark-mode {
  color-badge-status-critical: red; // Is this needed?
}

@SpyZzey SpyZzey force-pushed the fix/dark-theme-optimization-issue branch from c144f81 to 8d85739 Compare April 30, 2026 13:27
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