onurtashan opened a new issue, #40759:
URL: https://github.com/apache/superset/issues/40759

   ## Problem
   
   `EmbeddedContextProviders.tsx` hardcodes `initialMode: ThemeMode.DEFAULT`:
   
   ```typescript
   const themeController = new ThemeController({
     storage: new ThemeMemoryStorageAdapter(),
     initialMode: ThemeMode.DEFAULT, // hardcoded
   });
   ```
   
   Embedding pages (e.g. Partner Portals) that want to load embedded dashboards 
in dark mode must call `setThemeMode('dark')` post-load, causing a visible 
flash from light to dark. There is no way to set the initial theme at load time.
   
   ## Proposed solution
   
   The embedded SDK already supports passing arbitrary URL params to the iframe 
via `dashboardUiConfig.urlParams`. So a host app can already do:
   
   ```typescript
   embedDashboard({
     ...
     dashboardUiConfig: {
       urlParams: { theme: 'dark' },
     },
   });
   ```
   
   The only missing piece: `EmbeddedContextProviders.tsx` does not read this 
param. The fix is a single function (~8 lines) that reads `?theme=` from 
`window.location.search` on load:
   
   ```typescript
   function getInitialThemeMode(): ThemeMode {
     const params = new URLSearchParams(window.location.search);
     const theme = params.get('theme');
     switch (theme) {
       case 'dark':   return ThemeMode.DARK;
       case 'system': return ThemeMode.SYSTEM;
       default:       return ThemeMode.DEFAULT;
     }
   }
   
   const themeController = new ThemeController({
     storage: new ThemeMemoryStorageAdapter(),
     initialMode: getInitialThemeMode(), // reads ?theme= from URL
   });
   ```
   
   ## Why this is safe
   
   - Fully backward compatible — no URL param → `ThemeMode.DEFAULT` (unchanged 
behavior)
   - `ThemeMode.SYSTEM` already has a fallback guard (`isValidThemeMode` 
returns `false` when `darkTheme` is undefined, falling back to 
`ThemeMode.DEFAULT`)
   - No SDK changes required — `urlParams` already exists
   
   ## Scope
   
   ~8 lines changed in `EmbeddedContextProviders.tsx` + tests in a new 
`EmbeddedContextProviders.test.tsx`.
   
   Happy to submit a PR if the approach looks good!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to