jaredpalmer / razzle

✨ Create server-rendered universal JavaScript applications with no configuration
https://razzlejs.org
MIT License
11.1k stars 866 forks source link

Hot reloading not working with React Loadable example? #448

Closed benkingcode closed 5 years ago

benkingcode commented 6 years ago

I've cloned the razzle source and tried running the with-react-loadable example, but it seems like HMR no longer works. I'm not sure what the problem is here, does anyone have an idea how to get it working again?

olehreznichenko commented 6 years ago

I use koajs instead of expressjs

import http from 'http'
import Loadable from 'react-loadable'

import app from './server'

let currentApp = app.callback()

Loadable.preloadAll()
    .then(() => {
        const server = http.createServer(currentApp)

        server.listen(PORT, HOST, () => console.log(`🚀 started on ${HOST}:${PORT}`))

        if (module.hot) {
            console.log('✅  Server-side HMR Enabled!')

            module.hot.accept('./server', () => {
                console.log('🔁  HMR Reloading `./server`...')
                server.removeListener('request', currentApp)
                console.log("after `removeListener`", server.listeners("request").length)
                currentApp = require('./server').default.callback()
                server.on('request', currentApp)
            })
        }
    })
    .catch(console.error)
seanyu4296 commented 6 years ago

@olegreznichenko I'm also running into this issue. So basically just changing to koa will solve HMR?

seanyu4296 commented 6 years ago

I was able to make HMR work with the with-react-loadable example @dbbk where you able to make it work?

hrasoa commented 6 years ago

I could not make it work too with a fresh install.

I had to add this to make it work in the client.js:

if (module.hot) {
  module.hot.accept('./App', window.main);
}
seanyu4296 commented 6 years ago

I also did the same thing @hrasoa!


if (module.hot) {
  module.hot.accept('./App.jsx', () => window.main());
}
stale[bot] commented 5 years ago

Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.

stale[bot] commented 5 years ago

ProBot automatically closed this due to inactivity. Holler if this is a mistake, and we'll re-open it.