styled-components / xstyled

A utility-first CSS-in-JS framework built for React. πŸ’…πŸ‘©β€πŸŽ€βš‘οΈ
https://xstyled.dev
MIT License
2.27k stars 106 forks source link

rpxTransformers not working as expected in V3 #274

Closed SpicyPete closed 3 years ago

SpicyPete commented 3 years ago

πŸ’₯ Regression Report

After upgrading from 2.5.0 to 3.0.1, all of my unitless elements are no longer being converted to rem, but rather get rendered as their unitless value, which leads to a broken layout.

Last working version

Worked up to version: 2.5.0

Stopped working in version: 3.0.1

To Reproduce

Add rpxTransformers to your theme object.

import { defaultTheme, DefaultTheme, rpxTransformers } from '@xstyled/styled-components'
// import { rpxTransformers } from '@xstyled/system'

const bhsTheme: DefaultTheme = {
  ...defaultTheme,
    transformers: {
      ...rpxTransformers,
    },
    sizes: {
      ...defaultTheme.sizes,
      cardWidth: 320 - 32,
      }
  }

note - rpxTransformers is now imported from @xstyled/styled-components instead of @xstyled/system as before. Didn't see this documented in the migration guide, but this page indicate this change.
The same issue persists importing this either way.

Create a component using this feature, example.

const ToolsArea = styled.divBox`
  display: grid;
  grid-template-columns: 1fr;
  gap: 8;
  @media (min-width: md) {
    gap: 120;
    height: 5000;
    grid-template-columns: repeat(
      auto-fit,
      minmax(${th.size('cardWidth')}, 1fr)
    );
  }
`

Expected behavior

gap: 8 maps to the default theme size key, and works as expected (2 rem). gap: 120 doesn't map to a theme value, so I expect it to be converted to the rem equivalent, but it comes out as gap: 120, which is an invalid value.

  1. grid-template-columns uses a size from my theme, but the value does not get converted to it's rem equivalent (7.5rem), but instead comes out as... grid-template-columns: repeat( auto-fit,minmax(288,1fr) );

  2. Put in height for the example, which also doesn't convert. height: 5000; vs the expected height: 312.5rem;

npx envinfo --system --binaries --npmPackages @xstyled/system,@xstyled/styled-components,styled-components --markdown --clipboard

Paste the results here:

## System:
 - OS: macOS 11.2.3
 - CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
 - Memory: 521.88 MB / 8.00 GB
 - Shell: 5.8 - /bin/zsh
## Binaries:
 - Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
 - Yarn: 1.22.5 - ~/.yarn/bin/yarn
 - npm: 6.14.6 - ~/.nvm/versions/node/v12.16.1/bin/npm
 - Watchman: 4.9.0 - /usr/local/bin/watchman
## npmPackages:
 - @xstyled/styled-components: ^3.0.1 => 3.0.1 
 - styled-components: ^5.3.0 => 5.3.0
P1X3L commented 3 years ago

@gregberge I don't know if it'll help but you can reproduce on your playground by modifying line 25 my={15} fails to convert to rem (it converts to 15px), where your default my={20} correctly converts to 5rem. Some values are correctly converted to rems, some aren't. πŸ€·β€β™‚οΈ Hope this helps…