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

Server rendering dynamic routes (require.ensure) produces client React warning #1500

Closed
jorge-pascual opened this issue Jul 8, 2015 · 4 comments

Comments

@jorge-pascual
Copy link

Hi!

I'm using react-router v1.0.0-beta3 in a server rendering project with Fluxible. All is running really well now... but dynamic routes.

I have this route configuration

// Polyfill
if(typeof require.ensure !== "function") require.ensure = function(d, c) { c(require) };

var routes = {
 (...)
  path: 'search',
  component: Content,
  childRoutes: [
  {
      path: 'invoice',
      getChildRoutes (state, cb) {
            require.ensure([], (require) => {
              cb(null, [
                require('./modules/invoiceCreate')
              ])
            })
      }             
  }
(...)             

Where ./modules/invoiceCreate is

// Polyfill
if(typeof require.ensure !== "function") require.ensure = function(d, c) { c(require) };

export default {
  path: 'create',

  getComponents (cb) {
    require.ensure([], (require) => {
      cb(null, require('./views/home'))
    })
  }
}

All is working fine and I get the page composition that I expect... however, React in the client says...

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
 (client) <noscript data-reacti
 (server) <div data-reactid=".t

If I use a static route, it works fine and React doesn't say anything...

Do anyone know if the router dynamic load has any issue with server-rendering?

Regards.

@AndrewIngram
Copy link

I'm getting this too, using the same polyfill in fact.

@anatomic
Copy link

anatomic commented Jul 9, 2015

Hi, @jorge-pascual and @AndrewIngram Have a look at #1402 (comment) and see if this solves your problem

@AndrewIngram
Copy link

Yup, that does the trick, thanks for the help!

@jorge-pascual
Copy link
Author

thank you @anatomic. After few tries, I can't catch the point...

I think my client code is very close to yours (mine over Fluxible and yours over Redux)... however, the warning is still here... and React trigger the render again...

var history = new BrowserHistory();

if (typeof history.setup === "function") {
    history.setup();
}

var dehydratedState = window.App;
window.React = React;

app.rehydrate(dehydratedState, function (err, context) {
    if (err) {
        throw err;
    }
    window.context = context;
    var routes = app.getComponent();

    Router.run(routes, history, (err, initialState, transition) => {

        React.render(
            React.createElement(
                FluxibleComponent,
                { context: context.getComponentContext() },
                <Router children={routes}  history={history} />
            ),
            document.getElementById('app'),
            function () {
                debug('React Rendered');
            }
        );

    });

});

@lock lock bot locked as resolved and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants