#1915·stylex

[babel-plugin] `firstThatWorks('var(--z)', 100)` throws `varName.startsWith is not a function`

Author: Om-singhaICreated Sep 29, 2026Updated Sep 29, 2026

Describe the issue

Passing a number as the fallback after a var() in stylex.firstThatWorks fails the build with varName.startsWith is not a function. The string form works fine, and numbers are allowed by the type (<T extends string | number>) and the docs. In stylex-first-that-works.js the number gets folded into the var() chain as if it were a string.

There's a smaller second problem. A numeric 0 fallback is silently dropped, so top: stylex.firstThatWorks('anchor(--a bottom)', 0) compiles to just top:anchor(--a bottom). The "Remove Nulls" step in flatten-raw-style-obj.js uses filter(Boolean), which removes 0 as well. With '0' it works.

Expected behavior

The same CSS as the string forms: z-index:var(--z,100) and top:0;top:anchor(--a bottom).

Steps to reproduce

  1. npm install @stylexjs/[email protected] @babel/core
  2. Run the script below with Node.

I also see it on main at fe0be7f.

Test case

javascript
const { transformSync } = require('@babel/core');
const stylex = require('@stylexjs/babel-plugin');

const styles = [
  "zIndex: stylex.firstThatWorks('var(--z)', '100')",
  "zIndex: stylex.firstThatWorks('var(--z)', 100)",
  "top: stylex.firstThatWorks('anchor(--a bottom)', 0)",
];
for (const style of styles) {
  try {
    const { metadata } = transformSync(
      `import * as stylex from '@stylexjs/stylex';
       export const styles = stylex.create({ root: { ${style} } });`,
      { filename: '/a.js', plugins: [stylex] },
    );
    console.log(metadata.stylex[0][1].ltr);
  } catch (e) {
    console.log(e.message);
  }
}
.x13q71gy{z-index:var(--z,100)}
/a.js: varName.startsWith is not a function
.xtxu0yw{top:anchor(--a bottom)}

Additional comments

I've got a small fix with tests and will open a PR for it.