Repository: streamlit/streamlit
File: frontend/app/src/App.test.tsx (TypeScript)

Code before:
        primaryColor: "blue",
        light: {
          backgroundColor: "white",
        },
        dark: {
          backgroundColor: "black",
        },
      })

      sendForwardMessage("newSession", {
        ...NEW_SESSION_JSON,
        customTheme,
      })

      // Should apply Custom Theme Dark (from embed_options), not Light (from cache)
      expect(props.theme.setTheme).toHaveBeenCalled()
      const appliedTheme = vi.mocked(props.theme.setTheme).mock.calls[0][0]
      expect(appliedTheme.name).toBe(CUSTOM_THEME_DARK_NAME)
      expect(appliedTheme.emotion.colors.bgColor).toBe("black")
    })

    it("falls back to cached preference when no embed_options", () => {
      // Set cached theme to dark
      const cachedTheme: CachedTheme = {
        name: CUSTOM_THEME_DARK_NAME,
      }
      window.localStorage.setItem(
        LocalStore.ACTIVE_THEME,
        JSON.stringify(cachedTheme)
      )

      // No query params
      setLocationSearch("")

      const props = getProps()
      renderApp(props)

      // Send custom theme config
      const customTheme = new CustomThemeConfig({
        primaryColor: "blue",
        light: {
          backgroundColor: "white",
        },
        dark: {
          backgroundColor: "black",
        },
      })

      sendForwardMessage("newSession", {
        ...NEW_SESSION_JSON,
        customTheme,

Review comment (performance):
**Nit**: same
```javascript
// Set cached theme to dark (with required themeInput for custom themes)
const cachedTheme: CachedTheme = {
  name: CUSTOM_THEME_DARK_NAME,
  themeInput: { primaryColor: "blue" },
}
```

Code after:

      // Send custom theme config with light and dark sections
      sendForwardMessage("newSession", {
        ...NEW_SESSION_JSON,
        customTheme,
      })

      // Should apply Custom Theme Dark (from embed_options), not Light (from cache)
      expect(props.theme.setTheme).toHaveBeenCalled()
      const appliedTheme = vi.mocked(props.theme.setTheme).mock.calls[0][0]
      expect(appliedTheme.name).toBe(CUSTOM_THEME_DARK_NAME)
      expect(appliedTheme.emotion.colors.bgColor).toBe("black")
    })

    it("falls back to cached preference when no embed_options", () => {
      // Set cached theme to dark
      window.localStorage.setItem(
        LocalStore.ACTIVE_THEME,
        JSON.stringify(cachedDarkTheme)
      )

      // No query params
      setLocationSearch("")

      const props = getProps()
      renderApp(props)

      // Send custom theme config
      sendForwardMessage("newSession", {
        ...NEW_SESSION_JSON,
        customTheme,
      })

      // Should apply cached Custom Theme Dark
      expect(props.theme.setTheme).toHaveBeenCalled()
      const appliedTheme = vi.mocked(props.theme.setTheme).mock.calls[0][0]
      expect(appliedTheme.name).toBe(CUSTOM_THEME_DARK_NAME)
    })

    it("maps embed_options to preset theme when custom theme removed", () => {
      // Mock query params with dark_theme
      setLocationSearch("?embed=true&embed_options=dark_theme")

      const props = getProps()
      props.theme.activeTheme = {
        name: CUSTOM_THEME_DARK_NAME,
        displayName: "Dark",
        emotion: { ...darkTheme.emotion },
        basewebTheme: darkTheme.basewebTheme,
        primitives: darkTheme.primitives,
        themeInput: customTheme,