Skip to content

[babel-plugin] Drop floating-point noise when converting ms timings to seconds - #1999

Open
kevin9327 wants to merge 1 commit into
meta:mainfrom
kevin9327:fix/timings-float-noise
Open

kevin9327 wants to merge 1 commit into
meta:mainfrom
kevin9327:fix/timings-float-noise

Conversation

@kevin9327

Copy link
Copy Markdown

What changed / motivation ?

The timings value normalizer turns millisecond values of 10ms and up into seconds with value / 1000 + 's'. That division is done in binary floating point, so many ordinary values come out with representation noise in the generated CSS:

stylex.create({ x: { transitionDuration: '33.3ms' } })
// .x…{transition-duration:.033299999999999996s}   (expected .0333s)

Other examples are 11.3ms → .011300000000000001s, 13.8ms → .013800000000000002s and 10.2ms → .010199999999999999s. Roughly a quarter of the one-decimal millisecond values from 10ms to 200ms are affected. The value means the same thing, but the CSS is longer than the ms form it replaces, which defeats the point of the conversion ("shorter"), and the noise also ends up in the class-name hash input.

The fix rounds the quotient to 15 significant digits (Number((value / 1000).toPrecision(15))). That removes the noise and keeps every digit a CSS time value can carry. Values that already divided cleanly (1234ms → 1.234s, 10ms → .01s) are unchanged, and so are the existing inline snapshots.

Linked PR/Issues

None. I found no open issue or PR about this.

Additional Context

New test in packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js: 33.3ms, 11.3ms, and a transition shorthand with 13.8ms and 10.2ms compile to .0333s, .0113s and opacity .0138s ease-in .0102s. It fails on main (transition-duration:.033299999999999996s) and passes with the fix. The other 20 tests in that file still pass.

I ran the babel-plugin suite from a sparse checkout with the published @stylexjs/stylex/@stylexjs/shared 0.19.1 instead of the workspace builds. In that setup 3 suites (transform-stylex-props-test.js and two legacy suites, 7 tests) fail identically with and without this change; everything else passes.

AI assistance: I used an AI coding assistant to help find and write this fix. I reviewed the change and ran the tests above myself.

Pre-flight checklist

@vercel

vercel Bot commented Oct 30, 2026

Copy link
Copy Markdown

@kevin9327 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 Oct 30, 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