fix(embedded): default to light theme instead of system preference#38644
fix(embedded): default to light theme instead of system preference#38644sadpandajoe wants to merge 4 commits intomasterfrom
Conversation
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>
Code Review Agent Run #9703f6Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Sequence DiagramThis 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
Generated by CodeAnt AI |
Co-authored-by: Joe Li <joe@preset.io>
Code Review Agent Run #90c1fdActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
There was a problem hiding this comment.
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
ThemeControllerwith an optionalinitialModeconstructor option and use it when no saved mode exists. - Set embedded dashboards to initialize with
ThemeMode.DEFAULT. - Add Jest coverage validating
initialModebehavior 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.
| // Use explicit initial mode if provided (e.g. embedded dashboards default to light) | ||
| if (this.initialMode !== undefined) return this.initialMode; |
There was a problem hiding this comment.
Good catch — added isValidThemeMode() validation to match the savedMode check above. Also added a test for invalid initialMode fallback.
geido
left a comment
There was a problem hiding this comment.
This seems viable to me. The Copilot suggestions might be worth looking into. Also, curious what @msyavuz and @gabotorresruiz think about this.
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>
f9b9b5e to
236723e
Compare
Code Review Agent Run #501bfdActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
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 toThemeMode.SYSTEM, which readsprefers-color-schemefrom the user's OS. The SDK'ssetThemeMode()fires after initial render via postMessage, so the wrong theme is shown first.Fix: Add
initialModeoption toThemeControllerOptions. Embedded contexts passThemeMode.DEFAULTso 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. InvalidinitialModevalues are validated withisValidThemeMode()and fall back to SYSTEM, matching the existingsavedModecheck.Files changed:
packages/superset-core/src/theme/types.ts— AddedinitialMode?: ThemeModetoThemeControllerOptionssrc/theme/ThemeController.ts— Store and useinitialModeas fallback indetermineInitialMode(), withisValidThemeMode()validationsrc/embedded/EmbeddedContextProviders.tsx— PassinitialMode: ThemeMode.DEFAULTsrc/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
setThemeMode('dark')via the SDK — verify it switches to dark modesetThemeMode('system')via the SDK — verify it follows OS preferenceADDITIONAL INFORMATION