Skip to content

Commit

Permalink
fix(graph): don't listen to system theme changes in console (nrwl#22938)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless authored and AgentEnder committed Apr 23, 2024
1 parent 74ca777 commit ec0e9f5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions graph/ui-theme/src/lib/theme-resolver.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getEnvironmentConfig } from '@nx/graph/shared';

const htmlEl = document.documentElement;
export const localStorageThemeKey = 'nx-dep-graph-theme';
export type Theme = 'light' | 'dark' | 'system';
Expand Down Expand Up @@ -48,6 +50,10 @@ export function getSystemTheme(): 'light' | 'dark' {
if (isVSCodeDark || isVSCodeLight) {
return isVSCodeDark ? 'dark' : 'light';
}
// we don't want to use system theme in nx-console because it might conflict with the IDE theme
if (getEnvironmentConfig().environment === 'nx-console') {
return 'light';
}
const isDarkMedia = window.matchMedia('(prefers-color-scheme: dark)').matches;
return isDarkMedia || isVSCodeDark ? 'dark' : 'light';
}
Expand All @@ -65,8 +71,9 @@ export function themeResolver(theme: Theme) {
currentTheme = theme;
} else {
const resolver = getSystemTheme();

darkMedia.addEventListener('change', mediaListener);
if (getEnvironmentConfig().environment !== 'nx-console') {
darkMedia.addEventListener('change', mediaListener);
}
vscodeDarkOberserver.observe(document.body, {
attributes: true,
attributeFilter: ['class'],
Expand Down

0 comments on commit ec0e9f5

Please sign in to comment.