-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Keep getting an annoying warning message since version 1.0.1 #2704
Comments
Can you copy/paste your code that renders the |
The warning was a previously missing one - something you are doing is changing the set of routes passed into your |
I too just started getting this warning after upgrading to 1.0.2. It occurs immediately after webpack's hot loader reloads the modules after an update. I don't see anything unusual about how my Router is defined: export default class App extends Component {
render () {
return (
<Router history={history}>
<Route component={AppView} path="/">
<IndexRoute component={Home} />
<Route component={Home} path="/home" />
<Route component={Changelog} path="/changelog" />
<Route component={Loader} path="/:type/:component" />
<Route component={FourOhFour} path="*" />
</Route>
</Router>
);
}
}
render(<App />, document.getElementById('App')); Everything continues to work as normal, but the warning pops up after any module is hot reloaded. |
Hot reloading routes doesn't work, I'm pretty sure, so that sounds like an appropriate error in context. |
Thanks for your reply and sorry about not getting back in time.
|
Btw I'm not using hot reloading... I'm using react-transform, which seems to work fine for me. |
@DrkCoater react-transform is a tool that is built on hot reloading (the |
thanks. I still don't quite understand what taion meant by "Hot reloading routes doesn't work,"... Is that mean Hot reloading not working so it's causing warning message appear? Trying to identify whether it's a configuration issue or coding issue now. |
Hot reloading of routes doesn't yet work. We don't have any mechanism or API for replacing routes in place. So changing your route config will not be reloaded into your app during development until you refresh the full page. |
I want to update my routing logic along with the state of my app (I'm using redux). So say I have a list of todos in my store, and each todo has it's own page. I want to do a check in the Is this something |
@taion so does this mean that if I change absolutely anything inside of a component that is being hot loaded that it will always "warn" me now due to it being inside of a route? |
This fixes warnings/errors about the store and history being recreated when HMR happens by moving their creation up a level. Almost all changes in the app will be caught at or before app.jsx, so they'll never reach index.jsx and thus never re-run that code. Note that there will still be errors if you actually change the routes (and will require a full reload), but there's not much we can do about that right now. See: remix-run/react-router#2704
@jonstuebe That seems to be the behavior that I see too and it isn't very useful if I understand all of the points here.
So according to @taion it sounds like the warning was only intended to show when the list of routes have changed and not necessarily the components to which those routes lead. If this is the case then perhaps a new issue needs to be opened to report that the warnings are showing when they are unintended. I think the fact that this issue used the word "annoying" that it may be safe to assume that original issue here was not complaining about a useful warning that would result from actually making a change directly to the routes. This warning happens to be the last in a list of frequent warnings in an app I'm developing and it causes a bunch of noise so I'm eager to resolve what ever underlying issue is causing them. |
Things will break whenever the set of routes breaks referential identity. Just don't hot reload your |
@taion how prevent |
if (module.hot) {
module.hot.decline("./routes.js");
} |
I am having the same issue here, but with React-Intl v2.0.0-beta-2. If I update the By the way, it does not seem to be preventing the app, React-Intl and the router to keep on working as expected. It is just spitting out the warning. Here is my code:
|
@CedricLor: we worked around the same issue by defining the routes in a constant: For example: const routeConfig = [
{ path: '/:locale',
component: App,
indexRoute: { component: NewsCardsContainer },
...
}
];
return (
<IntlProvider key="intl" {...intlData}>
<Router history={history} routes={routeConfig} />
</IntlProvider>
) |
@noahmiller Great idea. Thanks a lot. |
I'm running into the same problem, please view my sample code below. I use _requireAnonymous(nextState, replaceState) {
if (isAuthenticated) {
replaceState({nextPathname: nextState.location.pathname}, '/dashboard')
}
return true
}
<Router history={history}>
<Route path='/.' component={Loader}/>
<Route component={Main}>
<Route path='/' component={Container}>
<IndexRoute component={Default} onEnter={::this._requireAnonymous}/>
<Route path='login' component={Login} onEnter={::this._requireAnonymous}/>
<Route path='register' component={Register} onEnter={::this._requireAnonymous}/>
<Route path='dashboard' component={dashboard}/>
</Route>
<Route path='/logout' onEnter={this.props.logout} />
</Route>
</Router> This LoC has checked that the Router's children were changed, if I remove |
@crashbell I've run into the same error but it seems the problem is if I have the component wrapped in a react-redux connect |
thanks @SimeonC! It also works fine to me. |
Strangely this was happening because I had a reducer called I changed it from to and that fixed the issue for me with routes being re-rendered. Is application some sort of reserved name? |
I'm having this issue in a react-redux scenario as well and I'm guessing that that is my problem although I'm not sure if I understand white how to follow @noahmiller's workaround example to move from Route components to a configuration. I don't want to screw something up in the process just to work around the warning. |
Oh, just changing this below seemed to do the same trick for me. const routes =
<Route path="/" component={App}>
<IndexRedirect to="default"/>
<Route name="one" path="one" component={One}/>
<Route name="two" path="two" component={Two}/>
<Route name="three" path="three" component={Three}/>
<Route path="*" component={NotFound} />
</Route>;
return (
<Provider store={store}>
<div>
<Router history={history}>
{routes}
</Router>
{__DEV__ && <DevTools />}
</div>
</Provider>
); Thanks @noahmiller! |
Same issue but only when I call parent handling functions. Example. My component holds data like the current logged user, current project, ...
As soon as I call the EX
|
@rackt/redux Do you have any recommendations for what to do here? react-redux |
@desduvauchelle You should be @taion It appears to be because most people are defining and rendering their routes within a component. And, as is usually the case, they have ReactDOM.render(
(
<Provider store={store}>
<Router history={browserHistory} children={routes(store)} />
</Provider>
),
document.getElementById('root')
); Everything below that is my app code and gets hot reloaded by |
Same situation like @globexdesigns. Have you solved this? For me, the error still there even I separate routes into a single file and module.hot.decline that file. |
@gaearon I am setting everything
the error is at the first check on history
what can I do to avoid this?? thanks. |
@gaearon after playing around, adding a specific handler like this seems solved the issue
thanks. |
Remembering the original problem that state is being modified at the router level where the routes are dependent on state, here's another option:
|
Cleared up the errors on my end. FWIW this is what my const root = document.getElementById('root');
const renderApp = () => {
const routes = require('./routes').default;
render(
<AppContainer>
<Provider {...stores} children={routes} />
</AppContainer>,
root
);
};
renderApp();
if (module.hot) {
module.hot.accept('./routes', () => {
unmountComponentAtNode(root);
renderApp();
}); For const routes = (
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute getComponent={(location, cb) => {
require.ensure([], (require) => {
cb(null, require('~/views/Home'));
});
}}
/>
<Route path="/compose" getComponent={(location, cb) => {
require.ensure([], (require) => {
cb(null, require('~/views/Compose'));
});
}}
etc… |
I found a very simple solution: |
does providing a key not cause you to lose state? I have added they key to a project, https://github.com/peter-mouland/react-lego#react-hot-loader-v3, and when hot-reloading is complete state is lost. Without the key i do get the warning, but hot-reload completes keeping state intact |
after hot reloading my states stayed the same |
@frankwallis's Solution worked for me. Adding a unique key to the router.
edit: changed it to Math.random() @sterjakovigor thanks! |
great to hear, must be my app having state problems then 🤔 |
Here is my workaround, just adding one line: import React from 'react';
import { Provider } from 'react-redux';
import { Router } from 'react-router';
import routeConfig from '../common/routeConfig';
export default class Root extends React.Component {
render() {
const { store, history } = this.props; // eslint-disable-line
if (!this.routeConfig) this.routeConfig = routeConfig;
return (
<Provider store={store}>
<Router history={history} routes={this.routeConfig} />
</Provider>
);
}
} I looked at the source code: https://github.com/ReactTraining/react-router/blob/6eeb7ad358f987520f5b519e48bdd31f725cbade/modules/Router.js , the warning is just logged when I guess this has better performance than adding a |
@supnate Thanks for this workaround! It not only has better performance, but it actually works. Because the Math.random() workaround effectively invalidates the whole tree of components and hence prevents the state from being retained upon a hot reload. |
My two cents. Based on @gaearon's comment, you will actually have to send an array of
|
I want to pass props to routes. I am doing it this way but getting error.
|
I think this will be much better for various environment: import React from 'react';
import ReactDOM from 'react-dom';
import {AppContainer} from 'react-hot-loader';
import Router from './Router';
const render = (Component) => {
ReactDOM.render(
<AppContainer>
<Component key={module.hot ? new Date() : undefined}/>
</AppContainer>,
document.getElementById('root')
);
};
render(Router);
if(module.hot) {
module.hot.accept('./Router', () => {
render(Router);
});
} |
…sage by implementing solution in Github: remix-run/react-router#2704 (comment) Router is only instantiated once in a production setting (e.g. not webpack-dev-server), so there is minimal overhead on producing a random key value for `Router`.
* accept hot module changes, move routes into root component * Fix "You cannot change <Router routes>; it will be ignored" error message by implementing solution in Github: remix-run/react-router#2704 (comment) Router is only instantiated once in a production setting (e.g. not webpack-dev-server), so there is minimal overhead on producing a random key value for `Router`.
Hi,
I'm keep getting an annoying warning message in the browser console after I upgrade to version 1.0.1 or 1.0.2, Every time I navigate to a different route...:
Warning: You cannot change ; it will be ignored
I've checked and made sure that routes prop nor the children prop of the Router has not been modified, (maybe react is doing some internal things)...
Does not happen in version 1.0.0 or lower, force me to keep react-router to be 1.0.0...
Is this a bug?
Thank you.
The text was updated successfully, but these errors were encountered: