Skip to content

Use CSS logical properties instead of flipping styles in RTL - #2980

Draft
zoontek wants to merge 5 commits into
masterfrom
use-css-logical-properties
Draft

zoontek wants to merge 5 commits into
masterfrom
use-css-logical-properties

Conversation

@zoontek

@zoontek zoontek commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Related: react/react-native#59404

  • Output logical properties (marginStart, paddingEnd, start, borderTopStartRadius, textAlign: 'start'…) as CSS logical properties. The browser resolves them from the element's direction.
  • Remove the logical to physical polyfills from static styles (all properties are supported by the current browsers target).
  • Expand inline shorthands so longforms take precedence, using logical sides next to logical longforms.
  • Make marginHorizontal, marginVertical, paddingHorizontal and paddingVertical physical shorthands, separate from marginInline and marginBlock (I will suggest a similar behavior in React Native, as it's confusing - or maybe we could deprecate marginHorizontal, marginVertical etc, we will see).
  • Accept the direction style (only used for local overrides, the preferred solution is to set both dir and lang on the document).
  • Support gap in rule ordering and inline styles.
  • Map React Native aliases in transitionProperty to CSS logical names.
  • Normalize logical border colors.

BREAKING CHANGES

  • Remove the dir and lang props, and the internal dir="auto" on Text and TextInput. Use the direction style or set dir on the document.
  • Remove useLocaleContext.
  • Remove the writingDirection, shadow and textShadow options from StyleSheet.resolve.
  • unstable_createElement signature is now (component, props, ...children) (similar to React.createElement).
  • In static styles, marginHorizontal (and the other physical axis shorthands) now take precedence over marginInline and logical longforms.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Size Change: -1.81 kB (-1.87%)

Total Size: 94.8 kB

📦 View Changed
Filename Size Change
packages/react-native-web/dist/exports/createElement/index.js 281 B -83 B (-22.8%) 🎉
packages/react-native-web/dist/exports/StyleSheet/compiler/createReactDOMStyle.js 1.86 kB +318 B (+20.57%) 🚨
packages/react-native-web/dist/exports/StyleSheet/compiler/index.js 1.28 kB -657 B (-33.95%) 🎉
packages/react-native-web/dist/exports/StyleSheet/compiler/normalizeValueWithProperty.js 300 B +26 B (+9.49%) 🔍
packages/react-native-web/dist/exports/StyleSheet/index.js 792 B -144 B (-15.38%) 👏
packages/react-native-web/dist/exports/StyleSheet/localizeStyle.js 0 B -244 B (removed) 🏆
packages/react-native-web/dist/exports/StyleSheet/preprocess.js 1.56 kB +1 B (+0.06%)
packages/react-native-web/dist/exports/StyleSheet/validate.js 623 B +8 B (+1.3%)
packages/react-native-web/dist/exports/Text/index.js 1.33 kB -104 B (-7.26%) ✅
packages/react-native-web/dist/exports/TextInput/index.js 2.17 kB -110 B (-4.83%) ✅
packages/react-native-web/dist/exports/useLocaleContext/index.js 0 B -103 B (removed) 🏆
packages/react-native-web/dist/exports/View/index.js 942 B -90 B (-8.72%) ✅
packages/react-native-web/dist/index.js 748 B -13 B (-1.71%)
packages/react-native-web/dist/modules/createDOMProps/index.js 1.11 kB -25 B (-2.2%)
packages/react-native-web/dist/modules/forwardedProps/index.js 635 B -2 B (-0.31%)
packages/react-native-web/dist/modules/useLocale/index.js 0 B -282 B (removed) 🏆
packages/react-native-web/dist/modules/useLocale/isLocaleRTL.js 0 B -306 B (removed) 🏆

compressed-size-action

@Kudo Kudo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

The switch to real CSS logical properties is coherent: aliases are normalized before compile, static rules use a numeric precedence ladder, and the documented removals (dir/lang, useLocaleContext, StyleSheet.resolve options, unstable_createElement options) match the code. Static StyleSheet.create output should follow that ladder because each property is its own rule. Inline styles do not. createReactDOMStyle still writes both a physical property and the logical property that maps to the same side, then keeps source key order, so the used value changes with object order and does not match the longhand rule the new helper claims to implement.

Issue counts by severity

  • bugs: 1
  • suggestions: 1
  • nits: 0

}
}

if (style[prop] == null) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[bug] Inline expansion does not keep a stable winner when a physical property and a logical property map to the same side. setLongForm only suppresses same-family keys. An axis shorthand such as marginInline is exempt from that check, so { marginLeft: 8, marginInline: 16 } becomes { marginLeft: '8px', marginInlineStart: '16px', marginInlineEnd: '16px' }. Those are assigned in insertion order, and the later declaration wins for the shared side, so in LTR the shorthand's margin-inline-start overrides the longhand. The reverse key order lets marginLeft win. The logical rewrite has the same hole: if any logical longhand in the group is set, line 325 renames the opposite side before the style[prop] == null check, so { marginBottom: 4, margin: 16, marginBlockStart: 8 } emits both marginBottom: '4px' and marginBlockEnd: '16px'. When margin is expanded after marginBottom, margin-block-end overrides the physical longhand. Explicit pairs such as marginLeft plus marginStart (marginInlineStart after preprocess) never enter setLongForm and have the same order dependence. Same-family tests already require precedence to ignore key order, and the comment on setLongForm says longhands win. Static rules do not use this order either: marginLeft is group 3, marginHorizontal is 2.3, and marginInlineStart is 2.2, so a physical longhand always beats a logical longhand. Inline styles currently follow a third rule.

Suggestion: After expansion, give the inline object one declaration order that does not depend on input key order. Match the static ladder (four-side shorthand, then logical axis, then logical longhands, then physical axis shorthands, then physical longhands) so the higher-precedence property is assigned last and wins on the shared side in both directions. When renaming a side to its logical longhand, still treat an explicit physical longhand on that side as occupying the slot. Add order-independent tests for marginLeft with marginInline / marginStart, marginHorizontal with marginInlineStart, and marginBottom with margin plus marginBlockStart.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants