Skip to content

fix(compiler): keep a custom property declared as auto - #572

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

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

Conversation

@jonthomp

Copy link
Copy Markdown

Problem

parseUnparsed rejects auto for every property outside allowAutoProperties, and custom properties are not in it. --my-var: auto compiles to a warning and no declaration, so a var() reading it falls through to the inherited value, the :root value or its fallback. On main, .auto { --my-var: auto } .fixed { --my-var: 10px } .test { width: var(--my-var, 5px) } renders width: 5 on test auto, where browsers compute width: auto.

Solution

parseUnparsed allows auto for custom properties. A custom property's value is any token list (css-variables-1 §2), so var() substitutes auto as written and the reading property receives it.

A property that cannot take auto, such as opacity: var(--my-var), now receives "auto", where a browser treats the declaration as invalid at computed-value time. Neither main nor this change matches that case, and #503 is where substituted values are validated.

Tests

  • src/__tests__/native/variables.test.tsx covers a custom property declared as auto and read by width 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 rejects `auto` for every property outside allowAutoProperties,
so `--my-var: auto` compiled to a warning and no declaration. A var() reading
it fell through to the inherited value, the :root value or its fallback, even
where the reading property takes `auto`.

A custom property's value is any token list, so custom properties now keep
`auto` and a var() substitutes it as written.
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

There are no active review issues for the change preserving auto values in custom properties.

No open issues 🎉

What changed in this PR

This PR fixes the compiler dropping custom properties declared as auto, allowing var() reads to use the declared value rather than an inherited value or fallback.

Changes:

  • Allow auto when parsing custom properties while retaining existing restrictions for other properties.
  • Add a regression test confirming a non-inlined custom property produces width: "auto" instead of the fallback.
File Description
src/​compiler/​declarations.ts Accepts auto for properties whose names begin with --.
src/​__tests__/​native/​variables.test.tsx Tests preservation of auto through a runtime var() read with a fallback.

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