question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS hot reloading does not work in v6

See original GitHub issue

Are you reporting a bug?

Yes.

Environment

  1. react-static -v: 6.0.0-beta.21
  2. node -v: v10.11.0
  3. yarn --version or npm -v: 1.10.1
  4. Operating system: macOS

Steps to Reproduce the problem

  1. npm i -g react-static@6.0.0-beta.21
  2. react-static create
  3. choose basic
  4. yarn start
  5. modify app.css

Expected Behavior

CSS should hot reload, but it doesn’t

I’ve been using react-static@6 beta since 6.0.0-beta.14 and css hot reloading never worked for me.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
LABCATcommented, Apr 26, 2020

@SleeplessByte tested on both windows 10 and Ubuntu 18 with both blank and basic installation. Changing the CSS doesn’t result in any changes until you refresh your browser.

Works fine when using “create react app” so nothing to do with the set up I’m using 😃 Care to share your configuration?

Should I create a new bug report? or does someone want to reopen this one?

0reactions
pztrickcommented, Mar 2, 2021

I encountered this on a vanilla project after adding only the react-static-plugin-stylus plugin.

HMR didn’t work for my Stylus stylesheets.

My work-around is below:

// index.js

import './stylesheets/index.styl'

// ...

if (module && module.hot) {
    module.hot.accept('./app', () => {
        render(App)
    })
    module.hot.addStatusHandler(status=>{
        if(status !== 'apply'){
            return
        }
        (async () => {
            let head = document.getElementsByTagName('head')[0]
            let cssRef = head.querySelector('link')
            let newRef = document.createElement('link')
            newRef.setAttribute('rel', 'stylesheet')
            newRef.setAttribute('type', 'text/css')
            newRef.setAttribute('href', `main.css?c=${Date.now().toString()}`)
            head.appendChild(newRef)
            setImmediate(()=>{cssRef.remove()})
        })()
    })
}

This will reload the transpiled CSS on all code changes. I’m sure there is a better way to do things but I’m not familiar with the HMR life-cycle and API.

Hope this helps someone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React router hot-reload not working - Stack Overflow
This as well happens when I make some changes to the item page and hot reloading is rerendering it. It looks like all...
Read more >
Webpack Hot Reload not working in react Storybook 6.0-rc.9
Describe the bug After changing a story the page reloads and I get following message in the browser console [HMR] The following modules ......
Read more >
Hot Reload in ElectronJS - GeeksforGeeks
This tutorial will demonstrate how to implement hot reloading in Electron using electron-reload npm package and electron-reloader npm package.
Read more >
Server Rendering with React and React Router - ui.dev
In this comprehensive, up-to-date guide, you'll learn how, why, and when to add server rendering to a React and React Router application.
Read more >
Babel Plugin: React CSS Modules - npm
Start using @dr.pogodin/babel-plugin-react-css-modules in your project by running ... If you don't know what is Hot Module Reloading (HMR), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found