Skip to content

fix(CSS): tolerate leading whitespace in a transform string - #10388

Merged
MatiPl01 merged 5 commits into
software-mansion:mainfrom
dennytosp:fix/transform-string-leading-whitespace
Aug 26, 2026
Merged

fix(CSS): tolerate leading whitespace in a transform string#10388
MatiPl01 merged 5 commits into
software-mansion:mainfrom
dennytosp:fix/transform-string-leading-whitespace

Conversation

@dennytosp

Copy link
Copy Markdown
Contributor

Note

This pull request was authored by AI on behalf of @dennytosp.

Summary

processTransform splits the string on /\)\s*/, so whitespace after each ) is consumed, and filter(Boolean) drops the empty part a trailing one leaves behind. Nothing ever reaches the start of the string, so the first function keeps its padding:

processTransform('  translate(25px) rotate(45deg)')
// throws: [Reanimated] Invalid transform property:   translate(25px)

parseTransformProperty splits that part on /\(\s*/, gets ' translate' as the key, matches no case, returns [], and processTransform turns the empty result into a thrown error. Only the first function in the string is affected — everything after a ) is already fine.

The same string without the two leading spaces parses without complaint, and React Native's parser accepts both:

RNCORE '  translate(25px) rotate(45deg)'  ->  [{"translate":[25,0]},{"rotate":"45deg"}]

CSS ignores leading whitespace in a property value, and a value assembled from a template literal or read out of a config file easily carries some — this is the kind of difference that produces a crash report with no obvious cause.

Fix

value.trim() before the split. Trimming the whole input rather than the parsed key also covers tabs and newlines, and leaves the error message intact for genuinely invalid input.

Test plan

Two cases added to the multi-transform table in src/common/style/processors/__tests__/transform.test.ts — one with leading and trailing spaces, one with newlines and indentation. Both fail on main:

$ git stash push src/common/style/processors/transform.ts
$ yarn jest src/common/style/processors/__tests__/transform.test.ts
  ✕ parses   translate(25, 25) scale(2)
  ✕ parses \n  translate(25, 25)\n  scale(2)\n
Tests: 2 failed, 64 passed, 66 total

With the fix applied:

$ yarn jest
Test Suites: 103 passed, 103 total
Tests:       1558 passed, 1558 total

Every existing error case still throws — translat(25, 25), rotate(90), scaleX() and the rest are unaffected, since trimming only removes padding that was never part of a function name. yarn eslint and oxfmt --check are clean on both files.

Touches the same file as #10385 but a different function; the two apply independently.

Changelog

  • I added an entry to the Unpublished section of each changed package's CHANGELOG.md, or this PR does not change react-native-reanimated or react-native-worklets.

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41e8fb37-c088-4524-9d30-0ca6fd7e1b8f

📥 Commits

Reviewing files that changed from the base of the PR and between 236434f and 17bc576.

📒 Files selected for processing (1)
  • packages/react-native-reanimated/CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-native-reanimated/CHANGELOG.md

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

processTransform and processTransformOrigin now trim surrounding whitespace before parsing string inputs. Tests cover spaces, newlines, and tabs while preserving normalized values and transform order. The changelog documents the fix.

Merge Risk: ⚪ Minimal · up to 17bc5

The change trims leading and trailing whitespace from transform strings while preserving invalid-input errors. It is localized and merge-ready after normal checks, with no actionable merge-blocking risk remaining.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: support leading whitespace in CSS transform strings.
Description check ✅ Passed The description accurately explains the parsing issue, the trim-based fix, the tests, validation results, and changelog update.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

`processTransform` splits on `/\)\s*/`, so whitespace after each `)` is
consumed, and `filter(Boolean)` drops the empty part a trailing one leaves
behind. Nothing reaches the start of the string, so the first function keeps its
padding, `parseTransformProperty` reads the key as `'  translate'`, no case
matches, and the whole declaration throws:

    processTransform('  translate(25px) rotate(45deg)')
    // [Reanimated] Invalid transform property:   translate(25px)

The same string without the two leading spaces parses fine, and React Native's
own parser accepts both. CSS ignores leading whitespace in a property value, and
a value built from a template literal or read from a config file easily carries
some.

Trim the string before splitting.
@dennytosp
dennytosp force-pushed the fix/transform-string-leading-whitespace branch from c5225b4 to 1336503 Compare August 26, 2026 14:25
@MatiPl01 MatiPl01 self-assigned this Aug 26, 2026
processTransformOrigin splits on /\s+/, so a leading space makes the first
component an empty string and the value throws, exactly like the transform
string did. Same one-line fix, with cases covering both ends of the value.

Drop the comments above the two trims - they restate the code.
# Conflicts:
#	packages/react-native-reanimated/CHANGELOG.md

@MatiPl01 MatiPl01 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MatiPl01
MatiPl01 merged commit a657530 into software-mansion:main Aug 26, 2026
21 of 23 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