Skip to content

fix - adapting theme switcher for echarts#2526

Open
varun-srinivasa wants to merge 4 commits into
mainfrom
fix/ix-4159
Open

fix - adapting theme switcher for echarts#2526
varun-srinivasa wants to merge 4 commits into
mainfrom
fix/ix-4159

Conversation

@varun-srinivasa
Copy link
Copy Markdown
Collaborator

💡 What is the current behavior?

Theme in echarts when toggled using ixmenu doesnt always take effect

GitHub Issue Number: NA / ix-4159

🆕 What is the new behavior?

  • Theme in echarts works even when toggeled rapidly

🏁 Checklist

A pull request can only be merged if all of these conditions are met (where applicable):

  • 🦮 Accessibility (a11y) features were implemented
  • 🗺️ Internationalization (i18n) - no hard coded strings
  • 📲 Responsiveness - components handle viewport changes and content overflow gracefully
  • 📕 Add or update a Storybook story
  • 📄 Documentation was reviewed/updated siemens/ix-docs
  • 🧪 Unit tests were added/updated and pass (pnpm test)
  • 📸 Visual regression tests were added/updated and pass (Guide)
  • 🧐 Static code analysis passes (pnpm lint)
  • 🏗️ Successful compilation (pnpm build, changes pushed)

👨‍💻 Help & support

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

⚠️ No Changeset found

Latest commit: 6e78107

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a snapshot-based mechanism to the ThemeSwitcher to prevent redundant theme change events. While the implementation improves efficiency, the snapshot logic should be expanded to include the colorSchema property to ensure all relevant changes are captured. Additionally, the PR needs to be updated to comply with project standards, specifically regarding the title format, the inclusion of a changeset for consumer-relevant changes, and the addition of missing unit tests as indicated in the checklist.

Comment on lines 26 to 42
private getSnapshot(): string {
return `${this.getTheme()}-${this.getMode()}`;
}

private emitThemeChange(isMediaChange: boolean) {
this.themeChanged.emit({
const snapshot = this.getSnapshot();
if (snapshot === this.lastEmittedSnapshot && !isMediaChange) return;
this.lastEmittedSnapshot = snapshot;

const detail: ThemeChangeEventDetail = {
theme: this.getTheme(),
colorSchema: this.getColorSchema(),
mode: this.getMode(),
isMediaChange,
});
};
this.themeChanged.emit(detail);
}
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.

high

The current snapshot logic in getSnapshot only considers theme and mode. However, ThemeChangeEventDetail also includes the colorSchema property. If the colorSchema changes (e.g., from 'system' to 'dark') while the resolved mode remains the same (because the system was already dark), the event will not be emitted. This results in listeners receiving stale information about the colorSchema.

Additionally, the emitThemeChange method performs multiple redundant calls to getTheme, getColorSchema, and getMode. I suggest refactoring this to capture the values once and include colorSchema in the snapshot.

  private emitThemeChange(isMediaChange: boolean) {
    const theme = this.getTheme();
    const colorSchema = this.getColorSchema();
    const mode = this.getMode();
    const snapshot = theme + "-" + colorSchema + "-" + mode;

    if (snapshot === this.lastEmittedSnapshot && !isMediaChange) return;
    this.lastEmittedSnapshot = snapshot;

    this.themeChanged.emit({
      theme,
      colorSchema,
      mode,
      isMediaChange,
    });
  }

class ThemeSwitcher {
private mutationObserver?: MutationObserver;
private mediaQueryList?: MediaQueryList;
private lastEmittedSnapshot?: string;
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.

medium

The pull request title 'fix - adapting theme switcher for echarts' does not adhere to the required format: '[optional ]: '. Please update it to follow the convention (e.g., 'fix(core): adapting theme switcher for echarts').

References
  1. Follow the rule [optional ]: for pull request titles. (link)

class ThemeSwitcher {
private mutationObserver?: MutationObserver;
private mediaQueryList?: MediaQueryList;
private lastEmittedSnapshot?: string;
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.

medium

This pull request introduces consumer-relevant changes to theme emission behavior. According to the style guide, a changeset should be included for such changes to ensure proper release management and documentation.

References
  1. Treat a missing changeset as a review issue when a pull request includes user-facing or consumer-relevant changes. (link)

this.setColorSchema(colorSchema);
document.documentElement.dataset.ixColorSchema =
colorSchema ?? this.getColorSchema();
this.emitThemeChange(false);
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.

medium

The PR checklist indicates that unit tests were added or updated, but no changes to test files are present in this diff. Automated tests are essential to verify the fix for rapid toggling and to prevent regressions in theme emission logic.

References
  1. Focus on missing validation and ensure adequate testing for changes.

@varun-srinivasa
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the ThemeSwitcher by implementing snapshot-based change detection to prevent redundant emissions and introducing a new global ix-theme-change DOM event. Review feedback highlights several style guide violations: the PR title needs to follow the standard format, a changeset is required for the new public event and behavior changes, and the new event must be documented with a @SInCE tag.

class ThemeSwitcher {
private mutationObserver?: MutationObserver;
private mediaQueryList?: MediaQueryList;
private lastEmittedSnapshot?: string;
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.

medium

The pull request title fix - adapting theme switcher for echarts does not follow the required format. According to the repository style guide, it should follow the pattern <type>[optional <scope>]: <description>. Please update the title to use a colon (e.g., fix: adapting theme switcher for echarts).

References
  1. Pull request titles must follow the rule [optional ]: . (link)

class ThemeSwitcher {
private mutationObserver?: MutationObserver;
private mediaQueryList?: MediaQueryList;
private lastEmittedSnapshot?: string;
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.

medium

This pull request introduces consumer-relevant changes, including a new global DOM event ix-theme-change and a change to synchronous theme change emissions. According to the repository style guide, a changeset is required for such changes. Please add a changeset file describing these updates.

References
  1. A changeset is required for public API updates, component behavior changes, styling or theming changes, accessibility changes, and bug fixes that materially affect users. (link)

this.themeChanged.emit(detail);

if (typeof document !== 'undefined') {
document.dispatchEvent(new CustomEvent('ix-theme-change', { detail }));
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.

medium

The new global DOM event ix-theme-change should be documented with a @since tag indicating the version in which it was introduced, as per the repository style guide for new events. Since this is a DOM event dispatched on the document, consider adding the documentation in the class JSDoc or near the dispatch point.

References
  1. Ensure that each new component, property, method, or event has a JSDocs which contains a @SInCE tag with the version number of the release in which it was added. (link)

@varun-srinivasa varun-srinivasa marked this pull request as ready for review May 18, 2026 03:13
@netlify
Copy link
Copy Markdown

netlify Bot commented May 26, 2026

Deploy Preview for ix-storybook ready!

Name Link
🔨 Latest commit 6e78107
🔍 Latest deploy log https://app.netlify.com/projects/ix-storybook/deploys/6a155223fd384c0008fdb19b
😎 Deploy Preview https://deploy-preview-2526--ix-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sonarqubecloud
Copy link
Copy Markdown

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.

2 participants