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

Nested selectors not processed #22

Open
goffioul opened this issue Jan 5, 2021 · 5 comments
Open

Nested selectors not processed #22

goffioul opened this issue Jan 5, 2021 · 5 comments

Comments

@goffioul
Copy link

goffioul commented Jan 5, 2021

In a simple MaterialUI v5 demo app (https://codesandbox.io/s/material-rtl-nested-selector-1qtmo), it seems that nested selectors are not processed by the plugin. Using something like the following snippet, the table element gets flipped CSS, while thead and td/th do not.

const styles = {
  width: 1,
  textAlign: "left",
  "& thead": {
    textAlign: "left"
  },
  "& th, & td": {
    paddingLeft: 1
  }
};

function App() {
  return (
    <Box component="table" sx={styles}>
      <thead>
        <tr>
          <th>Hello TH</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Hello TD</td>
        </tr>
      </tbody>
    </Box>
  );
}

Note: This was initially reported in mui/material-ui#24270 (comment)

@oliviertassinari
Copy link

@goffioul Could you provide a reproduction that doesn't involve MUI?

@goffioul
Copy link
Author

goffioul commented Jan 5, 2021

https://codesandbox.io/s/emotion-rtl-nested-selector-xcgrm

@goffioul
Copy link
Author

goffioul commented Jan 5, 2021

This is just a wild guess, but I've done some debugging in the above sandbox. What appears to be happening, is that when function stylisRTLPlugin is called for, let's say, the & thead rule element, the following condition is false:

element.type === KEYFRAMES || (element.type === RULESET && (!element.parent || element.parent.type === MEDIA))

Indeed, even though the element is of type RULESET, it has a non-null parent, which is not of type MEDIA (it's also of type RULESET). Hence CSSJanus transformation is not applied.

@oliviertassinari
Copy link

oliviertassinari commented Feb 8, 2021

This bug impacts the Grid component too. It can be seen on http://next.material-ui.com/components/grid/#basic-grid. It was first reported in emotion-js/emotion#2156.

@mnajdova
Copy link

mnajdova commented Apr 9, 2021

The bug was fixed by #21 @probablyup it can probably be closed.

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

No branches or pull requests

3 participants