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

Interpolation in styled template literal doesn't support values or expressions #197

Closed
jaredcrowe opened this issue May 25, 2020 · 4 comments · Fixed by #198
Closed

Interpolation in styled template literal doesn't support values or expressions #197

jaredcrowe opened this issue May 25, 2020 · 4 comments · Fixed by #198
Labels
bug 🐛 Something isn't working

Comments

@jaredcrowe
Copy link

jaredcrowe commented May 25, 2020

Describe the bug
When using the styled component API, expression interpolation only seems to work when using inline functions or a variable that points to a value.

To Reproduce
The following compiles successfully but produces broken CSS:

const Div = styled.div`
  border-radius: ${2 + 2}px;
`;
const br = 2 + 2;
const Div = styled.div`
  border-radius: ${br}px;
`;

The following fails to compile:

const Div = styled.div`
  border-radius: ${4}px;
`;
const Div = styled.div`
  border-radius: ${'4'}px;
`;
const Div = styled.div`
  border-radius: ${`${4}`}px;
`;
const getBr = () => 4;
const Div = styled.div`
  border-radius: ${getBr}px;
`;

These work correctly, however:

const br = 4;
const Div = styled.div`
  border-radius: ${br}px;
`;
const Div = styled.div`
  border-radius: ${() => 2 + 2}px;
`;

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome
  • Version: 0.3.2
@itsdouges
Copy link
Collaborator

itsdouges commented May 25, 2020

Thanks mate!

Can you double check if this works?

const br = 2 + 2;
const Div = styled.div`
  line-height: ${br};
`;

I'll also release the latest version of Compiled just to make sure.

edit:

To github.com:atlassian-labs/compiled-css-in-js.git

  • [new tag] v0.4.0 -> v0.4.0

done

@itsdouges itsdouges added the bug 🐛 Something isn't working label May 25, 2020
@jaredcrowe
Copy link
Author

That doesn't work in v0.3.2 either. It compiles but breaks the styles.

Just tried upgrading to v0.4 and I get an Element type is invalid runtime error in the component even when not using interpolation 😬

@itsdouges
Copy link
Collaborator

itsdouges commented May 25, 2020

I'll look into it 👍

Stick to 0.3 for now - if you can track down what's blowing up lmk. The website (https://compiledcssinjs.com/) is on the latest version as well 🤔

@itsdouges
Copy link
Collaborator

I have a PR up here #198 to fix it 👍

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

Successfully merging a pull request may close this issue.

2 participants