rusackas opened a new pull request, #41347:
URL: https://github.com/apache/superset/pull/41347

   ### SUMMARY
   
   Fixes a white-screen regression where a **partial** `THEME_DEFAULT` (or 
`THEME_DARK`) override in `superset_config.py` crashes the frontend.
   
   **Root cause:** PR #35220 populated `THEME_DEFAULT` with ~22 token fields 
(`fontFamily`, `colorLink`, etc.). Because Superset loads user config via `from 
superset_config import *`, defining `THEME_DEFAULT` in `superset_config.py` 
*replaces the entire dict* rather than merging. An operator who sets only a 
couple of tokens (e.g. just `colorPrimary`) silently drops all the others. The 
frontend then calls `.startsWith()` on an undefined field like `fontFamily` and 
dies with a blank white screen.
   
   **The fix:**
   1. `superset/config.py` — introduce private `_THEME_DEFAULT_BASE` / 
`_THEME_DARK_BASE` constants holding the built-in defaults. The underscore 
prefix means they survive `from superset_config import *` (star-imports skip 
underscore-prefixed names), so the built-in baseline is always available even 
when the operator overrides `THEME_DEFAULT`. `THEME_DEFAULT` / `THEME_DARK` are 
aliased to them.
   2. `superset/views/base.py` — in `get_theme_bootstrap_data()`, deep-merge 
the user's config theme on top of these base constants using the existing 
`_merge_theme_dicts()` helper, so unspecified token fields fall back to the 
built-in values.
   3. `tests/unit_tests/views/test_base_theme_helpers.py` — adds a regression 
test (`test_partial_theme_override_preserves_base_tokens`) and updates a few 
existing assertions whose expected output legitimately changes now that config 
themes are merged with the base.
   
   **Note on a subtle behavior change:** config themes are now **always** 
deep-merged over the built-in base — even a full replacement. This is more 
correct (you can no longer accidentally drop required tokens), but it does mean 
a *deliberately* minimal theme will get base tokens merged back in. Operators 
who want to clear a token should set it explicitly rather than omitting it.
   
   ### BEFORE/AFTER
   
   **Before:** Setting a partial override in `superset_config.py`, e.g.
   
   ```python
   THEME_DEFAULT = {"token": {"colorPrimary": "#ff0000"}, "algorithm": 
"default"}
   ```
   
   ...renders a blank white screen (`Cannot read properties of undefined 
(reading 'startsWith')`).
   
   **After:** The partial override is deep-merged over the built-in defaults. 
`/login` and the rest of the app render correctly, with `colorPrimary` applied 
and all other tokens (`fontFamily`, `colorLink`, etc.) intact.
   
   ### TESTING INSTRUCTIONS
   
   Automated:
   
   ```bash
   pytest tests/unit_tests/views/test_base_theme_helpers.py -v
   ```
   
   All 38 tests pass, including the new 
`test_partial_theme_override_preserves_base_tokens` regression test.
   
   Manual:
   1. Add a partial `THEME_DEFAULT` override (only `colorPrimary`) to 
`superset_config.py`.
   2. Start Superset and load `/login`.
   3. Before this fix: white screen. After: the page renders with the custom 
primary color and intact default fonts/tokens.
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: Fixes #40375
   - [ ] Required feature flags:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   ---
   
   Adopted from 
[abdul-haizelabs/superset#6](https://github.com/abdul-haizelabs/superset/pull/6).
 Original work by Devin (app/devin-ai-integration) on the Haize Labs fork; 
adopted, typing-cleaned, and rebased onto current `master` by @rusackas. 
Co-authorship preserved in the commit trailer.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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