Skip to content

Releases: atlassian-labs/compiled

v0.4.0

25 May 08:28
Compare
Choose a tag to compare

Breaking changes

PostCSS (#175)

Internally we've replaced stylis with post-css - as a consumer of Compiled you shouldn't notice any difference (but if you do please raise an issue!). This change paves the way for more interesting CSS plugins down the track, and also enables more powerful customization of autoprefixer, minification, and more.

Package export renaming (#187)

  • @compiled/style's default export has been removed and replaced with the CS export
  • @compiled/css-in-js's named export Style has been renamed to CS

New features

Constant inlining (#178)

Interpolations that reference simple variables (a string or number) will now be inlined directly in your CSS instead of being references as a CSS variable!

Before:

const color = 'blue';

<span css={{ color  }} />

// Transforms to css with dynamic property
<style>{['.cc-1sbi59p { color: var(----var-1ylxx6h); }']}</style>
<span style={{ '--var-1ylxx6h': color }} className="cc-1sbi59p" />

After:

const color = 'blue';

<span css={{ color }} />

// Transforms to static property
<style>{['.cc-1sbi59p { color: blue; }']}</style>
<span className="cc-1sbi59p" />

Thanks @ankeetmaini!

Bug fixes

Destructured variable idenfitiers (#185)

Previously when referencing a de-structured variable identifier it would blow up - this is fixed now!

const [color] = ['blue'];

<div css={{ color: `${color}` }}>hello world</div>

Thanks @ankeetmaini!

Chores

  • Jest matcher types were consolidated thanks @jdanil #180
  • Documentation was updated to point to the correct transformer section thanks @gwyneplaine #181

v0.3.2

26 Apr 07:48
Compare
Choose a tag to compare

New features

Jest matcher improvements (#168)

The jest matcher @compiled/jest-css-in-js has been improved thanks to @ankeetmaini! It now parses the CSS into an AST which enabled some cool improvements.

Notably, we can now narrow the assertion using target and/or media options like so:

expect(element).toHaveCompiledCss('color', 'blue', { target: '&:hover' });

For more information see the website https://compiledcssinjs.com/docs/testing

v0.3.1

25 Apr 11:11
Compare
Choose a tag to compare

New features

Dead code elimination (#169)

The Styled Component API now prepends a pure pragma to ensure bundlers know it's safe to get rid of when it hasn't been used! You can find the test code for it here which is then passed through size-limit to ensure it's the size we expect.

image

Bug fixes

Template literal interpolations

These interpolations now are correctly extracted when in a group, and multiple groups. CSS that broke before looked like:

<div
  css={`
    transform: translate3d(${x}, ${y}, ${z});
  `}
/>

Fear not! It should work as expected now. If you see anything interesting create an issue.

De-duplicated interpolations

Previously if the same interpolation was used multiple times the inline style prop would have it duplicated.

Css prop class name

When a css prop was passed a class name it wouldn't conditionally apply it - so it would end up appearing as undefined when it shouldn't!

v0.3.0

22 Apr 11:59
Compare
Choose a tag to compare

We're continuing the story of getting the basic features that we all expect from a modern CSS in JS library. This release has a juicy new feature, a DX improvement, and some bundle size wins!

New features

SSR but smaller (#156)

When server side rendering you will now only render the smallest amount of CSS - and you don't have to do anything to enable this! It will happen immediately after upgrading.

Say we're rendering this:

const StyledParent = styled.div`
  display: flex;
`;

const StyledDiv = styled.div`
  font-size: 12px;
`;

<StyledParent>
  <StyledDiv>hello world</StyledDiv>
  <StyledDiv>hello world</StyledDiv>
</StyledParent>

On the server before you'd get this HTML:

<style>.cc-10mivee{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}</style>
<div class="cc-10mivee">
  <style>.cc-1610nsm{font-size:12px;}</style>
  <div class="cc-1610nsm">hello world</div>
  <style>.cc-1610nsm{font-size:12px;}</style>
  <div class="cc-1610nsm">hello world</div>
</div>

Now we get...

<style>.cc-10mivee{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}</style>
<div class="cc-10mivee">
  <style>.cc-1610nsm{font-size:12px;}</style>
  <div class="cc-1610nsm">hello world</div>
-  <style>.cc-1610nsm{font-size:12px;}</style>
  <div class="cc-1610nsm">hello world</div>
</div>

If we extrapolate this out at scale - we're now saving a lot of Kb 🥳.

Developer experience

Source maps #153

Source map support has landed!

chrome-smp

You can turn them on in your transformer options like so:

{
  "plugins": [["@compiled/babel-plugin-css-in-js", { "sourceMap": true }]]
}
{
  "compilerOptions": {
    "plugins": [
      {
        "transform": "@compiled/ts-transform-css-in-js",
        "options": {
          "sourceMap": true
        }
      }
    ]
  }
}

Make sure to only turn them on in development! Else suffer a big bundle. Note source maps are currently only working in Chrome - we have a bug open for Firefox here.

Misc

Bundle size

The bundle size for @compiled/style has been reduced from 423 B to 323 B! Pretty chuffed TBH.

v0.2.15 | Atlassian ShipIt 48 🥳

17 Apr 08:38
Compare
Choose a tag to compare

So @Madou @flexdinesh and @danieldelcore worked over hackathon to smash out bugs, add new features, improve the testing story, and get some huge DX wins. Check it out! 👏

New features

CSP nonce (#146)

@Madou added content security policy nonce support, you can use it by setting the nonce option in both the Babel plugin or TypeScript transformer:

// .babelrc
{
  "plugins": [["@compiled/babel-plugin-css-in-js", { "nonce": "__webpack_nonce__" }]]
}
// tsconfig.json
{
  "compilerOptions": {
    "plugins": [
      {
        "transform": "@compiled/ts-transform-css-in-js",
        "options": {
          "nonce": "__webpack_nonce_"
        }
      }
    ]
  }
}

Not sure what content security policy aka CSP is? Have a read here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP. It allows us to be explicit about what can and can't run - JavaScript, styles, images even!

For us and styles it's about using the style-src part. So we could have a meta tag in our HTML head:

<meta
  http-equiv="Content-Security-Policy"
  content="style-src 'nonce-k0Mp1lEd' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;"
/>

Notice the nonce is k0Mp1lEd. Using the settings above if we imagine __webpack_none__ ends up resolving this string, we'll end up rendering style elements that look like:

<style none="k0Mp1lEd"></style>

And thus the styles will be allowed to render! But if the nonce did not match.. well.. the styles would be blocked by the browser!

Jest matcher can now assert not! (#140)

@danieldelcore added the ability for us to not our assertions now! And did some extra cleanup and added tests. What a guy!

expect(compiledComponent).not.toHaveCompiledCss('font-size', '12px');

Bug fixes

Template literal dynamic values (#150)

@flexdinesh fixed dynamic template literals not being compiled correctly!

Now you can use dynamic values inside calc CSS values and the like and it will correctly be transformed into a CSS variable.

<div
  css={{ marginLeft: `calc(100% - ${heading.depth}rem)` }}
/>

Which would end up rendering the CSS

.cc-112AS {
  margin-left: calc(100% - var(--var-asA23);
}

Remove potential for hash collisions with Emotion (#136)

@flexdinesh removes the potential for collisions with Emotion by renaming the prefix we use from css to cc (Compiled Component). Dope!

Removing jest types from css in js library (#148)

@Madou removed duplicate types for the jest matcher that were in @compiled/css-in-js!
Still need them? They're where they belong inside @compiled/jest-css-in-js.

Jest matcher can't find multiple style tags (#147)

@danieldelcore fixed the jest matcher util available in @compiled/jest-css-in-js to now correctly pick up style declarations when they're spread over multiple styles.

image

Remove unneeded prefix (#141)

@danieldelcore removed the cc prefix from the hash added to Compiled Components - to save some bytes!

image

Developer experience

Jest typeahead plugin (#134)

@danieldelcore added the ability to find tests while developing Compiled a bit easier!

image

Eslint (#149)

@danieldelcore added eslint which will run both in CI and as a pre-commit hook. It's watching you 👀.

Styled components display names (#145)

@Madou added display names to styled components that will only be applied in dev. When you build your code for production it should be dead code that will be eliminated! This is super useful for local development.

const Highlight = styled.div`
  :hover {
    background-color: pink;
  }
`;

image

Runtime warnings (#144)

@Madou added a runtime help that only runs in development to warn you when using unsafe selectors such as :first and :nth-child.

It'll look like this:

image

Style typing consolidation (#126)

@Madou consolidated all the types for all the APIs. Now they all share the same underlying types so there shouldn't be any inconsistencies for later development.

BREAKING: Removal of jsx pragma

04 Apr 23:05
Compare
Choose a tag to compare

Jsx pragma has been removed - instead it will be activated when any @compiled/css-in-js import is found.

Before

/** @jsx jsx */
import { jsx } from '@compiled/css-in-js';

<div css={{}} />

After

import '@compiled/css-in-js';

<div css={{}} />

There is also an issue to enabled css prop with no import as a configuration option, follow along here: #102

v0.0.9

28 Jan 11:52
Compare
Choose a tag to compare
v0.0.9 Pre-release
Pre-release
0.0.9