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

Adding styles to theme object implicitly overwrites root #2130

Open
vfilter opened this issue Feb 11, 2022 · 1 comment
Open

Adding styles to theme object implicitly overwrites root #2130

vfilter opened this issue Feb 11, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@vfilter
Copy link

vfilter commented Feb 11, 2022

Describe the bug
Recently added mdx files to an existing project, so to style them, I added a styles object to my theme. Only defined h1, h2 and p properties. But adding the styles object, even if empty, created an inexplicable 8 pixel margin around every single page.

Then I found out that 8 pixel is the browser default for the user agent stylesheet and that it would have to be manually set to 0. The problem was, that I didn't change the root style and that the Theme UI docs say that the global style will not be polluted by the styles object in the theme.

Apparently, however, once the styles property is added to the theme, it reverts the style for the html root to the default, which is 8 pixel. My options were to either delete the styles object completely, or add a root property with margin: 0.

Expected behavior
I would expect adding the styles object to only change the root stylesheet once it has the root property, and otherwise do not alter the current style of the root element.

@lachlanjc lachlanjc changed the title Adding styles to theme object implicitly creates root Adding styles to theme object implicitly overwrites root Feb 21, 2022
@lachlanjc lachlanjc added the bug Something isn't working label Feb 21, 2022
@lachlanjc
Copy link
Member

That makes a ton of sense! Here's the line of code that's causing this issue: https://github.com/system-ui/theme-ui/blob/develop/packages/theme-provider/src/index.tsx#L19

I'm not sure why it's written that way, but goes way back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants