Skip to content

fix: Correct native matrix translation indices - #529

Merged
javache merged 1 commit into
react:mainfrom
ZainnQureshii:fix/native-matrix-translation
Nov 16, 2026
Merged

javache merged 1 commit into
react:mainfrom
ZainnQureshii:fix/native-matrix-translation

Conversation

@ZainnQureshii

Copy link
Copy Markdown
Contributor

Summary

parseTransform expands CSS matrix(a, b, c, d, tx, ty) into the 16-value native matrix, but it put tx and ty at indices 8 and 9 (packages/react-strict-dom/src/native/css/parseTransform.js). React Native reads that array column-major with translation at indices 12 and 13 (the translate case in ReactCommon/react/renderer/graphics/Transform.cpp sets matrix[12] and matrix[13]), and the CSS Transforms spec maps matrix(a, b, c, d, e, f) to matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, e, f, 0, 1). So on native any translation inside a 2D matrix() was dropped.

For matrix(1, 0, 0, 1, 12, -34) the output goes from [1, 0, 0, 0, 0, 1, 0, 0, 12, -34, 1, 0, 0, 0, 0, 1] to [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 12, -34, 0, 1].

The existing matrix parser expectation is updated, and there are two new regression tests: one on the parser and one through css.create() on an html.div.

Test plan

npm run jest -w react-strict-dom -- --runInBand --runTestsByPath src/native/css/__tests__/parseTransform-test.js tests/css/css-create-test.native.js

With the fix reverted and the tests kept: 3 failed, 108 passed. With the fix: 111 passed.

npm run jest -w react-strict-dom

19 suites, 899 tests passed. Prettier and ESLint are clean on the changed files. Not run: device rendering and Flow.

Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

parseTransform expanded the CSS 2D matrix(a, b, c, d, tx, ty) into a 4x4 matrix with tx and ty at indices 8 and 9. React Native reads the 16 values column-major, with translation at indices 12 and 13 (Transform.cpp sets them there for translate), so the translation was dropped. Place tx and ty at 12 and 13 and keep index 10 as 1.
@meta-cla meta-cla Bot added the cla signed label Nov 10, 2026
@github-actions

Copy link
Copy Markdown

workflow: benchmarks/perf (native)

Comparison of performance test results, measured in operations per second. Larger is better.

Results Base Patch Ratio
css.create
· small 1,867,135 1,973,055 1.06 !!
· small with units 894,093 882,704 0.99 -
· small with variables 1,150,977 1,177,130 1.02 +
· several small 608,490 620,757 1.02 +
· large 354,985 358,115 1.01 +
· large with polyfills 254,841 254,269 1.00 -
· complex 177,221 177,388 1.00 +
· unsupported 382,700 387,162 1.01 +
css.createTheme
· simple theme 405,253 407,307 1.01 +
· polyfill theme 378,900 387,416 1.02 +

@github-actions

Copy link
Copy Markdown

workflow: benchmarks/size

Comparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.

Results Base Patch Ratio
react-strict-dom/dist/web/index.js
· compressed 3,251 3,251 1.00
· minified 10,375 10,375 1.00
react-strict-dom/dist/web/runtime.js
· compressed 1,645 1,645 1.00
· minified 4,131 4,131 1.00
react-strict-dom/dist/native/index.js
· compressed 16,850 16,855 1.00 +
· minified 65,487 65,487 1.00
react-strict-animated/dist/web/index.js
· compressed 6,861 6,861 1.00
· minified 23,486 23,486 1.00
react-strict-animated/dist/native/index.js
· compressed 797 797 1.00
· minified 2,518 2,518 1.00

@javache
javache merged commit d8e6d9a into react:main Nov 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants