-
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): support ordering for pseudo selectors #17669
Conversation
Asset size changes
Over Tolerance (1024 B) Over Baseline Below Baseline New Removed 1 kB = 1000 B Baseline commit: db4ef40e7be2a30b47e73dd0f0ec9ab17b31f241 (build) |
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 8dd453a:
|
Perf AnalysisNo significant results to display. All results
Perf Analysis (Fluent)Perf comparison
Perf tests with no regressions
|
"@supports (display: table-cell){.foo{color:red;}}", | ||
] | ||
`); | ||
}); |
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.
Tests are not related to changes in this PR, but are still valuable.
try { | ||
if (renderer.styleElement.sheet instanceof CSSStyleSheet) { | ||
renderer.styleElement.sheet.insertRule(ruleCSS, renderer.index); | ||
renderer.index++; |
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.
We can't rely on renderer.index
for .insertRule()
as insertion runs for different style nodes now.
]; | ||
|
||
// Renderer types | ||
|
||
export type MakeStylesMatchedDefinitions = Record<string, MakeStylesResolvedRule>; | ||
export type MakeStylesReducedDefinitions = Record<string, MakeStylesResolvedRule>; |
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 type was renamed as we don't have "matchers" anymore.
@@ -116,11 +116,11 @@ export function ax(dir: 'ltr' | 'rtl', classNames: (string | false | undefined)[ | |||
const resultDefinition = resultDefinitions[property]; | |||
|
|||
if (isRtl) { | |||
const rtlPrefix = isRtl && resultDefinition[2] ? RTL_PREFIX : ''; | |||
const rtlPrefix = isRtl && resultDefinition[3] ? RTL_PREFIX : ''; |
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 the time to introduce constants?
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.
btw, is there a way to force-inline a constant?
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.
btw, is there a way to force-inline a constant?
Terser will do it for us, I created a sandbox to show it: https://codesandbox.io/s/terser-forked-txjd2?file=/src/index.js
Is this the time to introduce constants?
Great idea, I will add them in a follow up PR, in this case we will be sure that it does not affect bundle size 👍
🎉 Handy links: |
* fix(makeStyles): support ordering for pseudo selectors * Change files * fix insertion * add a VR test * fix tabIndexes * update VR tests * update VR tests * update VR tests again * update VR tests * update VR tests * update VR tests
$ yarn change
Description of changes
This PR adds the concept of style buckets inspired by Compiled: style rules insertion is ordered to follow LVFHA order.
What it means on practice? The behavior of pseudo selectors becomes predictable as they will be inserted always in the same order: rules will be inserted into different style nodes are ordered.
How it works?
Styles are inserted into different nodes based on their priority, see
styleBucketOrdering
. Style nodes are created on demand, a sample output is below:Implementation details
A signature of resolved rules was changed to include a style bucket name:
Why we have this in resolved rules? This allows us to perform style bucket computations during build step and avoid runtime work.
I also changed the process of insertion to DOM (
createDOMRenderer.ts
), now it creates style nodes on demand to have style rules ordered.Trade-offs
Other pseudo selectors including media queries may unexpectedly clash: