Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useRootStyles: false disables whole theme #2516

Closed
pietrofxq opened this issue Sep 12, 2024 · 5 comments · Fixed by #2519
Closed

useRootStyles: false disables whole theme #2516

pietrofxq opened this issue Sep 12, 2024 · 5 comments · Fixed by #2519

Comments

@pietrofxq
Copy link

Describe the bug
When using useRootStyles: false, the default theme is not returned and variables in components do not work. The issue is here:

if (!colors || useRootStyles === false) return {}

I am not sure if we need to check useRootStyles at all here, the documentation says this property is only to avoid applying styles in the html, not that it would prevent the color mode from working

To Reproduce
Steps to reproduce the behavior:

  1. set useRootStyles: false in theme
  2. try to access a variable in a component, or check the devtools:
    image

Expected behavior
useRootStyles: false should not prevent variables from being defined

@hasparus
Copy link
Member

What framework are you using?

@pietrofxq
Copy link
Author

pietrofxq commented Sep 19, 2024

Developing a chrome extension with react, I used patch-package to make it work correctly by changing this:

-  if (!colors || useRootStyles === false) return {};
+  if (!colors) return {};
   return css({
     ...styles,
-    color: colorToVarValue('text'),
-    bg: colorToVarValue('background')
+   ...(useRootStyles ? {color: colorToVarValue("text"), bg: colorToVarValue('background')} : {})
   })(theme);

@hasparus
Copy link
Member

the documentation says this property is only to avoid applying styles in the html, not that it would prevent the color mode from working

Okay, I get it. So this function is used only to affect the global style for html element, which is why it was disabled like that, but you don't have a nested ColorModeProvider so there's nothing providing color variables for you.

It starts working again if you add a nested ThemeUIProvider or turn config.useCustomProperties to false, but it is in fact a bug.

Thanks! Good catch.

CodeSandbox

@hasparus
Copy link
Member

@pietrofxq #2519 should solve this.

@pietrofxq
Copy link
Author

awesome thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants