Repository navigation
Conversation
parseUnparsed returned nothing when its reduced token list was falsy, so `--my-var: 0` compiled to no declaration. A var() reading it fell through to the inherited value, the :root value or its fallback instead of 0. The check now drops only an undefined result.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change to preserve zero-valued custom properties.
No open issues 🎉
What changed in this PR
Fixes the CSS compiler dropping custom properties declared as 0, so var() uses the declared value instead of an inherited value or fallback.
Changes:
- Updates
parseUnparsedto discard onlyundefined, preserving zero values. - Adds a regression test verifying that a zero-valued custom property produces
opacity: 0when a fallback is present.
| File | Description |
|---|---|
src/compiler/declarations.ts |
Preserves zero values in parsed declarations. |
src/__tests__/native/variables.test.tsx |
Tests zero-valued custom property resolution through var(). |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
parseUnparseddrops a token list whose reduced value is falsy (if (!args) return), so--my-var: 0compiles to no declaration at all. Avar()reading it then falls through to the inherited value, the:rootvalue or its fallback. Onmain,.zero { --my-var: 0 } .one { --my-var: 1 } .test { opacity: var(--my-var, 0.5) }rendersopacity: 0.5ontest zero, where browsers computeopacity: 0.Solution
The check drops only an
undefinedresult, so a0value is kept like any other. The check is in sharedparseUnparsed, and no other property's compiled output changes: the rest of the suite passes unchanged.Tests
src/__tests__/native/variables.test.tsxcovers a custom property declared as0and read throughvar()with a fallback. It fails onmain.Verification
On macOS with Node 24:
yarn lintcleanyarn typecheckcleanyarn test: 87 suites, 1390 tests pass