Skip to content

Conversation

shanshrew
Copy link
Contributor

What is this change?

  • Adds SWC support via combination of manual and vibe coding.
  • Adds tests of babel-plugin to swc-plugin and verifies they all pass.
  • Meticulously tested the .wasm binary in a parcel-transform-swc step that will come in another PR.

Why are we making this change?

  • Babel plugin accounts for roughly 40% of the build (based on my rough testing) this improves the performance by up to 9x which is a multi-million dollar cost saving.

How are we making this change?

Change will be rolled out in 3 parts.

  1. swc-plugin PR merged
  2. parcel-transform-swc PR merged, verified in JIRA which will make sure the output is completely identical to the babel plugin.
  3. atlaspack core rollout (potentially) PR

PR checklist

Don't delete me!

I have...

  • [ x] Updated or added applicable tests
  • [ x] Updated the documentation in website/ When it's verified stable
  • [ x] Added a changeset (if making any changes that affect Compiled's behaviour)

Copy link

changeset-bot bot commented Aug 4, 2025

⚠️ No Changeset found

Latest commit: 7ca42fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Aug 4, 2025

Deploy Preview for compiled-css-in-js canceled.

Name Link
🔨 Latest commit 7ca42fc
🔍 Latest deploy log https://app.netlify.com/projects/compiled-css-in-js/deploys/68a501b1f3132c00089aa5c7

@yamadapc yamadapc self-requested a review August 5, 2025 02:11
Copy link
Collaborator

@kylorhall-atlassian kylorhall-atlassian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To hoist the comment—this is an "experimental dev-only package" right?

The StrictMode syntax mostly looks good, it's a great start. I think the only thing I'd like is that const padding = '8px'; local reusability.

Issues:

  • The hashes are wrong!
  • Could use validation of sorting (it's more important than it may seem)
  • What about sorting? I'm not 100% certain how it works.

},
"peerDependencies": {
"@swc/core": ">=1.3.0",
"react": ">=16.8.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we need a peer dep here actually, but ^18.2.0 to match Atlassian…unless Compiled has this peer dep elsewhere then just match it.

export interface CompiledSwcPluginOptions {
/**
* Import sources to transform CSS-in-JS from
* @default ["@compiled/react"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I defaulted this to ["@compiled/react", "@atlaskit/css"] elsewhere, could you check and match?

* Prefix for generated classes' hashes
* @default undefined
*/
classHashPrefix?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see dropping this in here, shouldn't be used in the first place.

* Whether to process xcss usages
* @default true
*/
processXcss?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see dropping this in here, shouldn't be overridden in the first place.

* Prefix for generated CSS class names
* @default "_"
*/
classNamePrefix?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see dropping this in here, shouldn't be overridden in the first place.

});
`;
const out = await transformResultString(code);
expect(out).toMatchInlineSnapshot(`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way for a friendlier message, eg. I saw the "…not supported in Strict Mode…" before?


const theme = { colors: { primary: 'red' } };
const styles = css({
color: theme.colors.primary
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might actually require refactor in a few places, but sparingly, that's fine.

const primaryColor = 'red';
const styles = cssMap({
primary: {
color: primaryColor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will definitely break in a few places, this is a "supported value" by default, it'd be ideal if at a minimum, this was supportable, because it's the only option (barring token(…) babel plugin type effort) for value reuse—local reuse is fairly necessary.

});
});

describe('Comparison with Babel Plugin Behavior', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't particularly do what it says ti? Eg. the hashes are wrong.

Be lovely if it could be 100% hooked up, then we could just have a huge css({ … }) edge-case call and compare it 1:1!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another dumb comment, what about sorting? Does <CC> and <CS> do this and we don't have to build it into the plugin (unless we're doing extraction into CSS files?)

See: https://github.com/atlassian-labs/compiled/blob/master/packages/css/src/plugins/sort-atomic-style-sheet.ts, but I don't recall where/how that's used in Babel.

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

Successfully merging this pull request may close these issues.

2 participants