Skip to content

feat(css-serializer): support custom properties in keyframes#2429

Merged
luhc228 merged 1 commit intolynx-family:mainfrom
usczz:p/zhouzhitao/feature/support_custom_property_keyframe
Apr 8, 2026
Merged

feat(css-serializer): support custom properties in keyframes#2429
luhc228 merged 1 commit intolynx-family:mainfrom
usczz:p/zhouzhitao/feature/support_custom_property_keyframe

Conversation

@usczz
Copy link
Copy Markdown
Collaborator

@usczz usczz commented Apr 7, 2026

  • Extract transformVariables utility function in parse.ts.
  • Add variables field to KeyframesStyle type to store parsed custom properties.
  • Collect CSS variables for each keyframe block in @keyframes rules.
  • Add test cases for @keyframes with CSS variables.

Summary by CodeRabbit

  • New Features
    • Serializer now extracts CSS custom properties for regular rules and for each @Keyframes step, including preservation of "!important", so animated styles receive declared variables.
  • Tests
    • Added test coverage validating that custom properties inside @Keyframes are serialized, encoded/decoded, and applied correctly to animation steps.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 7, 2026

🦋 Changeset detected

Latest commit: b60fc8b

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

This PR includes changesets to release 11 packages
Name Type
@lynx-js/css-serializer Patch
@lynx-js/lynx-bundle-rslib-config Patch
@lynx-js/web-core Patch
@lynx-js/template-webpack-plugin Patch
upgrade-rspeedy Patch
@lynx-js/web-rsbuild-server-middleware Patch
@lynx-js/react-rsbuild-plugin Patch
create-rspeedy Patch
@lynx-js/web-worker-rpc Patch
@lynx-js/react-alias-rsbuild-plugin Patch
@lynx-js/rspeedy 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added a helper to extract custom properties from AST blocks and wired it into parsing for StyleRule and KeyframesRule; KeyframesStyle now includes a variables field. Encoder now emits keyframe variable declarations. Tests include a new keyframes fixture with --bg-color declarations and an encode/decode snapshot test.

Changes

Cohort / File(s) Summary
Parser logic
packages/tools/css-serializer/src/parse.ts
Added transformVariables(block) to collect --* declarations (appends " !important" when applicable) and replaced inline extraction with this helper for StyleRule and KeyframesRule.
Types
packages/tools/css-serializer/src/types/LynxStyleNode.ts
Extended KeyframesStyle to include variables: Record<string,string>.
Encoder
packages/web-platform/web-core/ts/encode/encodeCSS.ts
Keyframes encoding now emits variable declarations by iterating keyframesStyle.variables for each keyframe step.
Tests & Fixtures
packages/tools/css-serializer/test/__preparation__/keyframes.css, packages/web-platform/web-core/tests/encode.spec.ts
Added @keyframes test-keyframe-declaration with --bg-color declarations and a Vitest case to encode/decode keyframes with CSS variables and assert snapshot output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

platform:Web

Poem

🐇 I nibble through the parse and spring,
I gather tiny vars each keyframe brings,
I tuck them in with gentle hop and cheer,
So colors dance when animations appear,
Carrot-coded frames prance far and near 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding support for custom properties (CSS variables) in keyframes, which aligns perfectly with the changeset.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/tools/css-serializer/src/parse.ts`:
- Around line 262-263: transformBlock currently strips custom properties (--*)
so keyframe declarations captured by transformVariables are never serialized;
update the keyframes encoding path to include those variables when emitting
keyframes by merging transformVariables(rule.block) into the serialized style
for keyframes (or adjust the encoder to iterate both keyframesStyle.style and
keyframesStyle.variables). Specifically, where keyframes are built from
keyframesStyle.style, also incorporate keyframesStyle.variables (the output of
transformVariables) so custom properties like --bg-color are preserved for
functions handling serialization; reference transformBlock, transformVariables,
and keyframesStyle.style in your changes.

In `@packages/tools/css-serializer/test/__preparation__/keyframes.css`:
- Around line 37-50: The keyframes fixture fails stylelint: rename the keyframe
identifier testKeyframeDeclaration to a name matching the project's
keyframes-name-pattern (e.g., test-keyframe-declaration) and add the required
empty lines before declarations to satisfy declaration-empty-line-before (ensure
there is a blank line after each opening brace of the keyframe percentage blocks
and before the first declaration, e.g., before --bg-color in the 0%, 50%, and
100% blocks); update the `@keyframes` name in the declaration and any references
accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7d29950a-8472-4a47-9b39-4d52baf2e872

📥 Commits

Reviewing files that changed from the base of the PR and between 55602e2 and bfa01ba.

⛔ Files ignored due to path filters (1)
  • packages/tools/css-serializer/test/__snapshots__/lynx.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • packages/tools/css-serializer/src/parse.ts
  • packages/tools/css-serializer/src/types/LynxStyleNode.ts
  • packages/tools/css-serializer/test/__preparation__/keyframes.css

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 7, 2026

Merging this PR will improve performance by 17.18%

⚡ 1 improved benchmark
✅ 71 untouched benchmarks
⏩ 21 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
transform 1000 view elements 47.4 ms 40.5 ms +17.18%

Comparing usczz:p/zhouzhitao/feature/support_custom_property_keyframe (b60fc8b) with main (b630df2)

Open in CodSpeed

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 7, 2026

Web Explorer

#8719 Bundle Size — 730.24KiB (0%).

b60fc8b(current) vs b630df2 main#8717(baseline)

Bundle metrics  Change 1 change
                 Current
#8719
     Baseline
#8717
No change  Initial JS 43.63KiB 43.63KiB
No change  Initial CSS 2.16KiB 2.16KiB
Change  Cache Invalidation 0% 48.73%
No change  Chunks 8 8
No change  Assets 10 10
Change  Modules 147(-1.34%) 149
No change  Duplicate Modules 11 11
No change  Duplicate Code 34.69% 34.69%
No change  Packages 3 3
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8719
     Baseline
#8717
No change  Other 385.55KiB 385.55KiB
No change  JS 342.53KiB 342.53KiB
No change  CSS 2.16KiB 2.16KiB

Bundle analysis reportBranch usczz:p/zhouzhitao/feature/suppo...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 7, 2026

React External

#263 Bundle Size — 590.57KiB (0%).

b60fc8b(current) vs b630df2 main#261(baseline)

Bundle metrics  no changes
                 Current
#263
     Baseline
#261
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#263
     Baseline
#261
No change  Other 590.57KiB 590.57KiB

Bundle analysis reportBranch usczz:p/zhouzhitao/feature/suppo...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 7, 2026

React Example

#7144 Bundle Size — 236.79KiB (0%).

b60fc8b(current) vs b630df2 main#7142(baseline)

Bundle metrics  no changes
                 Current
#7144
     Baseline
#7142
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 179 179
No change  Duplicate Modules 70 70
No change  Duplicate Code 46.11% 46.11%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#7144
     Baseline
#7142
No change  IMG 145.76KiB 145.76KiB
No change  Other 91.03KiB 91.03KiB

Bundle analysis reportBranch usczz:p/zhouzhitao/feature/suppo...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 7, 2026

React MTF Example

#277 Bundle Size — 206.05KiB (0%).

b60fc8b(current) vs b630df2 main#275(baseline)

Bundle metrics  no changes
                 Current
#277
     Baseline
#275
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 173 173
No change  Duplicate Modules 67 67
No change  Duplicate Code 45.77% 45.77%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#277
     Baseline
#275
No change  IMG 111.23KiB 111.23KiB
No change  Other 94.81KiB 94.81KiB

Bundle analysis reportBranch usczz:p/zhouzhitao/feature/suppo...Project dashboard


Generated by RelativeCIDocumentationReport issue

@usczz usczz force-pushed the p/zhouzhitao/feature/support_custom_property_keyframe branch 2 times, most recently from fe8b3b9 to 20bdd5c Compare April 7, 2026 06:16
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/tools/css-serializer/test/__preparation__/keyframes.css (1)

37-52: Good test coverage for keyframe CSS variables.

This fixture properly exercises the new transformVariables functionality for keyframes, testing custom property declarations alongside var() usage across multiple keyframe blocks.

Minor: Stylelint flags missing empty lines before background-color declarations (lines 40, 45, 50). If the project enforces this rule for test fixtures, consider adding blank lines:

Optional formatting fix
 `@keyframes` test-keyframe-declaration {
   0% {
     --bg-color: red;
+
     background-color: var(--bg-color);
   }

   50% {
     --bg-color: green;
+
     background-color: var(--bg-color);
   }

   100% {
     --bg-color: blue;
+
     background-color: var(--bg-color);
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/tools/css-serializer/test/__preparation__/keyframes.css` around
lines 37 - 52, Test fixture keyframes lack blank lines before the
background-color declarations, which Stylelint flags; update the `@keyframes`
block named test-keyframe-declaration so each keyframe rule (0%, 50%, 100%) has
an empty line between the custom property declaration (--bg-color: ...) and the
background-color: var(--bg-color); line to satisfy the project's formatting
rule.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/tools/css-serializer/test/__preparation__/keyframes.css`:
- Around line 37-52: Test fixture keyframes lack blank lines before the
background-color declarations, which Stylelint flags; update the `@keyframes`
block named test-keyframe-declaration so each keyframe rule (0%, 50%, 100%) has
an empty line between the custom property declaration (--bg-color: ...) and the
background-color: var(--bg-color); line to satisfy the project's formatting
rule.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4d6aa598-bfd8-472e-b2bc-958046e897e6

📥 Commits

Reviewing files that changed from the base of the PR and between fe8b3b9 and 20bdd5c.

⛔ Files ignored due to path filters (1)
  • packages/tools/css-serializer/test/__snapshots__/lynx.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • packages/tools/css-serializer/src/parse.ts
  • packages/tools/css-serializer/src/types/LynxStyleNode.ts
  • packages/tools/css-serializer/test/__preparation__/keyframes.css
✅ Files skipped from review due to trivial changes (1)
  • packages/tools/css-serializer/src/types/LynxStyleNode.ts

@usczz usczz force-pushed the p/zhouzhitao/feature/support_custom_property_keyframe branch from 20bdd5c to 86782a7 Compare April 7, 2026 07:49
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/tools/css-serializer/test/__preparation__/keyframes.css (1)

37-52: ⚠️ Potential issue | 🟡 Minor

Good test coverage, but fix stylelint violations for declaration-empty-line-before.

The fixture correctly tests custom properties in keyframes. The kebab-case naming is compliant, but stylelint flags missing empty lines before background-color declarations at lines 40, 45, and 50.

Proposed fix to satisfy stylelint
 `@keyframes` test-keyframe-declaration {
   0% {
     --bg-color: red;
+
     background-color: var(--bg-color);
   }

   50% {
     --bg-color: green;
+
     background-color: var(--bg-color);
   }

   100% {
     --bg-color: blue;
+
     background-color: var(--bg-color);
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/tools/css-serializer/test/__preparation__/keyframes.css` around
lines 37 - 52, The stylelint rule declaration-empty-line-before is violated for
the background-color declarations inside `@keyframes` test-keyframe-declaration;
fix it by adding a blank line immediately before each background-color
declaration in the 0%, 50%, and 100% keyframe blocks so that the lines with
background-color follow an empty line after the custom property (--bg-color)
assignment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/tools/css-serializer/test/__preparation__/keyframes.css`:
- Around line 37-52: The stylelint rule declaration-empty-line-before is
violated for the background-color declarations inside `@keyframes`
test-keyframe-declaration; fix it by adding a blank line immediately before each
background-color declaration in the 0%, 50%, and 100% keyframe blocks so that
the lines with background-color follow an empty line after the custom property
(--bg-color) assignment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d38daabe-c8cb-4bdc-a663-631a23c3e2ac

📥 Commits

Reviewing files that changed from the base of the PR and between 20bdd5c and 86782a7.

⛔ Files ignored due to path filters (1)
  • packages/tools/css-serializer/test/__snapshots__/lynx.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • packages/tools/css-serializer/src/parse.ts
  • packages/tools/css-serializer/src/types/LynxStyleNode.ts
  • packages/tools/css-serializer/test/__preparation__/keyframes.css
  • packages/web-platform/web-core/ts/encode/encodeCSS.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/tools/css-serializer/src/types/LynxStyleNode.ts

@usczz usczz force-pushed the p/zhouzhitao/feature/support_custom_property_keyframe branch from 86782a7 to 4aedb0e Compare April 7, 2026 08:49
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/tools/css-serializer/test/__preparation__/keyframes.css (1)

38-50: ⚠️ Potential issue | 🟡 Minor

Add required empty lines before background-color declarations.

declaration-empty-line-before is still failing at Line 40, Line 45, and Line 50. Please keep a blank line before each background-color declaration in these keyframe blocks.

Suggested fix
 `@keyframes` test-keyframe-declaration {
   0% {
     --bg-color: red;
+
     background-color: var(--bg-color);
   }

   50% {
     --bg-color: green;
+
     background-color: var(--bg-color);
   }

   100% {
     --bg-color: blue;
+
     background-color: var(--bg-color);
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/tools/css-serializer/test/__preparation__/keyframes.css` around
lines 38 - 50, Add a blank line before each "background-color" declaration
inside the keyframe blocks (the 0%, 50%, and 100% rules) so they comply with the
declaration-empty-line-before rule; locate the background-color lines within the
keyframe selectors (0%, 50%, 100%) and insert an empty line immediately above
each "background-color: var(--bg-color);" declaration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/tools/css-serializer/test/__preparation__/keyframes.css`:
- Around line 38-50: Add a blank line before each "background-color" declaration
inside the keyframe blocks (the 0%, 50%, and 100% rules) so they comply with the
declaration-empty-line-before rule; locate the background-color lines within the
keyframe selectors (0%, 50%, 100%) and insert an empty line immediately above
each "background-color: var(--bg-color);" declaration.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ea57a410-fc66-48dc-9d0a-ffa2f599d608

📥 Commits

Reviewing files that changed from the base of the PR and between 86782a7 and 4aedb0e.

⛔ Files ignored due to path filters (2)
  • packages/tools/css-serializer/test/__snapshots__/lynx.spec.ts.snap is excluded by !**/*.snap
  • packages/web-platform/web-core/tests/__snapshots__/encode.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • packages/tools/css-serializer/src/parse.ts
  • packages/tools/css-serializer/src/types/LynxStyleNode.ts
  • packages/tools/css-serializer/test/__preparation__/keyframes.css
  • packages/web-platform/web-core/tests/encode.spec.ts
  • packages/web-platform/web-core/ts/encode/encodeCSS.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/tools/css-serializer/src/types/LynxStyleNode.ts
  • packages/tools/css-serializer/src/parse.ts
  • packages/web-platform/web-core/tests/encode.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web-platform/web-core/ts/encode/encodeCSS.ts

@usczz usczz force-pushed the p/zhouzhitao/feature/support_custom_property_keyframe branch 2 times, most recently from 61863be to 602dcf4 Compare April 7, 2026 09:48
PupilTong
PupilTong previously approved these changes Apr 7, 2026
@usczz
Copy link
Copy Markdown
Collaborator Author

usczz commented Apr 7, 2026

@Sherry-hue PTAL

@usczz usczz force-pushed the p/zhouzhitao/feature/support_custom_property_keyframe branch 2 times, most recently from c53d761 to 6bdaf24 Compare April 8, 2026 03:56
- Extract `transformVariables` utility function in `parse.ts`.
- Add `variables` field to `KeyframesStyle` type to store parsed custom properties.
- Collect CSS variables for each keyframe block in `@keyframes` rules.
- Add test cases for `@keyframes` with CSS variables.
@usczz usczz force-pushed the p/zhouzhitao/feature/support_custom_property_keyframe branch from 6bdaf24 to b60fc8b Compare April 8, 2026 04:21
@luhc228 luhc228 merged commit 59d11b2 into lynx-family:main Apr 8, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants