Skip to content

feat(babel-plugin): support top-level @starting-style in cssMap - #1981

Open
officialasishkumar wants to merge 1 commit into
atlassian-labs:masterfrom
officialasishkumar:support-top-level-starting-style-in-css-map
Open

officialasishkumar wants to merge 1 commit into
atlassian-labs:masterfrom
officialasishkumar:support-top-level-starting-style-in-css-map

Conversation

@officialasishkumar

Copy link
Copy Markdown

What is this change?

Adds support for declaring @starting-style directly inside a cssMap variant (not nested within another at-rule or selector), and updates the cssMap types so the block is typed as styles.

Fixes #1788

Why are we making this change?

cssMap treats at-rules as having two halves ('@media': { 'screen and ...': {...} }) and merged every child key into the at-rule name. @starting-style has no prelude, so { '@starting-style': { color: 'blue' } } was rewritten into the key @starting-style color, producing the invalid sheet @starting-style color: blue{} with no class name. The types had the same two-halves assumption. Only the nested form worked.

How are we making this change?

  • mergeExtendedSelectorsIntoProperties passes at-rules without a prelude through unchanged, keeping duplicate detection (including against the selectors object) and erroring when the value isn't an object.
  • cssMap/cssMapScoped types accept styles (and pseudo selectors) directly under '@starting-style'.
  • Tests: replaced the TODO in the babel-plugin tests with coverage for cssMap, cssMapScoped, the selectors object and both error cases, plus type tests.
  • Docs in api-cssmap.mdx and a changeset.

Three module traversal tests in packages/babel-plugin fail in my environment with and without this change.


PR checklist

I have...

  • Updated or added applicable tests
  • Updated the documentation in website/
  • Added a changeset (if making any changes that affect Compiled's behaviour)

cssMap treated every at-rule key listed in its at-rule table as having
two halves (`'@media': { 'screen and ...': { ... } }`) and merged each
child key into the at-rule name. `@starting-style` has no prelude, so a
variant such as `{ '@starting-style': { color: 'blue' } }` was rewritten
to the key `@starting-style color` with a string value, which ended up
as the invalid sheet `@starting-style color: blue{}` and no class name.
Only the nested form (inside another at-rule) worked.

- Add a list of at-rules without a prelude and, in
  mergeExtendedSelectorsIntoProperties, pass those blocks through
  unchanged so buildCss handles them like any other nested block. Keep
  the duplicate detection (including against the `selectors` object) and
  report a clear error when the value is not an object.
- Update the cssMap / cssMapScoped types so `@starting-style` directly
  contains styles (and pseudo selectors) instead of a record of
  preludes, and add type tests for valid and invalid usage.
- Replace the TODO in the babel-plugin tests with real coverage for
  cssMap and cssMapScoped, the `selectors` object, the duplicate error
  and the non-object error.
- Document the syntax in the cssMap API docs and add a changeset.
@atlassian-cla-bot

Copy link
Copy Markdown

Thank you for your submission! Like many open source projects, we ask that you sign our CLA (Contributor License Agreement) before we can accept your contribution.
If your email is listed below, please ensure that you sign the CLA with the same email address.

The following users still need to sign our CLA:
❌officialasishkumar

Already signed the CLA? To re-check, try refreshing the page.

@netlify

netlify Bot commented Nov 19, 2026

Copy link
Copy Markdown

👷 Deploy request for compiled-css-in-js pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit f03058a

@changeset-bot

changeset-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f03058a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@compiled/babel-plugin Minor
@compiled/react Minor

Not sure what this means? Click here to learn what changesets are.

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

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.

Add support for @starting-style at-rule **when not nested**

1 participant