Skip to content

fix(theme): reset to default theme on setTheme(null) and warn on unregistered names - #21781

Open
schizophrenicmaniac wants to merge 1 commit into
apache:masterfrom
schizophrenicmaniac:fix/21779-bug-settheme-with-no-theme-null-or-an
Open

schizophrenicmaniac wants to merge 1 commit into
apache:masterfrom
schizophrenicmaniac:fix/21779-bug-settheme-with-no-theme-null-or-an

Conversation

@schizophrenicmaniac

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Makes setTheme(undefined | null) go back to the default theme and logs a dev warning when setTheme gets a theme name that isn't registered.

Fixed issues

Details

Before: What was the problem?

_updateTheme only assigned this._theme when the argument resolved to a truthy theme. So setTheme(undefined), setTheme(null) and setTheme('<unregistered name>') all left the previous theme in place with no warning. That meant a chart started with 'dark' couldn't go back to the default theme this way, even though init(dom, undefined) means "default theme".

After: How does it behave after the fixing?

null/undefined now resets the theme to the default ({}), the same as init without a theme. An unregistered name logs Theme xxx is not registered. in dev mode and keeps the current theme, the same way other invalid arguments are handled (e.g. showLoading with an unknown effect). Registered names and theme objects work as before.

I added unit tests in test/ut/spec/api/setTheme.test.ts for all three cases.

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

test/ut/spec/api/setTheme.test.ts

Merging options

  • Please squash the commits into a single one when merging.

Other information

Fixes #21779

@echarts-bot

echarts-bot Bot commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] setTheme() with no theme, null or an unregistered name silently keeps the current theme

1 participant