-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[AutoPrefix] Change getTrasform() to return the prefixer object #3112
Conversation
@felipethome Looking at this from a high level the changes seem correct and reasonable. The interesting thing is pretty much all these methods (except for That being said:
That makes sense I think your changes in this area make sense and I think we should change this. Though the @oliviertassinari @alitaheri @mbrookes How do you think we should handle this in light of preparing next version? |
In the PR you mentioned it seems the set method will remain. It will be shorter, but still with the reference problem. |
Yeah I know, we still plan to remove it 😄 We just haven't change the components that use it to use not use it yet. |
@@ -28,7 +28,7 @@ export default { | |||
userAgent: userAgent, | |||
}); | |||
|
|||
return prefixer.prefix; | |||
return prefixer; |
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.
From what I understood from the issues you mentioned. It has a reference issue, wouldn't
return (style) => prefixer.prefix(style);
fix 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.
True, I believe it would. And it is actually better like that since I forgot to change this other code:
if (userAgent === false) { // Disabled autoprefixer
return (style) => style;
} else if (userAgent === 'all' || userAgent === undefined) { // Prefix for all user agent
return InlineStylePrefixer.prefixAll;
...
Now, what about the set() method? It will be removed but the components that use this method are not having their styles transformed right now.
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.
return (style) => prefixer.prefix(style);
That makes sense to me.
Now, what about the set() method? It will be removed but the components that use this method are not having their styles transformed right now.
I think the easiest way to deal with this once an for all is to migrate the components that are using set()
to use the prefixAll
method now included in muiTheme.
@felipethome That's a really good finding 🎉! The auto-prefixer just doesn't work 😨. return (style) => prefixer.prefix(style); What about adding a test so that this type of regression never happen again 🙈? That's some very good observations we plan to remove the
Well, that explains why when I tried to remove the set(style, key, value) {
style[key] = value;
} |
@oliviertassinari Of course, I will do it . And thanks @alitaheri for the insight. The test you are purposing should test just the |
I believe there are three problems with the AutoPrefix module:
The getTransform() method is returning the prefix() method from the Prefixer class. This will not work since inline-style-prefixer has statements like this one:
When one calls muiTheme.prefix() he is actually setting the this keyword to the muiTheme object (so, _this.hasPropsRequiringPrefix would be undefined). This is a big problem because it means that none of the styles transformations being called with set() is working.
The set() method has the signature: set(style, key, value, muiTheme). Then, inside of it there are some piece of code like this:
This will not work because it is being passed a reference to the style object, so when you assign a new value to it we are actually loosing the reference to the original object and not changing anything at all in the caller.
As a setter the set function should not pass the entire style object to the prefix method, because inside of its code it has:
So prefix() will iterate though all the style properties.
Obs: in the all() method inside the AutoPrefix module there are statements returning the object created by InlineStylePrefixerInstance.prefix(). That approach would not work for the set method because material-ui has statements like this one:
The style object returned by a DOM element is actually a CSSStyleDeclaration and not a conventional Javascript object so one definetelly can not override it with the return object from InlineStylePrefixerInstance.prefix().