Skip to content
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

[ButtonBase] Remove dead style #15503

Merged
merged 5 commits into from
Apr 27, 2019
Merged

[ButtonBase] Remove dead style #15503

merged 5 commits into from
Apr 27, 2019

Conversation

koshea
Copy link
Contributor

@koshea koshea commented Apr 26, 2019

Our application uses some JSS plugins to modify the CSS. A few components in MUI use inline styles, particularly for animation, and this sometimes causes breakage for us. If you are open to this change for ripple, we could make similar adjustments to the remaining components using the style attribute.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide more detail on your custom JSS plugin use case?

packages/material-ui/src/ButtonBase/Ripple.js Outdated Show resolved Hide resolved
packages/material-ui/src/ButtonBase/Ripple.js Outdated Show resolved Hide resolved
@mui-pr-bot
Copy link

mui-pr-bot commented Apr 26, 2019

Details of bundle changes.

Comparing: 5950587...b572e0c

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core -0.01% -0.01% 311,507 311,475 84,543 84,533
@material-ui/core/Paper 0.00% 0.00% 67,624 67,624 20,123 20,123
@material-ui/core/Paper.esm 0.00% 0.00% 60,988 60,988 19,025 19,025
@material-ui/core/Popper 0.00% 0.00% 31,114 31,114 10,802 10,802
@material-ui/core/Textarea 0.00% 0.00% 5,472 5,472 2,368 2,368
@material-ui/core/TrapFocus 0.00% 0.00% 3,731 3,731 1,565 1,565
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 15,943 15,943 5,777 5,777
@material-ui/core/useMediaQuery 0.00% 0.00% 2,106 2,106 975 975
@material-ui/lab -0.02% -0.03% 141,034 141,002 42,663 42,652
@material-ui/styles 0.00% 0.00% 51,151 51,151 15,156 15,156
@material-ui/system 0.00% 0.00% 11,765 11,765 3,923 3,923
Button -0.04% -0.04% 85,937 85,905 25,746 25,735
Modal 0.00% 0.00% 20,579 20,579 6,608 6,608
colorManipulator 0.00% 0.00% 3,904 3,904 1,543 1,543
docs.landing 0.00% 0.00% 51,154 51,154 11,250 11,250
docs.main -0.00% -0.00% 649,336 649,304 202,481 202,473
packages/material-ui/build/umd/material-ui.production.min.js -0.01% -0.01% 292,943 292,911 82,385 82,375

Generated by 🚫 dangerJS against b572e0c

@koshea
Copy link
Contributor Author

koshea commented Apr 26, 2019

Could you provide more detail on your custom JSS plugin use case?

Essentially we use MUI to create a widget that is embedded directly on other websites (not in an iframe). To avoid style conflicts, we prefix all of our styles with a base class, and mark all properties as important. We then have a reset sheet on our namespace. It is a bit ugly, but it does work, with the exception of a couple of items like the ripple effect, and the resizing of multiline text areas.

@oliviertassinari
Copy link
Member

@koshea Thanks. inline style has more specificity than style sheet, injected in the HEAD. What would be possibly creating a conflict in the ripple case?
I know that a few users have a strict CSP policy that prevents the usage of inline style.

@koshea
Copy link
Contributor Author

koshea commented Apr 26, 2019

@oliviertassinari because our JSS plugin makes all of the styles !important, and the styles in the style attribute are not processed in this manner, they are overridden and the effect does not happen. Another option that would solve our use case would be to just make the inline styles important, but in my mind that is an uglier solution than running this through the style system.

@oliviertassinari
Copy link
Member

Have you considered this change?

--- a/packages/material-ui/src/ButtonBase/TouchRipple.js
+++ b/packages/material-ui/src/ButtonBase/TouchRipple.js
@@ -24,10 +24,6 @@ export const styles = theme => ({
   },
   /* Styles applied to the internal `Ripple` components `ripple` class. */
   ripple: {
-    width: 50,
-    height: 50,
-    left: 0,
-    top: 0,
     opacity: 0,
     position: 'absolute',
   },

@oliviertassinari oliviertassinari added the component: ButtonBase The React component. label Apr 26, 2019
);

const rippleStyles = {
Copy link
Member

@oliviertassinari oliviertassinari Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert this change? I believe that removing the !important style that overrides the inline style should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting we keep the inline styles in addition to the new class?

Copy link
Member

@oliviertassinari oliviertassinari Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you confirm that we only need #15503 (comment) to solve the problem?

Copy link
Member

@oliviertassinari oliviertassinari Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather use inline style than the style function (in our case).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see what you are saying. No, that resolves the need to use the index option on makeStyles, but it would not resolve my issue without the rest of the changes. I have to run my code on websites with crazy garbage like span { width: 200px !Important; } set in their stylesheets. So I have to clean that up in my namespace with a reset including things like .myNamespace * { width: auto !important; }.

What is the aversion to moving to a style function, performance? Just seems like it would be nice to solve the CSP issue and allow any sort of preprocessing to run on these styles that users would like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the extra detail, I better understand the problem now. There is close to no performance implication in this case, but it will once it's made a systematic solution. We might be able to use CSS variables in v5 (#14420). I have reverted the change of this file.
Did you consider using the shadow DOM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to be using shadow DOM, it is perfect for my use case. I may implement it for most users again soon (past attempted this in MUI 0.x and ran into too many issues).

That said, unfortunately we have a ton of IE11 and Edge users. The polyfill basically does what I am doing with my jss plugins, namespaces all of the CSS. So in those browsers I will still have this issue.

I understand not wanting to pull in this change, I will probably just patch it locally for now. Would you mind giving some insight into where you think I will hit a performance issue when changing the other cases of inline style usage?

Copy link
Member

@oliviertassinari oliviertassinari Apr 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can imagine that supporting IE 11 is important for you, shadow DOM is not an option. Dropping IE 11 would also enable CSS variables and probably solve the issue here at the same time.

I'm curious why is dynamically creating an iframe is not an option for you? We do it for a few of our demos in the documentation, e.g. the Drawers' demos. If you are familiar with Stripe, it's how they increase the security of their web input widget.

Using style functions is slower. If it's only 10% slower (end-to-end), it worth it, 💯 ! It would unlock a lot of interesting features for Material-UI. I'm happy to push this further but in a different pull request. Removing the dead CSS rules is already an improvement :).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This discussion echos with the one of #15499 as it requires the usage of style functions in the core components.

@oliviertassinari oliviertassinari changed the title [ButtonBase] use makeStyles for ripple effect [ButtonBase] Remove dead style Apr 26, 2019
@oliviertassinari oliviertassinari added the new feature New feature or request label Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ButtonBase The React component. new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants