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.

Formatting incorrect using styled-component component selector pattern

See original GitHub issue

Prettier 2.0.1 Playground link

--parser babel

Input:

const Icon = styled.div`
  flex: none;
  transition: fill 0.25s;
  width: 48px;
  height: 48px;

  ${Link}:hover {
    fill: rebeccapurple;
  }
`;

Output:

const Icon = styled.div`
  flex: none;
  transition: fill 0.25s;
  width: 48px;
  height: 48px;

  ${Link}: hover{
    fill: rebeccapurple;
  }
`;

Expected behavior:

const Icon = styled.div`
  flex: none;
  transition: fill 0.25s;
  width: 48px;
  height: 48px;

  ${Link}:hover {
    fill: rebeccapurple;
  }
`;

When using the component selector pattern from styled-components, I am seeing an issue with the formatting of the output CSS. This above is a slightly modified example from the documentation. Note that if I included an & to the selector (before the curly brace) it will format correctly (e.g., ${Link}:hover &).

The examples I am seeing in my own application are being formatted:

${DataCell}: empty: before{
${Tab}: first-child{
${Tab}:nth-child (2) {

All of which I would expect to break styling behavior.

Love the new update, though! The Prettier team must have worked incredibly hard to make so many impressive improvements.

Thank you for your time.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
marclemagnecommented, Mar 23, 2020

Thank you for addressing so quickly!

0reactions
alexander-akaitcommented, Mar 26, 2020

@thorn0 yes, I think it will save the situation, that’s why I didn’t want to update postcss-less, as a contributor stylelint I have already raised more than once the question of forking a project and rewriting, maybe we should rush it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Usage - styled-components
styled -components has full theming support by exporting a <ThemeProvider> wrapper component. This component provides a theme to all React components underneath ...
Read more >
Demystifying styled-components - Josh W Comeau
In this post, we'll learn exactly how styled-components works by ... it to a React component, bypassing the CSS selectors we've always used....
Read more >
Before and After pseudo classes used with styled-components
Pseudo-selectors in styled-components work just like they do in CSS. (or rather, Sass) Whatever isn't working is likely a problem in your ...
Read more >
How To Use React Styled Components Efficiently - Copycat
Using styled -components makes it simple to use actual CSS to style components by writing JavaScript code. These components are known as “styled ......
Read more >
Styled Components: Enforcing Best Practices In Component ...
Because styled-components is just CSS, it supports all of CSS perfectly fine. Media queries, pseudo-selectors, even nesting just work. We are ...
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