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

fix(core): Disable HMR for CSS modules #11032

Merged
merged 2 commits into from
Jan 31, 2019
Merged

Conversation

jonlow
Copy link
Contributor

@jonlow jonlow commented Jan 13, 2019

Description

CSS modules will not work correctly with style-loader when HMR is enabled (HMR was introduced in gatsby v2). For new styles to appear on a page, a full page refresh is required for css modules to work. Otherwise, an error is thrown. This PR disables HMR for css-modules as suggested by webpack-contrib/style-loader#320 so that saving a .module.scss file will refresh the page and show any new styles.

Here's a screencast showing the issue before the fix https://www.useloom.com/share/a1061fb2d4344942af1f9efa4870d965

Related Issues

#10316

@jonlow jonlow changed the title Disable HMR for CSS modules Disable HMR for CSS modules in gatsby-plugin-sass Jan 17, 2019
@jonlow jonlow changed the title Disable HMR for CSS modules in gatsby-plugin-sass fix(gatsby-plugin-sass): Disable HMR for CSS modules Jan 17, 2019
@KyleAMathews
Copy link
Contributor

This is modifying the sass rules? I assume you meant to modify all of the CSS module rules?

@jonlow
Copy link
Contributor Author

jonlow commented Jan 29, 2019

@KyleAMathews I'm only modifying the SASS CSS modules (eg components.module.scss), since this code currently lives in gatsby-plugin-sass. I figured that anything specific to SASS should live in this plugin.

If we want to add this fix for regular CSS modules (no SASS), then shouldn't that fix go into the main Gatsby package? (maybe utils/webpack-utils.js)

@wardpeet
Copy link
Contributor

@jonlow sorry for keeping you waiting, i'll be checking this today!

It would be really helpful if you do it for all cssmodules plugins like less, ...

@wardpeet wardpeet self-assigned this Jan 31, 2019
@jonlow jonlow requested a review from a team as a code owner January 31, 2019 21:08
@wardpeet wardpeet changed the title fix(gatsby-plugin-sass): Disable HMR for CSS modules fix(core): Disable HMR for CSS modules Jan 31, 2019
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

I've tested this change and looks Great! I've also added hmr: false to all our flavors of cssmodules.

@jonlow 🥇 Thank you very much for taking this issue on! And We're really sorry that it took so long to actually look at this one.

@wardpeet wardpeet merged commit 97c98e9 into gatsbyjs:master Jan 31, 2019
@gatsbot
Copy link

gatsbot bot commented Jan 31, 2019

Holy buckets, @jonlow — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

wardpeet pushed a commit that referenced this pull request Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants