Skip to content

[babel-plugin] Throw on NaN and Infinity style values - #2106

Open
FSF-ADMIN wants to merge 3 commits into
meta:mainfrom
FSF-ADMIN:reject-non-finite-values
Open

FSF-ADMIN wants to merge 3 commits into
meta:mainfrom
FSF-ADMIN:reject-non-finite-values

Conversation

@FSF-ADMIN

Copy link
Copy Markdown

What changed / motivation ?

stylex.create() currently accepts any value whose typeof is 'number', which includes NaN and Infinity. These are not valid CSS values, but they are emitted silently, for example:

const a = 'x';
stylex.create({ root: { opacity: a * 2, zIndex: 1 / 0 } });
// .x1yfwku{opacity:NaN}
// .xbdygrb{z-index:Infinity}

The most likely way to hit this is the case reported in #1946: imported defineConsts values are compiled as var(--...) strings, so arithmetic such as c.one * c.two evaluates to NaN at compile time and produces opacity:NaN with no warning.

This PR makes the basic validation in preprocess-rules/basic-validation.js throw a new ILLEGAL_PROP_NUMBER_VALUE error for non-finite numbers. It applies to plain values, array values and conditional (pseudo/at-rule) values.

Linked PR/Issues

Related to #1946. This handles the silent NaN case only. It does not change how + on imported constants concatenates strings, or whether defineConsts should accept numbers, which still need a maintainer decision.

Additional Context

Tests added in validation-stylex-create-test.js: NaN, Infinity, NaN in an array, -Infinity in a conditional style, and NaN from arithmetic on an imported defineConsts value (using the existing __fixtures__/constants.stylex.js). All 5 fail without the change and pass with it.

Locally: the full @stylexjs/babel-plugin test suite passes (1050 passed), and flow check, prettier --check and eslint report no errors.

Pre-flight checklist

@vercel

vercel Bot commented Dec 3, 2026

Copy link
Copy Markdown

@FSF-ADMIN is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 3, 2026

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

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant