-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fix(makeStyles): handle RTL properly #17549
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 88d58b9:
|
Asset size changes
Over Tolerance (1024 B) Over Baseline Below Baseline New Removed 1 kB = 1000 B Baseline commit: c2331d66c74be1b3e0ed413b89d4f795ee5581a1 (build) |
Perf Analysis
All results
Perf Analysis (Fluent)Perf comparison
Perf tests with no regressions
|
// arguments are parsed manually to avoid double loops as TS & Babel transforms rest via an additional loop | ||
// @see https://babeljs.io/docs/en/babel-plugin-transform-parameters |
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 this perf opimization no longer true ?
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.
Yes, as signature of ax()
in make-styles
changed (now it accepts an array as a second param).
@@ -1,3 +1,2 @@ | |||
export { createCSSVariablesProxy } from './createCSSVariablesProxy'; | |||
export { resolveDefinitions } from './resolveDefinitions'; |
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.
Cruft, from previous implementation of makeStyles()
@@ -394,7 +390,7 @@ describe('resolveStyleRules', () => { | |||
animationDuration: '5s', | |||
}), | |||
).toMatchInlineSnapshot(` | |||
@-webkit-keyframes f13owpa8 { | |||
@-webkit-keyframes f1q8eu9e { |
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.
Hashes of keyframes have been changed because of a change in cssifyObject()
that always adds trailing commas now.
import { cssifyObject } from './utils/cssifyObject'; | ||
|
||
export function compileStaticCSS(property: string, value: MakeStyles): string { | ||
const cssRule = `${property} {${cssifyObject(value)}}`; | ||
return compileCSSRule(cssRule); | ||
return compileCSSRules(cssRule)[0]; |
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.
What is the story for RTL in static CSS?
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.
Automatic transformers are not supported as we don't know how global classes will be applied later. For example:
body { left: 10px }
|
||
// eslint-disable-next-line guard-for-in | ||
for (const slotName in resolvedStyles) { | ||
const slotClasses = renderer.insertDefinitions(dir, resolvedStyles[slotName]); |
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.
It is renderer
's responsibility to compute the classnames, but the rest of the code expect the classnames are stable and atomic. Where do we have this contract described and tested?
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.
It is not described. For me it's unclear path yet...
- Will we implement CSS extraction to .css files?
- How will look build time transform?
- Where is the balance between memory and perf for runtime/build time?
I don't have answers and thus don't want to make a strict contract there yet...
packages/react-examples/src/react-make-styles/RTL/RTL.stories.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Miroslav Stastny <mistastn@microsoft.com>
Co-authored-by: Miroslav Stastny <mistastn@microsoft.com>
🎉 Handy links: |
🎉 Handy links: |
🎉 Handy links: |
🎉 Handy links: |
🎉 Handy links: |
🎉 Handy links: |
🎉 Handy links: |
* fix(makeStyles): handle RTL properly * Change files * fix test, add export to avoid explosion in all components * fix lint * fix tests, fix build issues * fix typings, ignore eslint * fixes to compileCSS, unit tests * fixes to cssifyObject(), update useBadgeStyles & useCardStyles * rework impl * Change files * remove todo * complete todos * add a UT * add VR tests * use smaller screenshots * Update packages/make-styles/src/ax.ts Co-authored-by: Miroslav Stastny <mistastn@microsoft.com> * Update packages/react-examples/src/react-make-styles/RTL/RTL.stories.tsx Co-authored-by: Miroslav Stastny <mistastn@microsoft.com> * add a warning and UT for unregistered sequence * fix insertion for RTL * fix lint error Co-authored-by: Miroslav Stastny <mistastn@microsoft.com>
Pull request checklist
Addresses an existing issue: Fixes$ yarn change
TL;DR
This PR fixes RTL handling in
makeStyles()
and makesax()
context aware, so it will also handle it properly.RTL classnames
We can only use different classes for LTR & RTL if we want to avoid collisions, see CodeSandbox for example. This PR follows this approach, we will emit following CSS:
(results in 👇)
Previously,
makeStyles()
always returned LTR classes, this PR fixes it as classes for LTR and RTL are resolved separately (resolvedClasses
&resolvedClassesRtl
).ax() changes
The signature of
ax()
function@fluentui/make-styles
have been changed as spreads are complied into additional loops:Sample TS compiler output
In
@fluentui/react-make-styles
, but nowax()
consumes a React context to be aware of text direction. I will rename it intouseAx()
in a separate PR, in this PR bothax()
anduseAx()
are exported.:global
changesBehavior for
:global()
pseudo selector have been changed.Before
After
Now output will be the same.
We should use
makeStaticStyles()
to emit global styles:makeStyles()
emits theme specific styles that can be different for different themes. An example of possible issue before the change:Testing
PR contains a lot of new unit tests, new stories for
@fluentui/react-make-styles
and VR tests.