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.

Asynchronous React Router v3 routes fail to hot-reload

See original GitHub issue

Hey there! I’m having some difficulty getting react-hot-loader@3.0.0-beta.1 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 using react-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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:12
  • Comments:32 (4 by maintainers)

github_iconTop GitHub Comments

18reactions
sthzgcommented, Oct 18, 2016

I ran into the problem with hot reloading async routes and updated by additionally registering amodule.hot.accept in the require.ensure() callbacks. E.g. like this

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,
    ]);
  });
},
10reactions
kettanaitocommented, Aug 12, 2017

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 <Route />

Fixed the problem, but as mentioned causes deep re-render, therefore loosing components’ state. However, you can find this workaround in officially listed examples of react-hot-loader (i.e. here).

Using asyncComponent from react-async-component

As suggested here, it is possible to wrap the modules you wish to load async with asyncComponent and pass them as component prop to Route directly. This will eliminate hot-reloading issue, however forces you to create additional files doing nothing but resolving modules async.

Various other workarounds

Which are not meant for good code maintenance.

So, it this somehow being solved, or already has been solved with the new release of react-hot-loader?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Hot Reload with React-hot-loader 3, React-router 4 ...
1 Answer 1 ; 'webpack'; import ; const config = require ; Webpack(config); const ; '/public/index.html', }, hot ; HapiWebpackPlugin, options, }, ( ......
Read more >
React Location - Enterprise routing for React applications
Powerful, enterprise-grade routing for React applications. Declarative & asynchronous route elements and data loaders, first-class Search Param APIs, ...
Read more >
react-dom.development.js:18687 the above error occurred ...
It's as the error states, the links the Header component is rendering need to be rendered within the routing context provided by a...
Read more >
connected-react-router
✨ Synchronize router state with redux store through uni-directional flow (i.e. history -> store -> router -> components). Supports React ...
Read more >
Code splitting routers with React Lazy and Suspense
Using React Lazy and Suspense on React routes will code-split your application. By lazy loading React routes, it can cause an increase in...
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