Skip to content

fix(embedded): default to light theme instead of system preference#38644

Open
sadpandajoe wants to merge 4 commits intomasterfrom
fix-embedded-system-settings
Open

fix(embedded): default to light theme instead of system preference#38644
sadpandajoe wants to merge 4 commits intomasterfrom
fix-embedded-system-settings

Conversation

@sadpandajoe
Copy link
Member

@sadpandajoe sadpandajoe commented Mar 14, 2026

SUMMARY

Embedded dashboards were inheriting the user's OS dark/light mode preference instead of defaulting to light mode. When both default and dark themes are available via bootstrap data, ThemeController.determineInitialMode() defaults to ThemeMode.SYSTEM, which reads prefers-color-scheme from the user's OS. The SDK's setThemeMode() fires after initial render via postMessage, so the wrong theme is shown first.

Fix: Add initialMode option to ThemeControllerOptions. Embedded contexts pass ThemeMode.DEFAULT so they start in light mode. Main app behavior is unchanged (still defaults to SYSTEM when both themes exist). The SDK can still override the mode after init. Invalid initialMode values are validated with isValidThemeMode() and fall back to SYSTEM, matching the existing savedMode check.

Files changed:

  • packages/superset-core/src/theme/types.ts — Added initialMode?: ThemeMode to ThemeControllerOptions
  • src/theme/ThemeController.ts — Store and use initialMode as fallback in determineInitialMode(), with isValidThemeMode() validation
  • src/embedded/EmbeddedContextProviders.tsx — Pass initialMode: ThemeMode.DEFAULT
  • src/theme/tests/ThemeController.test.ts — 7 new tests (73/73 passing)

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before: Embedded dashboard renders in dark mode if user's OS is set to dark mode, ignoring SDK theme setting.
After: Embedded dashboard renders in light mode by default. SDK setThemeMode() can still switch to dark/system.

TESTING INSTRUCTIONS

  1. Set your OS to dark mode
  2. Load an embedded dashboard (via the Superset Embedded SDK)
  3. Verify the dashboard renders in light mode by default
  4. Call setThemeMode('dark') via the SDK — verify it switches to dark mode
  5. Call setThemeMode('system') via the SDK — verify it follows OS preference
  6. Verify non-embedded Superset still follows system theme preference

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Embedded dashboards were inheriting the user's OS dark/light mode
preference instead of defaulting to light mode. Added initialMode
option to ThemeControllerOptions so embedded contexts can specify
their default theme mode explicitly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Mar 14, 2026

Code Review Agent Run #9703f6

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: 8437c93..8437c93
    • superset-frontend/packages/superset-core/src/theme/types.ts
    • superset-frontend/src/embedded/EmbeddedContextProviders.tsx
    • superset-frontend/src/theme/ThemeController.ts
    • superset-frontend/src/theme/tests/ThemeController.test.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ 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

@codeant-ai-for-open-source codeant-ai-for-open-source bot added the size:L This PR changes 100-499 lines, ignoring generated files label Mar 14, 2026
@dosubot dosubot bot added embedded global:theming Related to theming Superset labels Mar 14, 2026
@codeant-ai-for-open-source
Copy link
Contributor

Sequence Diagram

This PR adds an explicit initial mode for theme initialization so embedded dashboards start in light mode instead of inheriting OS preference. It preserves later SDK-driven theme changes after the first render.

sequenceDiagram
    participant EmbeddedApp
    participant ThemeController
    participant ThemeStorage
    participant SDK

    EmbeddedApp->>ThemeController: Initialize with initial mode default
    ThemeController->>ThemeStorage: Read saved theme mode
    ThemeStorage-->>ThemeController: No saved mode
    ThemeController->>ThemeController: Use initial mode as startup fallback
    ThemeController-->>EmbeddedApp: Apply light theme on first render
    SDK->>ThemeController: Set theme mode dark or system
    ThemeController-->>EmbeddedApp: Apply requested mode after init
Loading

Generated by CodeAnt AI

Co-authored-by: Joe Li <joe@preset.io>
@github-actions github-actions bot removed the embedded label Mar 14, 2026
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Mar 14, 2026

Code Review Agent Run #90c1fd

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 8437c93..9ef0fd9
    • superset-frontend/src/theme/tests/ThemeController.test.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ 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

@sadpandajoe sadpandajoe requested a review from Copilot March 14, 2026 16:26
@codeant-ai-for-open-source codeant-ai-for-open-source bot added size:L This PR changes 100-499 lines, ignoring generated files and removed size:L This PR changes 100-499 lines, ignoring generated files labels Mar 14, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for an explicit initial theme mode in the frontend ThemeController, and uses it to force embedded contexts to start in light/default mode rather than following OS/system preference.

Changes:

  • Extend ThemeController with an optional initialMode constructor option and use it when no saved mode exists.
  • Set embedded dashboards to initialize with ThemeMode.DEFAULT.
  • Add Jest coverage validating initialMode behavior and precedence relative to saved mode/system mode.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
superset-frontend/src/theme/ThemeController.ts Adds initialMode handling in initial mode determination.
superset-frontend/src/theme/tests/ThemeController.test.ts Adds unit tests for initialMode precedence and behavior.
superset-frontend/src/embedded/EmbeddedContextProviders.tsx Forces embedded theme controller to start in DEFAULT mode.
superset-frontend/packages/superset-core/src/theme/types.ts Extends ThemeControllerOptions with initialMode?: ThemeMode.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +750 to +751
// Use explicit initial mode if provided (e.g. embedded dashboards default to light)
if (this.initialMode !== undefined) return this.initialMode;
Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch — added isValidThemeMode() validation to match the savedMode check above. Also added a test for invalid initialMode fallback.

Copy link
Member

@geido geido left a comment

Choose a reason for hiding this comment

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

This seems viable to me. The Copilot suggestions might be worth looking into. Also, curious what @msyavuz and @gabotorresruiz think about this.

@geido geido requested a review from msyavuz March 15, 2026 11:41
Copy link
Member

@msyavuz msyavuz left a comment

Choose a reason for hiding this comment

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

Yeah, i think this looks sensible to me as well

@codeant-ai-for-open-source codeant-ai-for-open-source bot added size:L This PR changes 100-499 lines, ignoring generated files and removed size:L This PR changes 100-499 lines, ignoring generated files labels Mar 15, 2026
Add isValidThemeMode() validation to initialMode check in
determineInitialMode(), matching the existing savedMode validation
on the line above. Invalid initialMode values now fall back to
SYSTEM instead of being returned as-is.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sadpandajoe sadpandajoe force-pushed the fix-embedded-system-settings branch from f9b9b5e to 236723e Compare March 15, 2026 21:29
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Mar 15, 2026

Code Review Agent Run #501bfd

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 9ef0fd9..236723e
    • superset-frontend/src/theme/ThemeController.ts
    • superset-frontend/src/theme/tests/ThemeController.test.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

global:theming Related to theming Superset packages size/L size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants