Skip to content

Conversation

@ranmocy
Copy link
Contributor

@ranmocy ranmocy commented Jan 2, 2026

Describe your changes

When the app is embedded, always honor the query params to choose the theme, especially when the app has custom themes.

This allows the host to sync the themes between the host app and the embedded Streamlit app for consistency. This is critical when the host app manages the theme selection itself.

The cached theme selection in the local storage may be set when user visit the Streamlit app directly from a different interface. It should only be honored when the embedding option not present in the URL query param.

Screenshot or video (only for visual changes)

GitHub Issue Link (if applicable)

Fixes #13496

Testing Plan

  • Unit Tests for JS
  • E2E Test

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Contributor

snyk-io bot commented Jan 2, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Thanks for contributing to Streamlit! 🎈

Please make sure you have read our Contributing Guide. You can find additional information about Streamlit development in the wiki.

The review process:

  1. Initial triage: A maintainer will apply labels, approve CI to run, and trigger AI-assisted reviews. Your PR may be flagged with status:needs-product-approval if the feature requires product team sign-off.

  2. Code review: A core maintainer will start reviewing your PR once:

    • It is marked as 'ready for review', not 'draft'
    • It has status:product-approved (or doesn't need it)
    • All CI checks pass
    • All AI review comments are addressed

We're receiving many contributions and have limited review bandwidth — please expect some delay. We appreciate your patience! 🙏

@lukasmasuch lukasmasuch added change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Jan 3, 2026
@lukasmasuch lukasmasuch requested a review from Copilot January 3, 2026 12:17
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

This PR fixes custom theme selection when the app is embedded with embed_options query parameters. The fix ensures that host-specified themes (via embed_options=light_theme or embed_options=dark_theme) take precedence over cached user preferences, allowing embedding hosts to control the theme for consistency with their own UI.

Key changes:

  • Introduced getHostSpecifiedThemeOnly() to distinguish between explicit host theme specification vs. auto theme fallback
  • Updated theme selection logic in App.tsx to prioritize embed_options over cached preferences when custom themes are added or removed

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
frontend/lib/src/theme/utils.ts Added getHostSpecifiedThemeOnly() function that returns theme from query params or null (without auto theme fallback); refactored getHostSpecifiedTheme() to use it
frontend/lib/src/theme/utils.test.ts Added comprehensive test suite for getHostSpecifiedThemeOnly() covering null return, light/dark themes, and system preference scenarios
frontend/lib/src/index.ts Exported the new getHostSpecifiedThemeOnly function for use in the app
frontend/app/src/App.tsx Updated processThemeInput() to prioritize host-specified theme over cached preference when adding/removing custom themes; added createAutoTheme and getHostSpecifiedThemeOnly imports
frontend/app/src/App.test.tsx Added extensive test suite for embed_options behavior with custom themes, including tests for overriding cached preferences and proper fallback handling

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!

@mayagbarnes mayagbarnes self-assigned this Jan 5, 2026
@mayagbarnes mayagbarnes added the security-assessment-completed Security assessment has been completed for PR label Jan 5, 2026
@ranmocy
Copy link
Contributor Author

ranmocy commented Jan 5, 2026

Thank you @mayagbarnes for your feedback! Super helpful. I've addressed all your comments. PTAL.

Meanwhile, I have trouble running frontend unit tests locally. It shows errors like TypeError: window.localStorage.clear is not a function, but seems OK on CI. It's the same case when I run tests from develop branch. Any hint on where the issue is?

@ranmocy ranmocy requested a review from mayagbarnes January 5, 2026 21:06
@ranmocy ranmocy requested a review from mayagbarnes January 5, 2026 21:45
@mayagbarnes
Copy link
Collaborator

Hi @ranmocy, thanks for your contribution and speedily addressing feedback!
Think after the 1 outstanding fix above the frontend type/lint/tests should pass and should be good to go!

@ranmocy ranmocy requested a review from mayagbarnes January 5, 2026 23:03
Copy link
Collaborator

@mayagbarnes mayagbarnes left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@mayagbarnes mayagbarnes merged commit 408cbbd into streamlit:develop Jan 6, 2026
39 checks passed
@ranmocy ranmocy deleted the fix/embedded_custom_theme branch January 6, 2026 16:37
@ranmocy
Copy link
Contributor Author

ranmocy commented Jan 6, 2026

Thanks @mayagbarnes for the quick reviews!
I'm wondering when this fix will be in the release. Will there be a quick patch release soon, or be in the next monthly minor release? Thank you!

@mayagbarnes
Copy link
Collaborator

The current plan is to have the 1.53 release next week (this fix would be included) - but please note this is subject to change

majiayu000 pushed a commit to majiayu000/streamlit that referenced this pull request Jan 9, 2026
When the app is embedded, always honor the query params to choose the theme, especially when the app has custom themes.

This allows the host to sync the themes between the host app and the embedded Streamlit app for consistency. This is critical when the host app manages the theme selection itself.

The cached theme selection in the local storage may be set when user visit the Streamlit app directly from a different interface. It should only be honored when the embedding option not present in the URL query param.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

embed_options=dark_theme is not respected when config.toml defines any custom theme.

4 participants