material-components-web icon indicating copy to clipboard operation
material-components-web copied to clipboard

Ripple effect looks weird when building with webpack

Open yannski opened this issue 8 years ago • 11 comments

What MDC Web Version are you using?

0.30.0

What browser(s) is this bug affecting?

Chrome, Firefox

What OS are you using?

Linux

What are the steps to reproduce the bug?

Import MDC Web through webpack with this line:

@import "~material-components-web/material-components-web";

What is the expected behavior?

Ripple effect should look like the demo on appspot demo

What is the actual behavior?

Same weird looking described in #1184

Any other information you believe would be useful?

When I include MDC Web CSS https://unpkg.com/[email protected]/dist/material-components-web.min.css with a link tag without building with webpack, everything looks normal.

yannski avatar Feb 12 '18 17:02 yannski

I just tried reproducing this using a CSS file compiled using node-sass and don't see an issue with ripples. It's odd that this would break specifically with locally-compiled scss but work with what should effectively be the same scss online though, if everything else remains constant...

I guess one thing you could try is build a scss file that only includes material-components-web.scss, and diff the output against https://unpkg.com/[email protected]/dist/material-components-web.css?

The issue you pointed to was a very specific regression due to style changes that had unintended side effects, and the change in question was reverted the same day that was reported, so I'm very surprised if that's exactly what you're seeing (unless you're invoking the mdc-ripple-radius-unbounded mixin with values that are too small).

Something I'd expect to be more likely is that you're instantiating ripples on components that aren't initially in document flow, and need to call layout on those ripple instances when their surfaces are displayed, but I'd expect that to happen regardless of using unpkg's CSS or your own.

If you still experience the issue after the ideas above, can you reduce it to a simplified case and post the HTML that you're using to reproduce the issue?

kfranqueiro avatar Feb 12 '18 20:02 kfranqueiro

@yannski did you use default mdc-ripple-surface or use sass mixin to produce new ripple class ? image when i use mixin, i have same problem with you. but when im use mdc-ripple-surface no problem anymore

ombimo avatar Feb 13 '18 10:02 ombimo

I didn't add any sass mixins. I just initialized the JS component like this:

import {MDCRipple, MDCRippleFoundation} from '@material/ripple'

document.querySelectorAll('.mdc-button, .mdc-ripple-surface').forEach((elem) => {
  new MDCRipple(elem)
})

yannski avatar Feb 13 '18 10:02 yannski

@kfranqueiro thanks for your suggestion. I'm a noob with MDC Web (currently transforming a project from Bootstrap Material Design to "pure" MDC Web). Is there some kind of jQuery DOM Ready stuff to be sure to run my JS code after the elements are rendered?

yannski avatar Feb 13 '18 10:02 yannski

@yannski im currently using laravel-mix (webpack), and i initialized the JS like yours and it work. did you attach mdc-ripple-surface in inline element (display: inline)?

ombimo avatar Feb 14 '18 02:02 ombimo

@kfranqueiro I've just noticed this warning in my wepack output:

webpack_1   |     WARNING in ./node_modules/css-loader?{"minimize":false,"sourceMap":true,"importLoaders":2}!./node_modules/postcss-loader/lib?{"sourceMap":true,"config":{"path":"/usr/src/app/.postcssrc.yml"}}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":true,"includePaths":["node_modules"]}!./app/javascript/css/application.scss
webpack_1   |     (Emitted value instead of an instance of Error) postcss-custom-properties: /usr/src/app/node_modules/@material/ripple/_mixins.scss:27:2: Custom property ignored: not scoped to the top-level :root element (.mdc-checkbox { ... --mdc-ripple-fg-translate-end: ... })
webpack_1   |     NonErrorEmittedError: (Emitted value instead of an instance of Error) postcss-custom-properties: /usr/src/app/node_modules/@material/ripple/_mixins.scss:27:2: Custom property ignored: not scoped to the top-level :root element (.mdc-checkbox { ... --mdc-ripple-fg-translate-end: ... })
webpack_1   |         at Object.emitWarning (/usr/src/app/node_modules/webpack/lib/NormalModule.js:117:16)
webpack_1   |         at result.warnings.forEach (/usr/src/app/node_modules/postcss-loader/lib/index.js:149:49)
webpack_1   |         at Array.forEach (<anonymous>)
webpack_1   |         at postcss.process.then (/usr/src/app/node_modules/postcss-loader/lib/index.js:149:27)
webpack_1   |         at <anonymous>

Could this be related?

yannski avatar Feb 16 '18 08:02 yannski

After a few tests, I'm pretty convinced the problem lies with the webpack loaders/modules somewhere, not in the material stuff :)

yannski avatar Feb 16 '18 08:02 yannski

By removing postcss-cssnext from the postcss stuff, I get it working normally (I'm using Rails with webpacker and that was the default)

yannski avatar Feb 16 '18 09:02 yannski

@yannski are you saying that cssnext conflicts with ripple? Which part of cssnext do you think was affecting it?

moog16 avatar Feb 21 '18 04:02 moog16

Closing since it is not an MDC related issue.

moog16 avatar Feb 22 '18 21:02 moog16

I encountered the same problem and was able to solve it. I'm use Rails 5 with Webpacker. Something in the Ripple CSS was not being compiled properly, so my buttons were using the CSS fallback instead of the real ripple.

I used the fix recommended here: https://github.com/jamesmfriedman/rmwc/issues/65

I updated the app's .postcssrc.yml to make PostCSS preserve custom properties:

plugins:
  postcss-import: {}
  postcss-cssnext: {
    features: {
      customProperties: {
        preserve: true
      }
    }
  }

pangolingo avatar Nov 26 '18 19:11 pangolingo