-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
makeStyles: expansion of shorthands does not work sometimes #19402
Comments
We briefly discussed this with @miroslavstastny, we see following options. ⬇⬇⬇ (not an option) 1️⃣ Use Atomic CSS & fix expansionThe problem it's probably impossible. There are many cases where cannot expand (CSS variables that using compound values) or it will be too complex. .a {
--foo: 5px 10px;
} // ⚠ if we will expand this we will get "paddingLeft: "5px 10px"
const input = { padding: "var(--foo)" }; 2️⃣ Do not use Atomic CSSWe need expand properties to be able merge properly atomic CSS rules. Without expansion our behavior will be be deterministic: /* Order of insertion can be different */
.a {
padding-left: 5px;
}
.b {
padding: 10px;
} <-- ⚠ Applied padding depends on order of class in CSS i.e. insertion/rendering
order -->
<div>
<div class="a" id="foo">
<div class="b" id="bar">
<div class="a b"></div>
</div>
</div>
</div> microsoft/griffel#129 describes different problem, but the result of non-deterministic behavior will be the same: Pros
Cons
ImplementationCurrently, i.e. before
const useStylesBefore = makeStyles({
base: { padding: "5px" },
override: { paddingLeft: "10px" }
});
const classesBefore = useStylesBefore();
// 💅 CSS
// .a { padding-left: 5px }
// .b { padding-right: 5px }
// .c { padding-top: 5px }
// .d { padding-bottom: 5px }
// .e { padding-left: 10px }
mergeClasses(classesBefore.base, classesBefore.override); // ➡ "b c d e" Without Atomic CSS, i.e. after
const useStylesAfter = makeStyles({
base: { padding: "5px" },
override: { paddingLeft: "10px" }
});
const classesAfter = useStylesBefore();
// 💅 CSS
// .base { padding: 5px }
// .override { padding-left: 10px }
const buttonClasses = mergeClasses(classesAfter.base, classesAfter.override); // ➡ "base_override"
// 💅 CSS .base_override { padding: 5px; padding-left: 10px }
const buttonClasses = mergeClasses(buttonClasses, classesAfter.override); // ➡ "base_override_override"
// ⚠ Yeah, it gets duplicated as CSS is not merged, it's concatenated
// 💅 CSS .base_override { padding: 5px; padding-left: 10px; padding-left: 10px } 3️⃣ Use Atomic CSS, fix expansion as we can, have restrictionsA middle ground solution: keep Atomic CSS, but introduce some restrictions. For example, we cannot expand
As we know that our CSS variables are not compound, we can write expansion for shorthands that is more specific. |
This issue should be solve by #20573 RFC, Next steps is implementing the RFC |
Intro
As
makeStyles()
also uses Atomic CSS we have the same problem and we are using the same package to expand shorthands:Problem
It was not a big problem in Fluent N* as we don't use there CSS variables, with
makeStyles()
we have a problem there.CSS variables cannot be expanded
There are cases when CSS variables cannot be expanded, for example
background
:This behavior is questionable as
-foo
can have different values:https://codesandbox.io/s/dank-hooks-r7jmr?file=/src/App.js
Not all shorthands are expanded
A list of shorthands supported by
inline-style-expand-shorthand
is very limited.Complete list of shorthands based on MDN data
For example,
background
is not supported (robinweser/inline-style-expand-shorthand#5):https://codesandbox.io/s/silent-flower-txe4u?file=/src/App.js
Some shorthands are not properly expanded
For example,
flex
, see robinweser/inline-style-expand-shorthand#14.The text was updated successfully, but these errors were encountered: