Skip to content

fix(compiler): keep a custom property declared as 0 - #571

Open
jonthomp wants to merge 1 commit into
nativewind:mainfrom
jonthomp:fix/zero-custom-property
Open

jonthomp wants to merge 1 commit into
nativewind:mainfrom
jonthomp:fix/zero-custom-property

Conversation

@jonthomp

Copy link
Copy Markdown

Problem

parseUnparsed drops a token list whose reduced value is falsy (if (!args) return), so --my-var: 0 compiles to no declaration at all. A var() reading it then falls through to the inherited value, the :root value or its fallback. On main, .zero { --my-var: 0 } .one { --my-var: 1 } .test { opacity: var(--my-var, 0.5) } renders opacity: 0.5 on test zero, where browsers compute opacity: 0.

Solution

The check drops only an undefined result, so a 0 value is kept like any other. The check is in shared parseUnparsed, and no other property's compiled output changes: the rest of the suite passes unchanged.

Tests

  • src/__tests__/native/variables.test.tsx covers a custom property declared as 0 and read through var() with a fallback. It fails on main.

Verification

On macOS with Node 24:

  • yarn lint clean
  • yarn typecheck clean
  • yarn test: 87 suites, 1390 tests pass

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.
Copilot AI balanced review requested due to automatic review settings November 11, 2026 01:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 parseUnparsed to discard only undefined, preserving zero values.
  • Adds a regression test verifying that a zero-valued custom property produces opacity: 0 when 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

No deployments
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