Skip to content

fix(dashboard): changing a theme no longer discards unsaved edits or reloads charts - #42815

Open
gabotorresruiz wants to merge 1 commit into
apache:masterfrom
gabotorresruiz:fix/dashboard-theme-change-remount
Open

fix(dashboard): changing a theme no longer discards unsaved edits or reloads charts#42815
gabotorresruiz wants to merge 1 commit into
apache:masterfrom
gabotorresruiz:fix/dashboard-theme-change-remount

Conversation

@gabotorresruiz

@gabotorresruiz gabotorresruiz commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

Changing a dashboard's theme in edit mode had two problems, both from a remount:

  1. CrudThemeProvider recreated the Theme on every theme change. Since each Theme binds its own SupersetThemeProvider, this swapped the provider identity and remounted the whole dashboard subtree, reloading every chart. It now keeps one stable Theme instance updated in place via Theme.setConfig (which gains an optional baseTheme, merged the same way fromConfig does).

  2. That remount unmounted the dashboard header, whose auto-refresh cleanup dispatches setRefreshFrequency(0). The SET_REFRESH_FREQUENCY reducer wrote hasUnsavedChanges from action.isPersistent, clearing the flag so Save went disabled right after a theme was applied. A refresh-frequency update now only adds unsaved changes, never clears them.

Together, a theme can be applied, changed, or removed and saved through the UI without reloading charts. Backward compatible: existing setConfig and fromConfig callers are unaffected.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:

dashboard-theme-before

After:

dashboard-theme-after

TESTING INSTRUCTIONS

  1. Give a dashboard a custom theme (Settings > Themes).
  2. In edit mode, open Edit properties > Styling, then change or remove the theme and click Apply.
  3. Save stays enabled and persists; switching between two themes recolors in place without reloading charts.

ADDITIONAL INFORMATION

  • Changes UI

@gabotorresruiz
gabotorresruiz force-pushed the fix/dashboard-theme-change-remount branch from 3354d82 to b00fe08 Compare August 5, 2026 21:33
@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit a56a8f2
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a76183e3eaab600088a5ecf
😎 Deploy Preview https://deploy-preview-42815--superset-docs-preview.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.

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.37%. Comparing base (fe06ebe) to head (db91536).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #42815   +/-   ##
=======================================
  Coverage   66.37%   66.37%           
=======================================
  Files        2857     2857           
  Lines      161048   161066   +18     
  Branches    37046    37054    +8     
=======================================
+ Hits       106892   106915   +23     
+ Misses      52141    52136    -5     
  Partials     2015     2015           
Flag Coverage Δ
javascript 73.20% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@gabotorresruiz
gabotorresruiz force-pushed the fix/dashboard-theme-change-remount branch 2 times, most recently from 5b5ad42 to 4357db3 Compare August 6, 2026 17:10
@gabotorresruiz gabotorresruiz changed the title fix(dashboard): avoid remounting the dashboard when its theme changes fix(dashboard): changing a theme no longer discards unsaved edits or reloads charts Aug 6, 2026
@gabotorresruiz
gabotorresruiz force-pushed the fix/dashboard-theme-change-remount branch 2 times, most recently from 8ab88d5 to 9a5aba1 Compare August 6, 2026 17:31
@gabotorresruiz
gabotorresruiz force-pushed the fix/dashboard-theme-change-remount branch 3 times, most recently from 2532354 to db91536 Compare August 7, 2026 14:05
@gabotorresruiz
gabotorresruiz requested review from msyavuz, rusackas and sadpandajoe and removed request for msyavuz and sadpandajoe August 7, 2026 15:23
@gabotorresruiz
gabotorresruiz marked this pull request as ready for review August 7, 2026 15:23
@dosubot dosubot Bot added change:frontend Requires changing the frontend dashboard:design Related to the Dashboard UI/UX labels Aug 7, 2026
@bito-code-review

bito-code-review Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b78dd2

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset-frontend/packages/superset-core/src/theme/Theme.tsx - 1
    • Untested setConfig overload · Line 67-95
      The new `setConfig(config, baseTheme)` overload at line 127 is not exercised by any existing test. The test file has coverage for `fromConfig(config, baseTheme)` (lines 223-329) and for `setConfig(config)` with one argument (lines 119-163), but the new two-argument variant used by `CrudThemeProvider` at line 97 is untested.
Review Details
  • Files reviewed - 5 · Commit Range: db91536..db91536
    • superset-frontend/packages/superset-core/src/theme/Theme.tsx
    • superset-frontend/src/components/CrudThemeProvider.test.tsx
    • superset-frontend/src/components/CrudThemeProvider.tsx
    • superset-frontend/src/dashboard/reducers/dashboardState.test.ts
    • superset-frontend/src/dashboard/reducers/dashboardState.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

…reloads charts

Changing a dashboard's theme in edit mode had two problems, both rooted in a
remount:

1. CrudThemeProvider created a new Theme instance on every theme change. Since
each Theme binds its own SupersetThemeProvider, this swapped the provider
identity and remounted the whole dashboard subtree, reloading every chart. It
now keeps a single stable Theme instance updated in place via Theme.setConfig
(which gains an optional baseTheme merged the same way fromConfig does), so
switching themes no longer remounts.

2. That remount unmounted the header, whose auto-refresh cleanup dispatches
setRefreshFrequency(0). The SET_REFRESH_FREQUENCY reducer wrote
hasUnsavedChanges from action.isPersistent, clearing the flag and disabling
Save right after a theme was applied. A refresh-frequency update now only adds
unsaved changes, never clears them.
@gabotorresruiz
gabotorresruiz force-pushed the fix/dashboard-theme-change-remount branch from db91536 to a56a8f2 Compare August 7, 2026 17:39
const antdConfig = normalizeThemeConfig(config);
setConfig(config: AnyThemeConfig, baseTheme?: AnyThemeConfig): void {
const antdConfig = normalizeThemeConfig(
Theme.mergeConfig(config, baseTheme) ?? config,

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.

Suggestion: The merged configuration is used only for Ant Design token generation, while the Superset-specific ECharts overrides are still extracted from the unmerged config. When baseTheme provides these overrides and the dashboard config does not, the initial fromConfig call includes them but every later in-place update removes them, causing ECharts charts to lose their global or chart-specific customizations. Extract the Superset-specific fields from the same merged configuration passed to normalization. [api mismatch]

Severity Level: Major ⚠️
- ❌ ECharts charts lose inherited global customizations after theme updates.
- ⚠️ Chart-specific ECharts styling disappears during dashboard theme changes.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/packages/superset-core/src/theme/Theme.tsx
**Line:** 129:129
**Comment:**
	*Api Mismatch: The merged configuration is used only for Ant Design token generation, while the Superset-specific ECharts overrides are still extracted from the unmerged `config`. When `baseTheme` provides these overrides and the dashboard config does not, the initial `fromConfig` call includes them but every later in-place update removes them, causing ECharts charts to lose their global or chart-specific customizations. Extract the Superset-specific fields from the same merged configuration passed to normalization.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is valid. The current implementation of Theme.mergeConfig only merges the Ant Design token object, which causes Superset-specific ECharts overrides (often located outside the token object in the configuration) to be lost during subsequent setConfig updates.

To resolve this, update Theme.mergeConfig to perform a deeper merge that includes Superset-specific fields. Here is the corrected implementation for superset-frontend/packages/superset-core/src/theme/Theme.tsx:

  private static mergeConfig(
    config?: AnyThemeConfig,
    baseTheme?: AnyThemeConfig,
  ): AnyThemeConfig | undefined {
    if (baseTheme && config) {
      // Merge the entire config object, not just the token property
      const mergedConfig = { ...baseTheme, ...config, token: { ...baseTheme.token, ...config.token } };

      // In Ant Design v5, colorLink derives from colorInfo, not colorPrimary.
      if (config.token?.colorPrimary && !config.token?.colorLink) {
        mergedConfig.token.colorLink = config.token.colorPrimary;
      }
      return mergedConfig;
    }
    return config;
  }

There are other comments on this PR. Would you like me to fetch and validate them as well?

superset-frontend/packages/superset-core/src/theme/Theme.tsx

private static mergeConfig(
    config?: AnyThemeConfig,
    baseTheme?: AnyThemeConfig,
  ): AnyThemeConfig | undefined {
    if (baseTheme && config) {
      // Merge the entire config object, not just the token property
      const mergedConfig = { ...baseTheme, ...config, token: { ...baseTheme.token, ...config.token } };

      // In Ant Design v5, colorLink derives from colorInfo, not colorPrimary.
      if (config.token?.colorPrimary && !config.token?.colorLink) {
        mergedConfig.token.colorLink = config.token.colorPrimary;
      }
      return mergedConfig;
    }
    return config;
  }

@bito-code-review

bito-code-review Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #ca9c3a

Actionable Suggestions - 0
Review Details
  • Files reviewed - 5 · Commit Range: a56a8f2..a56a8f2
    • superset-frontend/packages/superset-core/src/theme/Theme.tsx
    • superset-frontend/src/components/CrudThemeProvider.test.tsx
    • superset-frontend/src/components/CrudThemeProvider.tsx
    • superset-frontend/src/dashboard/reducers/dashboardState.test.ts
    • superset-frontend/src/dashboard/reducers/dashboardState.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

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

Labels

change:frontend Requires changing the frontend dashboard:design Related to the Dashboard UI/UX packages size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants