Skip to content
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

Problem migrating to v3 #473

Closed
dcosson opened this issue Feb 3, 2017 · 2 comments
Closed

Problem migrating to v3 #473

dcosson opened this issue Feb 3, 2017 · 2 comments

Comments

@dcosson
Copy link

dcosson commented Feb 3, 2017

I'm trying to migrate to v3, and am following directions here #243 (comment) which were the most full-fledged I could find.

I'm not sure how to interpret a couple of lines. For steps 2 & 3, if I do want React Hot Loader to preserve state should I still also be setting up module.hot to re-render the root component?

I've tried it both ways, when I don't have module.hot I get a warning on every change that it can't update because it would require a full reload and nothing happens. When I do add module.hot, the state is not preserved and the whole page re-renders on every change (even though I've done all of step 3). In this latter case there's a react-router error when the hot reload happens that says Warning: [react-router] You cannot change <Router routes>; it will be ignored, not sure if that's related.

Hoping someone can point me in the right direction (or perhaps there's a bug using this with react router?)

@mutsys
Copy link

mutsys commented Feb 3, 2017

@dcosson I don't know if that warning message is the cause of your issue but as it just so happens, I found a work around for that tonight.

produces the warning message

import App from "./app";

const renderRouterWithAppContainer = () => {
    render((
        <AppContainer>
            <Router history={ browserHistory }>
                <Route path="/" component={ App }/>
            </Router>
        </AppContainer>
    ),  document.getElementById("app"));
};

renderRouterWithAppContainer();

if (module.hot) {
    module.hot.accept("./app", () => renderRouterWithAppContainer());
}

does not produce the warning message

import App from "./app";

const router = (
    <Router history={ browserHistory }>
        <Route path="/" component={ App }/>
    </Router>
);

const renderRouterWithAppContainer = () => {
    render((
        <AppContainer>
            { router }
        </AppContainer>
    ),  document.getElementById("app"));
};

renderRouterWithAppContainer();

if (module.hot) {
    module.hot.accept("./app", () => renderRouterWithAppContainer());
}

In my limited experience so far, it seems that RHL is kind of touchy when React Router is in the mix. What I have observed is that it only seems to work when <AppContainer/> is the parent of <Router/>. Reversing that parent/child ordering always seems to result in failure.

@calesce
Copy link
Collaborator

calesce commented Feb 11, 2017

Yes, the warning message is something in React Router 2/3 that probably won't be removed (not an issue with RHL). The known RR issues are mostly covered by #249 and #288, so I'm going to close this.

@calesce calesce closed this as completed Feb 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants