-
Notifications
You must be signed in to change notification settings - Fork 329
[babel-plugin] add LTR/RTL config to legacy-e… #1083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
workflow: benchmarks/perfComparison of performance test results, measured in operations per second. Larger is better.
|
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mapping to marginStart etc is not really for RN, it's just the legacy non-standard names we used internally before moving into the standard ones.
We could also move the related polyfill tests into the 'legacy' directory
packages/@stylexjs/babel-plugin/src/shared/physical-rtl/generate-ltr.js
Outdated
Show resolved
Hide resolved
packages/@stylexjs/babel-plugin/src/shared/utils/default-options.js
Outdated
Show resolved
Hide resolved
@@ -53,19 +53,19 @@ describe('Legacy-shorthand-expansion resolution', () => { | |||
var _inject2 = _inject; | |||
import stylex from 'stylex'; | |||
_inject2(".x123j3cw{padding-top:5px}", 4000); | |||
_inject2(".x1mpkggp{padding-right:5px}", 3000, ".x1mpkggp{padding-left:5px}"); | |||
_inject2(".x1gabggj{padding-right:5px}", 3000, ".x1gabggj{padding-left:5px}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm can we avoid having these hashes change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm actually not sure why these are changing and have to investigate...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just dug into this a bit. in the stylex-create
visitor, we build the hash using the property name after shorthand expansion (padding
-> padding-top
, padding-start
), but before ltr/rtl polyfill (see below).
the hashes changed because i made a change to expand to padding-inline-start
instead of padding-start
, but the polyfill later changes it back to paddingLeft
and paddingRight
_inject2(".x1hm9lzh{margin-left:10px}", 3000, ".x1hm9lzh{margin-right:10px}"); | ||
_inject2(".x1sa5p1d{margin-right:10px}", 3000, ".x1sa5p1d{margin-left:10px}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that the classname hash is the same for 2 different rules? Is this just how we've always done it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also dug into this, I think it's because:
<div class = "x1hm9lzh ..." />
we serve two different stylesheets depending on if it's LTR/RTL, but want to avoid adding two classnames, so in LTR it gets the .x1hm9lzh {margin-left }
rule and in RTL it gets the .x1hm9lzh {margin-right}
packages/@stylexjs/babel-plugin/src/shared/utils/default-options.js
Outdated
Show resolved
Hide resolved
enableLegacyDirectionPolyfill
config to legacy-e…const propertyToLTR: $ReadOnly<{ | ||
[key: string]: ($ReadOnly<[string, string]>) => $ReadOnly<[string, string]>, | ||
}> = { | ||
'margin-start': ([_key, val]: $ReadOnly<[string, string]>) => [ | ||
'margin-left', | ||
val, | ||
], | ||
// 'margin-inline-start': ([_key, val]) => ['margin-left', val], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are previous "aliases" that didn't need to be explicitly included, because we converted instances of marginInlineStart
to marginStart
while expanding shorthands. since we're expanding to marginInlineStart
now, we need to include this in the mapping.
now included in inlinePropertyToLTR
and used when LTR/RTL fallback is on and style resolution is legacy-expand-shorthands
. after we ship this with experimental stylesheets we can try to remove most of this logic altogether
['marginBottom', bottom], | ||
['marginStart', left], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is where we previously expanded margin
to marginStart
anyway, since it all got translated to marginLeft
/marginRight
downstream
@@ -53,19 +53,19 @@ describe('Legacy-shorthand-expansion resolution', () => { | |||
var _inject2 = _inject; | |||
import stylex from 'stylex'; | |||
_inject2(".x123j3cw{padding-top:5px}", 4000); | |||
_inject2(".x1mpkggp{padding-right:5px}", 3000, ".x1mpkggp{padding-left:5px}"); | |||
_inject2(".x1gabggj{padding-inline-end:5px}", 3000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should turn the feature flag on for these tests, if they're basically to test that the way we current use StyleX internally is not changed?
Context
Let's remove the LTR/RTL polyfill (#752), as most browsers support logical styles now:
legacy-expand-shorthands
works in a few steps:legacy-expand-shorthands.js
: We split shorthands into respective longhands. There are no (common) shorthands left after this./physical-rtl
we convert these into ltr:marginLeft
and rtl:marginRight
.Follow ups:
In 1., we do some transforms (marginInlineStart
-> to RN equivalentmarginStart
, for legacy internal reasons) that we need to remove, since this would be exposed without being converted tomarginLeft
andmarginRight
margin-start
css propertiesborder-*-*-radius
properties, though it's on the edge of browser support. They fit the internal browser requirements for every app except WhatsApp.Testing
For these tests, we expect to see the LTR/RTL polyfill when
enableLegacyDirectionPolyfill: true
. We expect to the unmodified logical styles whenenableLegacyDirectionPolyfill: false
.Note: We want to migrate over to
application-order
(and laterproperty-specificity
), but it'll be a long process to test and ship@layer
. In the meantime, let's remove the LTR/RTL polyfill as a way to test experimental stylesheets. We use thelegacy-expand-shorthands
style resolution overapplication-order
orproperty-specificity
internally for this reason:legacy-expand-shorthands
gets rid of the most common shorthands and expands them, since without@layer
use inprocessStylexRules
, we run into ordering issues with shorthands