Skip to content

fix(server): retain keyframes across animation shorthand components - #1537

Merged
Anber merged 2 commits into
callstack:masterfrom
pcbeingused333:fix/c2799-animation-keyframes
Nov 23, 2026
Merged

Anber merged 2 commits into
callstack:masterfrom
pcbeingused333:fix/c2799-animation-keyframes

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Motivation

Critical CSS collection in @linaria/server drops referenced @keyframes when the animation name is not the first space-separated word of the declaration, or when a declaration lists several animations. For example, animation: 1s linear spin loses @keyframes spin (while animation: spin 1s linear keeps it), so the element does not animate until the rest of the CSS loads. With animation: spin 1s, fade 2s, only spin is kept; animation-name: spin, fade keeps neither.

The cause is decl.value.split(' ')[0] in collect.ts, which only takes the first word of the whole value.

Summary

Collect candidate names from every comma-separated animation and every whitespace-separated component, using postcss.list.comma / postcss.list.space (which keep steps(2, end) and cubic-bezier(...) intact). The tokens are still only matched against the names of existing @keyframes rules, so unreferenced keyframes stay out of the critical CSS. Includes a patch changeset for @linaria/server.

Test plan

New test.each cases in packages/server/__tests__/collect.test.ts cover duration-first and middle names, tabs and newlines, multiple shorthands, timing functions with commas, and comma-separated animation-name; each also checks that an unused keyframe is not collected. Against the current collect.ts, 6 of the 7 cases fail (only spin 1s linear passes); with the change all 7 pass.

AI assistance: this change and its regression tests were generated with Codex.

@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a68b19a

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

This PR includes changesets to release 9 packages
Name Type
@linaria/server Patch
@linaria/atomic Patch
@linaria/core Patch
@linaria/babel-plugin-interop Patch
linaria Patch
@linaria/postcss-linaria Patch
@linaria/react Patch
@linaria/stylelint-config-standard-linaria Patch
@linaria/stylelint Patch

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

collect drops keyframes that only non-critical rules use from both
outputs, so other never contains them. That is a separate issue, and the
assertion would lock it in. The new cases still check which keyframes go
to the critical CSS.

@Anber Anber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix and the thorough cases! I pushed one small change to the new test: it no longer asserts that other has no @keyframes. Today collect drops keyframes that only non-critical rules use from both outputs, which is a separate bug, and that assertion would have locked it in. The check that unused keyframes stay out of the critical CSS is unchanged.

@Anber
Anber merged commit c51dfe9 into callstack:master Nov 23, 2026
4 checks passed
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