-
Notifications
You must be signed in to change notification settings - Fork 53
fix(css-shorthands): expanding the shorthand properties in the styles #296
Conversation
this is a nice move, great that this one is finally addressed 👍 Speaking of the points raised. Not all CSS properties are expanded
Here I would suggest to search for extensibility options for However, considering which properties are not handled by the Performance considerationsAgree with these concerns, but it seems that if we would be able to make this functionality to be a Fela's plugin (once again, haven't reviewed PR yet), it would be quite easy for us to make perf measurements, due to there would be mechanism to enable and disable this functionality for the overall pipeline. So, for that reason I don't think that we should wait for perf measurements' scaffolding before introducing these changes. |
I'm not sure we should add this here, or possibly at all. Where would it be added?This is an operation that mutates the style object, so it would be a If it is added to Should it be added at all?Simple is better than complex. Predictable is better than magical. Consider this: http://fela.js.org/docs/introduction/Caveats.html#2-shorthand--longhand-properties
I think it might possibly be better to simply not allow shorthand mixture with expanded properties. Or, don't allow shorthand properties at all:
ConclusionI don't think we should add a separate dependency for this right now. I also think we should use a renderer plugin if we do add something. If we add something, it should probably be an error for now. Feedback? |
I was thinking about this as I watch all of these PRs fly in. I think a simple validation check on styles to throw a runtime error to the user to let them know they should not mix shorthands would be the best way to go. It might also be worth reaching out to @rofrischmann and find out how close he may or may not be to that tool he mentions in Fela docs. If it's close to complete, it might be worth just waiting for it and adding it at the |
Let me, please, respond to the points raised.
Totally agree that it should be added/used as Fela plugin - have expressed the same vision on that in my previous comment (#296 (comment)).
To me it seems that it rather should. Agree with all the points cited, but let me dissect the We should not 'surprise' client in a bad waySpeaking of this With that being said, lets consider the situation described by #237 - essentially, how it looks on the side of the client. Is it a point of astonishment? I would say decent 'yes' - because even if client would follow all the Stardust guidelines, she will still receive rendering result that is
I might agree that it could be considered a step in the right direction for short-term perspective, but still am not sure whether we could consider this to be a solution for the problem. Specifically, let me provide the reasons for that. Show warnings?Suppose that we will decide to show warnings (so that components tree will be rendered). In that case I might easily imagine the situation where problems won't be noticed by client (once again, we should think about client use cases - where there might not be any screen validation tests) - for example, due to the fact that styles should be applied for some pseudo-state that is not displayed by default. Thus, we won't be able to prevent this problem from happening on the client side - or, better to say, we won't be able to prevent our clients from shipping their product with broken styles. Throw errors?Another alternative - throw error and prevent component tree from being rendered. While, for this case, the problem of broken styles for sure will be noticed, I might think about cases where client will decide to consume theme dynamically in her product (e.g. load theme object through ajax requests as one of the examples) - and, in that case it might happen that theme that has been dynamically applied will break the app. To me it seems to be a point of huge astonishment as well - given that styles have broken the entire app, - maybe much worse than the previous one. ConclusionSo, for these reasons I'd rather see this 'CSS prop expansion' functionality being supported - for the sake of preventing any surprises to our clients. |
@mnajdova Thanks for the mail, I'll write here so everyone can see my response =) In my opinion, it's worth adding that to the core as it reduces confusion a lot. I don't think performance is an issue here. border-top-width: 1px;
border-top-style: solid;
border-top-color: grey;
border-right-width: 1px;
border-right-style: solid;
border-right-color: grey;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: grey;
border-left-width: 1px;
border-left-style: solid;
border-left-color: grey; Maybe the plugin in combination with built-in expansion is the way to go? In devMode most mixing issue will be logged and eventually fixed by the developer, but you still have the shorthand expansion in production (especially for dynamic styles). tl;dr: I'd be more than happy collaborating on both tools as fela plugins. Especially adding the missing props to the expansion library. |
@levithomason be assured that this will be added as a fela plugin, this is just a showcase that it works. @rofrischmann thanks very much for sharing your thoughts on this PR :) |
The logic for expanding the css shorthands is now moved to plugin. Please, share your feedback. |
const expandCssShorthands = styles => { | ||
const processedStyles = {} | ||
|
||
Object.keys(styles).forEach(cssPropertyName => { |
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.
nit: if lodash
is imported and, what is more appealing, is used below, we might consider to use _.keys :) in either case, please, feel free to decide by your own
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 code is refactored.
return expandCssShorthands | ||
} | ||
|
||
const shorthands = [ |
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.
could you, please, suggest which cases we are aim to prevent with this explicit list?
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 deleted it
src/lib/felaRenderer.tsx
Outdated
@@ -9,6 +10,8 @@ import { IRenderer } from '../../types/theme' | |||
|
|||
const createRendererConfig = (options: any = {}) => ({ | |||
plugins: [ | |||
felaExpandCssShorthandsPlugin(), |
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.
shouldn't it come after CSS is sanitized?
-moved it after the sanitize plugin
Codecov Report
@@ Coverage Diff @@
## master #296 +/- ##
=======================================
Coverage 89.59% 89.59%
=======================================
Files 62 62
Lines 1220 1220
Branches 156 156
=======================================
Hits 1093 1093
Misses 125 125
Partials 2 2 Continue to review full report at Codecov.
|
…do classes too -added test for the new fela plugin
# Conflicts: # package.json
… not released newer version after it is fixed)
-added tests for covering the borderColor prop (as an example for ensuring two-words properties work)
Closing this in favor of #869 |
Fix
This PR aims to fix #237 by expanding the css shorthands of the theme's components styles and the styles prop provided to the component while they are merged.
I added the css-shorthand-expand library and provided service for expanding the styles. There are still some points that should be addressed:
1. The library provides extending for the following shorthands:
This means that we still don't have any mechanism for expanding the other shorthands like:
2. It would have been nice if we would be able to measure the performance of the components and conclude whether this changes would impact them.
I need input whether this is worth exploring further, or whether maybe we should just try to use the library when defining the styles for the themes or applying the styles prop on the components.
NOTE
The css-shorthand-expand library was replaced with a better alternative shortcss. There is one known bug in the first library that is preventing us of using it. I liked the second library better because of more cleaner expanding of the props.