Skip to content

feat(theming): support user OS-level dark/light mode configuration #33890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Jun 24, 2025

This PR introduce new superset_config settings:

# THEME and THEME_DARK are used for setting a custom theme to Superset,
# it follows the ant design theme structure.
# You can use the AntDesign theme editor to generate a theme structure
# https://ant.design/theme-editor
# The config are set as a callable returning an antd-compatible theme object
# so that themes can be hot-swapped by fetching a theme object definition remotely

# Whether to respect the user's OS dark mode setting. If True, THEME_DARK must be set
THEME_RESPECT_USER_OS_DARK_SETTING = False
THEME: dict[str, Any] = lambda: {}  # NOQA
THEME_DARK: dict[str, Any] = lambda: {"algorithm": "dark"}  # NOQA

Some of the logic:

  • the frontend will set a cookie with the os-level preference for dark theme
  • on first request, before cookie is set, the backend returns both theme (light and dark) configuration under boostrapData.themes, letting the frontend to pick the right one
  • on subsequent request, once the cookie is available, the backend return the right theme under boostrapData.themes

@mistercrunch mistercrunch marked this pull request as draft June 24, 2025 20:55
@dosubot dosubot bot added the global:theming Related to theming Superset label Jun 24, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Security Unvalidated Cookie Value Setting ▹ view 🧠 Not in scope
Functionality No UI Theme Update ▹ view 🧠 Not in scope
Functionality Missing Fallback Theme Logic ▹ view 🧠 Not in scope
Documentation Documentation Accuracy Issue ▹ view 🧠 Not in standard
Design Unnecessary Lambda Functions for Static Config Values ▹ view 🧠 Not in scope
Functionality Missing OS Theme Change Listener ▹ view 🧠 Not in standard
Files scanned
File Path Reviewed
superset-frontend/src/views/RootContextProviders.tsx
superset-frontend/src/setup/setupApp.ts
superset-frontend/src/theme/ThemeController.tsx
superset/views/base.py
superset/config.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

: 'light';

const setThemeCookie = theme => {
document.cookie = `superset_theme=${theme}; path=/; SameSite=Lax; secure`;

This comment was marked as resolved.

function syncBrowserThemePreferenceWithCookie() {
try {
const getCurrentPreference = () =>
window.matchMedia('(prefers-color-scheme: dark)').matches

This comment was marked as resolved.

const cookies = parseCookie();

if (cookies.superset_theme !== currentPreference) {
setThemeCookie(currentPreference);

This comment was marked as resolved.

Comment on lines +132 to +134
if (bootstrapData.themes[preferred]) {
themeConfig = bootstrapData.themes[preferred];
}

This comment was marked as resolved.

@@ -292,6 +293,27 @@ def menu_data(user: User) -> dict[str, Any]:
}


def get_theme_bootstrap_data() -> dict[str, Any]:
"""
On frst call, the cookie related to light/dark may not be set,

This comment was marked as resolved.

Comment on lines +681 to +682
THEME: dict[str, Any] = lambda: {} # NOQA
THEME_DARK: dict[str, Any] = lambda: {"algorithm": "dark"} # NOQA

This comment was marked as resolved.

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 preset-io size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant