Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styled Component styles are disabled in Chrome DevTools

Tags:

I am working on a static page that uses React, Gatsby, and styled-components.

When styling a page, my development workflow usually heavily involves Chrome DevTools, tweaking styles there until I have something that I like, and then implementing them in the code.

When using styled-components, however, all of the styles/rules that appear in DevTools for each rendered element are grey, italicized, and disabled. I can override them by adding styles in element.style {}, but that can be a pain, and it doesn't solve the root question which is: why are styles applied by styled-components disabled in DevTools?

Here's a screenshot of what I'm referring to. screenshot

like image 290
lusk Avatar asked Jul 26 '18 17:07

lusk


People also ask

Can I use CSS with styled-components?

Integrating an existing CSS framework with styled-components is really easy! You can use its existing class names alongside your components. For example, imagine you have an existing app with two classes you want to use again: .

How do you override styles in styled-components?

You can override an existing styled-components component by passing it to the styled() constructor/wrapper. For example, suppose you have the following styled button element: const Button = styled.

Can you use material UI with styled-components?

Change the default styled engine By default, MUI components come with Emotion as their style engine. If, however, you would like to use styled-components , you can configure your app by following the styled engine guide or starting with one of the example projects: Create React App with styled-components.


1 Answers

It's because styled-components injects styles through the CSSOM API, which the Dev Tools in Chrome (and every other browser AFAIK) can't handle. See this ticket: https://bugs.chromium.org/p/chromium/issues/detail?id=387952

Note that this is only true when styled-components is in production mode, i.e. process.env.NODE_ENV is set to "production". As long as you aren't in production mode, styled-components should generate normal <style> tags, which you can interact with through the Dev Tools.

like image 156
Trevor Burnham Avatar answered Sep 25 '22 00:09

Trevor Burnham