-
Notifications
You must be signed in to change notification settings - Fork 801
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
Asynchronous React Router v3 routes fail to hot-reload #288
Comments
Thanks for a repro case. Here’s another great repro case: gaearon/react-hot-boilerplate#61 (comment). We’ll need to look into this before releasing 3.0. Probably something funky related to how |
It looks like this has something to do with using the |
|
With webpack 2 in System.import HMR too doesn't work. |
Beta.2 has the same issue. MrEfrem [email protected] schrieb am So., 12. Juni 2016, 22:41:
|
👍 |
Now it stopped working for me with beta.0. I had this case already some days ago, which was fixed by a |
When routes/history are imported in the I'll move my routes/history back as hot reloading is more important, then I'll try to add back the async routes. |
With async routes, it appears that import React from 'react'
export default function (props:any) {
return (<div>Foo3</div> )
} import React, {Component} from 'react'
export default class FooComponent extends Component {
render () {
return (<div>FooComponent2</div>)
}
} |
@dferber90, @gaearon, @rosskevin
having a routing config in the form of:
|
@dkulichkin Yes, that workaround seems to be the only way for now. As the sacrifice of not being able to use code-splitting is only for development, this isn't that much of a problem is it? Of course it would be nice if this wasn't necessary, but I don't even know why that fixes the problem in the first place so a lot of investigation would be necessary. The code you provided isn't helpful because it leaves out the important parts (importing the component that is being split out in the second snippet). Your snippets only contain |
@dferber90 the main point of having a chunking in development is the profiling, f.e. with help of such tools like webpack-dashboard. That allows for instance immediately see an impact of the changes to files size without necessity to build and switch to prod. So the drawback is pretty much serious. Anyway what's a main bottleneck in this issue making only pure stateless components reloaded in chunks? Router, react-hot-reloader or bundler? Regarding '...' character in my snippet - that's just skipped pathes to component files, nothing else |
I ran into the problem with hot reloading async routes and updated by additionally registering a getChildRoutes(partialNextState, callback) {
require.ensure([], function (require) {
if (module.hot) {
module.hot.accept('../routes/Blog', () =>
callback(null, [require('../routes/Blog').default]);
}
callback(null, [
require('../routes/Blog').default,
]);
});
}, |
@sthzg Did you by chance also manage to make it working with a webpack-bundle loader? |
@dkulichkin No, sorry. So far I have only tried it with an app that uses code splitting based on the |
Just wanted to add that I was playing around with It looks like the |
I worked around the getComponent() issue by adding a key prop to Router that changes on each hot update. This will force a different Router instance to be created, and re-executing getComponent() calls. This also fixed the
|
@flut1 yeah that will allow updates to happen, but component state is lost because it's deeply re-rendering all of the components, so it's not the ideal workaround. |
Grain of salt and all, but it seems this issue has mysteriously resolved itself with Webpack 2.2.0. Previously, in order to make hot reloading work, I was manually adding chunks of code like this to any parent view that asynchronously loaded children: if (process.env.NODE_ENV === 'development') {
require('./child1');
require('./child2');
require('./child3');
} I removed all such lines on a whim to see what it'd break, and much to my surprise and delight, HMR continued to function beautifully. I don't think anything relevant has changed in my setup other than the Webpack version, but this wasn't carefully tested. Would be glad to see if others could corroborate my story. |
Good news. |
I ran into the same issue where HMR was not working with react-router, and I managed to work around the issue, so I thought I'd share my solution:
Used with the Router like this:
|
@sthzg Made it for me with async routes and react-router 3.x (Did not try yet react-router 4.x with history 4.x)
It seems like the The logs missings are:
If anyone has an idea? Does someone has the same issue? What do you think @gaearon? (sorry for hard poking) EDIT : Just found the issue... Events are not the same between webpack and webpack 2. I just needed to update my Thanks for these tools :) |
Hello guys! For those who want to make react-router's routes to work with // Example bellow is for webpack2
const dev = true; // Should be false when building for production
// later..
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
// babel options here
},
},
dev ? 'preprocess-loader?+DEV' : 'preprocess-loader',
],
},
// Other rules...
],
}, And then use preprocess in your async routes: // Example bellow uses import() but works with require.ensure() too
{
path: 'about',
// Ensure component is required synchronously in DEV so that it works with react-hot-loader
// When not in DEV, we want to make sure that it generates a chunk
// @ifdef DEV
component: require('./About').default,
// @endif
getComponent: () => import('./About'),
} Enjoy! |
Using anything that is not an ES6 Also note that, if you save the |
@Kovensky I've tested using ES6 imports like so: // @ifdef DEV
import About from './About';
// @endif
export default [
{
path: 'about',
getComponent: () => {
// @ifdef DEV
return Promise.resolve(About);
// @endif
return import('./About');
},
},
]; but it always needs I've got all of this working great in https://github.com/moxystudio/react-with-moxy if you guys want to see how all the pieces are glued together. |
Is there any update regarding this issue? So far there has been only a few suggestions, each having its own drawbacks and all being but workarounds: Provide "key" prop to
|
@kettanaito Why don't you migrate to react-router 4? |
@morajabi I haven't got enough time to read about it. So far, I don't see how to migrate my code to use |
@morajabi sorry, there is nothing about SSR in the migration guide. |
@kettanaito You're right, but read this:
And maybe it's worth a reading: https://github.com/ReactTraining/react-router/tree/v4.0.0-beta.8#why-did-you-get-rid-of-feature-x |
I close it. React Router v4 is supported and stable. |
Hey there! I'm having some difficulty getting
[email protected]
to hot-reload changes to views that are passed to React Router as lazy-loaded POJOs. Updating a view class triggers the usual console messages and throws the warning about changing<Router history>
, but the rendered output doesn't refresh. Curiously, though, changing the components that the views require immediately hot-reloads them, even within the selfsame non-reloading async views.Here's a quick screencast demonstrating the issue:
...and here's the code base that screencast's taken from: https://github.com/phyllisstein/hildy/tree/react-hot-3. (The
master
branch of which repo is still usingreact-transform-hmr
without any evident issues.)I'd be grateful for any suggestions you can provide, and happy to offer more troubleshooting info if I can! Thanks for looking into this.
The text was updated successfully, but these errors were encountered: