question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sx prop does not correctly apply theme in nested ThemeProviders with ColorMode

See original GitHub issue

Describe the bug

When having an application that has a nested ThemeProviders with the same theme and color modes but different values, toggling the colorMode changes the colorMode and theme in both the top level and nested theme provider, but when utilizing that theme in the nested component with the sx prop, the wrong colour gets applied.

To Reproduce Here is a simple codesandbox that reproduces the issue. https://codesandbox.io/s/exciting-banzai-hrjom?file=/src/index.js Expected behavior

In the example provided, I would expect the inner components background value for light mode to be “darkcyan”, and it is if you print out the theme object. But when its applied to the div using sx={{ bg: "background" }} it applies “red”.

Screenshot 2021-01-21 at 11 48 01

Kapture 2021-01-21 at 11 54 02

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hasparuscommented, Jan 22, 2021

@hasparus ?

We could split CollorModeProvider into actual React context provider and consumer? Provide color mode in top level ThemeProvider (from theme-provider package, not core), consume in all ThemeProviders.

0reactions
rezavationcommented, Mar 2, 2021

Hi @hasparus , I didn’t get an opportunity to look at this yet. Is there any chance one of the existing maintainers of theme-ui will be able to tackle it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - sx prop does not correctly apply theme in nested ...
Describe the bug. When having an application that has a nested ThemeProviders with the same theme and color modes but different values, ...
Read more >
MUI component received wrong theme color through SX ...
Either you have incorrectly nested themes, or you have imported a component that ships its own Mui palette... such as components from material- ......
Read more >
Nested Theme Providers - Theme UI
The inner Theme Provider will not create a new color mode state, but inherit this from the parent. Functional Themes. The nested ThemeProvider...
Read more >
Theming with React and MUI - Welcome, Developer
Learn how to create custom themes to React app using MUI. ... The goal of this post is not to dive into the...
Read more >
Upgrading to v1 - Chakra UI
Theme -aware sx prop: Just like theme-ui , we've added support for the sx prop to ... You can skip this if you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found