Skip to content

[fix] StyleSheet: do not mutate inline transitionProperty arrays - #2971

Closed
goranai wants to merge 1 commit into
necolas:masterfrom
goranai:fix-inline-transitionproperty-mutation
Closed

goranai wants to merge 1 commit into
necolas:masterfrom
goranai:fix-inline-transitionproperty-mutation

Conversation

@goranai

@goranai goranai commented Nov 18, 2026

Copy link
Copy Markdown

Fixes #2970

inline() flips logical names in an array transitionProperty by writing into the caller's array. After the first call the style object holds names that are already flipped for that direction. So the next RTL call keeps marginLeft instead of marginRight, a second call in the same direction returns an array instead of a string, and a frozen array throws TypeError: Cannot assign to read only property '0'.

On master (6885829):

const style = { transitionProperty: ['marginInlineStart', 'opacity'] };
inline(style, false); // { transitionProperty: 'marginLeft opacity' }
inline(style, true);  // { transitionProperty: ['marginLeft', 'opacity'] }, expected 'marginRight opacity'
style.transitionProperty; // ['marginLeft', 'opacity']

Change

  • compiler/index.js: copy the array with originalValue.slice() before writing to it. atomic() already does the same with [...values].
  • Remove the $FlowFixMe[cannot-write] comment. The copy is a writable array, so Flow reports the comment as unused.
  • compiler-test.js: two new tests, run for LTR and RTL. One checks the input array is unchanged and the same object gives the right result for the other direction. One checks a frozen array works.

Behavior changes

  • inline() no longer changes the caller's transitionProperty array.
  • A frozen transitionProperty array now works instead of throwing.
  • The first call on a fresh object returns the same output as before. In a fuzz of 5000 random styles this was identical on every case.

Testing

  • New tests fail on master (4 failed, the frozen ones with the TypeError) and pass with the change.
  • npm run unit -- --ci --runInBand: 55 suites passed, 811 passed, 6 skipped.
  • npm run flow: 0 errors, and 0 warnings with --include-warnings.
  • npm run lint and npm run format: clean. The pre-commit lint-staged tasks pass on the changed files.
  • A fuzz of 5000 styles (20000 calls, LTR and RTL in turn on one object, a quarter of them deep-frozen) against a fresh copy per call: master was wrong on 7970 calls and threw on 2456. With the change: 0 wrong, 0 thrown, 0 inputs changed.

Validated with Claude Opus 5.5.

@zoontek

zoontek commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

The mutation only happens with camelCase names like marginInlineStart, which don't work as CSS transition-property values anyway (marginLeft matches no CSS property).
Users would write margin-inline-start. That name isn't in the flip map, so inline() leaves the array untouched and this change has no effect.

@zoontek zoontek closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StyleSheet: inline transitionProperty array is mutated, so the RTL flip breaks on reuse

2 participants